<template>
  <div>
    <avue-form :option="option"
               @submit="submit"
               v-model="form"
               ref="form">
      <!--<template slot-scope="scope" slot="menuForm">
        <el-button @click="tip">自定義按鈕</el-button>
      </template>-->
      <template slot="isTurnIn">
        <!--        <el-checkbox v-model="row.isTurnIn" @change="turnInChange"></el-checkbox>-->
        <el-tag size="small " type="success" plain v-if="form.isTurnIn">上繳</el-tag>
        <el-tag size="small " type="danger" plain v-if="!form.isTurnIn">非上繳</el-tag>
      </template>
    </avue-form>
  </div>
</template>

<script>
  import {sure} from "@/api/bank/keypwd";
  import {getKeyType} from "@/api/bank/keypwd";

  export default {
    name: "keypwd-sure",
    data(){
      return {
        loading: false,
        option: {
          mockBtn: false,
          submitText: '確認',
          printBtn: false,
          emptyBtn: false,
          column: [
            {
              label: "銀行號",
              prop: "bankNo",
              span: 24,
              hide: true,
              display: false,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入銀行號",
                trigger: "blur"
              }]
            },
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              display: false,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              span: 24,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "分類種類",
              prop: "category",
              search: true,
              checkStrictly: true,
              type: "tree",
              disabled: true,
              multiple: true,
              // dicUrl: "/api/blade-system/dict/dictionary?code=key_type",
              dicData: [],
              dataType: "string",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              rules: [{
                required: true,
                message: "請輸入分類",
                trigger: "blur"
              }]
            },
            /*{
              label: "數量",
              prop: "number",
              type: "number",
              display: false,
              disabled: true,
              hide:true,
              rules: [{
                required: true,
                message: "請輸入數量",
                trigger: "blur"
              }]
            },*/
            {
              label: "是否上繳",
              prop: "isTurnIn",
              formslot: true,
              rules: [{
                required: false,
                message: "請勾選是否上繳",
                trigger: "blur"
              }]
            },
            {
              label: "交出人",
              prop: "handoverPersonName",
              disabled:  true,
              rules: [{
                required: false,
                message: "請輸入交出人姓名",
                trigger: "blur"
              }]
            },
            {
              label: "交出人員工號",
              prop: "handoverPersonNo",
              disabled: true,
              rules: [{
                required: false,
                message: "請輸入交出人員工號",
                trigger: "blur"
              }]
            },

            {
              label: "接收人",
              prop: "receiverName",
              disabled:  true,
              rules: [{
                required: true,
                message: "請輸入接收人員工號",
                trigger: "focus"
              }]
            },
            {
              label: "接收人員工號",
              prop: "receiverNo",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入接收人員工號",
                trigger: "change"
              }]
            },
            {
              label: "交接日期",
              prop: "handoverDate",
              type: "datetime",
              disabled: true,
              format: "yyyy-MM-dd HH:mm",
              valueFormat: "yyyy-MM-dd HH:mm",
              rules: [{
                required: true,
                message: "請輸入交接日期",
                trigger: "blur"
              }]
            },
            {
              label: "備註",
              prop: "remark",
              rules: [{
                required: false,
                message: "請輸入備註",
                trigger: "blur"
              }]
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              disabled: true,
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              rules: [{
                required: true,
                message: "請輸入填報時間",
                trigger: "blur"
              }]
            },
            {
              label: "填報人",
              prop: "fillingPerson",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入填報人",
                trigger: "blur"
              }]
            },
          ]
        }
      }
    },
    props: {
      form: {
        type: Object
      },

    },
    mounted() {
      this.initTypeDict();
    },
    methods: {
      initTypeDict(){
        getKeyType().then(res => {

          let data = res.data.data;
          let pid = new Set();
          for (let i = 0; i < data.length; i++) {
            let item = data[i];
            pid.add(item.parentId);
          }
          let arr = [];
          pid.forEach(id => {
            data.forEach(item => {
              if (id == item.id){
                arr.push(item)
              }
            })
          })
          arr.forEach(item => {
            data.forEach(it => {
              if (item.id == it.parentId){
                if (!item.children){
                  item.children = [];
                }
                it.dictValue = item.dictValue + '-' + it.dictValue;
                item.children.push(it)
                item.hasChildren = true;
              }
            })
          })
          this.typeList = arr;
          let formDicData = this.deepClone(arr);
          formDicData.forEach(item => {
            item.disabled = true;
            if (item.hasChildren){
              item.children.forEach(child => {
                child.disabled = child.isSealed == 1;
              })
            }
          });
          this.findObject(this.option.column, 'category').dicData = formDicData;
          return arr;
        })
      },
      submit(row, done){
        row.isTurnIn = !row.isTurnIn ? 0 : 1;
        sure(row).then(() => {
          this.$message.success("操作成功！");
          this.$emit("close")
          done();
        });
      },
    }
  }
</script>

<style scoped>

</style>
