<template>
  <basic-container>
    <div v-if="formVisible">
      <avue-form :option="option" v-model="form" @submit="handleSubmit" @tab-click="handleTabClick">
      </avue-form>
    </div>
  </basic-container>
</template>

<script>
  import {getDictByCodes, getDictValue} from "../../api/system/dict";

  export default {
    name: "user-log-view",
    props: {
      form: {
        type: Object
      },
    },
    data(){
      return {
        formVisible: false,
        dicts: {},

        option:{
          emptyBtn: false,
          submitBtn: false,
          column:[
            {
              label: "銀行號",
              prop: "bankNo",
              span: 24,
              hide: true,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入銀行號",
                trigger: "blur"
              }]
            },
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "表名",
              prop: "tableName",
              type: "select",
              disabled: true,
              dicData: [
                {
                  label: "網點鎖匙/密碼/實物交接登記表", value: "keypwd"
                },
                {
                  label: "業務印章交接登記表", value: "sealhandover"
                },
                {
                  label: "網點出納主管及專管員崗位變更記錄表", value: "postchange"
                },
                {
                  label: "查庫流水帳記錄表", value: "checkwarehouse"
                },
                {
                  label: "核對記錄表", value: "checklist"
                },
                {
                  label: "櫃員尾箱檢查流水帳記錄表", value: "tellertrunk"
                },
                {
                  label: "使用及出入庫登記表", value: "goodsuse"
                },
                {
                  label: "新開戶退件登記表", value: "returns"
                },
                {
                  label: "自助設備吞卡資料", value: "cardswallow"
                },
                {
                  label: "信息發佈", value: "message"
                },
              ],
            },
            {
              label: "員工號",
              prop: "personNo",
              disabled: true,
            },
            {
              label: "用戶姓名",
              prop: "personName",
              disabled: true,
            },
            {
              label: "操作類型",
              prop: "operationType",
              type: "select",
              disabled: true,
              dicData: [
                {
                  label: "新增", value: "add"
                },
                {
                  label: "上繳", value: "turnin"
                },
                {
                  label: "編輯", value: "edit"
                },
                {
                  label: "刪除", value: "del"
                },
                {
                  label: "上傳", value: "upload"
                },
                {
                  label: "發佈", value: "issue"
                },
                {
                  label: "審核", value: "approve"
                },
                {
                  label: "確認", value: "sure"
                },
                {
                  label: "簽收", value: "signin"
                },
                {
                  label: "一鍵移交", value: "transfer"
                },
              ],
            },
            {
              label: "舊數據",
              prop: "oldData",
              disabled: true,
              type: "textarea",
            },
            {
              label: "新數據",
              prop: "newData",
              disabled: true,
              type: "textarea",
            },
            {
              label: "操作時間",
              prop: "createTime",
              disabled: true,
              type: "datetime",
            },
          ],
          group:[
          ]
        },
        keypwdGroup: [{
          label: "網點鎖匙/密碼/實物交接登記表",
          column: [
            {
              label: "分類種類",
              prop: "category",
              checkStrictly: true,
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=key_type",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
           /* {
              label: "數量",
              prop: "number",
              type: "number",
              display: false,
            },*/
            {
              label: "交出人",
              prop: "handoverPersonName",
            },
            {
              label: "交出人員工號",
              prop: "handoverPersonNo",
            },
            {
              label: "接收人",
              prop: "receiverName",
            },
            {
              label: "接收人員工號",
              prop: "receiverNo",
            },
            {
              label: "交接日期",
              prop: "handoverDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",
            },
            {
              label: "備註",
              prop: "remark",
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
            },
            {
              label: "填報人",
              prop: "fillingPerson",
            },
          ],
        }],
        sealhandoverGroup: [{
          label: "業務印章交接登記表",
          column: [
            {
              label: "印章類型",
              prop: "sealType",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=seal_type",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
              search: true,
              searchMultiple: true,

            },
            {
              label: "印章編號",
              prop: "sealNo",
            },
            {
              label: "交出人",
              prop: "handoverPersonName",
            },
            {
              label: "交出人員工號",
              prop: "handoverPersonNo",
            },
            {
              label: "交接日期",
              prop: "handoverDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",
            },
            {
              label: "接收人",
              prop: "receiverName",
            },
            {
              label: "接收人員工號",
              prop: "receiverNo",
            },
            {
              label: "備註",
              prop: "remark",
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
            },
            {
              label: "填報人",
              prop: "fillingPerson",
            },
          ]
        }],
        postchangeGroup: [{
          label: "網點出納主管及專管員崗位變更記錄表",
          column: [
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "申請日期",
              prop: "applyDate",
              type: "datetime",
              format: "yyyy-MM-dd",
              // valueFormat: "yyyy-MM-dd",
            },
            {
              label: "生效日期",
              prop: "effectiveDate",
              type: "date",
              format: "yyyy-MM-dd",
              // valueFormat: "yyyy-MM-dd",
            },
            {
              label: "審批人",
              prop: "personName",
            },
            {
              label: "審批人員工號",
              prop: "personNo",
            },
            {
              label: "備註",
              prop: "remark",
            },
          ],
        }],
        checkwarehouseGroup: [{
          label: "查庫流水帳記錄表",
          column: [
            {
              label: "檢查時間開始",
              prop: "checkTimeBegin",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",

            },
            {
              label: "檢查時間結束",
              prop: "checkTimeEnd",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",

            },
            {
              label: "檢查單位",
              prop: "checkUnit",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=unit_type",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "檢查目的",
              prop: "checkPurpose",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_purpose",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "檢查內容",
              prop: "checkContent",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_content_warehouse",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "核對結果",
              prop: "checkResult",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_result",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "檢查人員",
              prop: "checkPersonName",
            },
            {
              label: "檢查人員工號",
              prop: "checkPersonNo",
              disabled: true,
            },
            {
              label: "備註(可簡要補充檢查發現情況)",
              prop: "remark",
              span: 24,
              labelWidth: 150,
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
            },
            {
              label: "填報人",
              prop: "fillingPerson",
            },
          ]
        }],
        tellertrunkGroup: [{
          label: "櫃員尾箱檢查流水帳記錄表",
          column: [
            {
              label: "檢查內容",
              prop: "checkContent",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_content_tellertrunk",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "檢查時間開始",
              prop: "checkTimeBegin",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",

            },
            {
              label: "檢查時間結束",
              prop: "checkTimeEnd",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              // valueFormat: "yyyy-MM-dd HH:mm",

            },
            {
              label: "檢查單位",
              prop: "checkUnit",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=unit_type",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },

            },
            {
              label: "本單位持有現金櫃員數量",
              prop: "holdingNumberUnit",
              type: "number",

            },
            {
              label: "本次檢查持有現金櫃員數量",
              prop: "holdingNumberCheck",
              type: "number",

            },
            {
              label: "檢查類型",
              prop: "checkType",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_type",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "核對結果",
              prop: "checkResult",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_result",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },

            {
              label: "檢查人員",
              prop: "checkPersonName",
            },
            {
              label: "檢查人員工號",
              prop: "checkPersonNo",
            },
            {
              label: "檢查人員姓名",
              prop: "checkPersonNameOut",
            },
            {
              label: "檢查人員工號或身份證後四位",
              prop: "checkPersonNoOut",
            },
            {
              label: "備註(可簡要補充檢查發現情況)",
              prop: "remark",
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
            },
            {
              label: "填報人",
              prop: "fillingPerson",
            },
            {
              label: "附件",
              prop: "enclosureName",
            },
          ]
        }],
        checklistGroup: [{
          label: "核對記錄表",
          column: [

            {
              label: "核對日期",
              prop: "checkDate",
              type: "datetime",
              format: "yyyy-MM-dd",
              // valueFormat: "yyyy-MM-dd",
            },
            {
              label: "分類",
              prop: "type",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_category",
              props:{
                label: "dictValue",
                value: "dictKey",
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "核對項目",
              prop: "item",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_item",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "核對內容/標準",
              prop: "content",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=check_content_normal",
              props:{
                label: "dictValue",
                value: "dictKey",
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "已核對",
              prop: "checked",
              type: "checkbox",
              dicData: [{
                value: 1
              }],
            },
            {
              label: "核對人",
              prop: "checkName",
              disabled: true,

            },
            {
              label: "核對人員工號",
              prop: "checkNo",

            },
            {
              label: "備註",
              prop: "remark",

            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
            },
          ]
        }],
        goodsuseGroup: [{
          label: "使用及出入庫登記表",
          column: [
            {
              label: "日期",
              prop: "date",
              type: "datetime",
              format: "yyyy-MM-dd",
              // valueFormat: "yyyy-MM-dd",
              placeholder: "",
            },
            {
              label: "憑證/實物種類",
              prop: "type",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=voucher_type",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "使用數量",
              prop: "useNumber",
              placeholder: "",
              type: "number",
            },
            {
              label: "領入數量",
              prop: "receiptNumber",
              placeholder: "",
              type: "number",
            },
            {
              label: "註銷數量",
              prop: "writeOffNumber",
              placeholder: "",
              type: "number",
            },
            {
              label: "開始編號",
              placeholder: "",
              prop: "beginNo",
            },
            {
              label: "結束編號",
              placeholder: "",
              prop: "endNo",
            },
            {
              label: "餘額",
              prop: "balance",
              type: "number",
              placeholder: "",
              disabled: true,
            },
            {
              label: "備註",
              prop: "remark",
              placeholder: "",
            },
            {
              label: "填報人員工號",
              prop: "fillingNo",
              placeholder: "",
            },
            {
              label: "填報人姓名",
              prop: "fillingName",
              placeholder: "",
            },
            {
              label: "確認人員工號",
              prop: "confirmNo",
              placeholder: "",
            },
            {
              label: "確認人姓名",
              prop: "confirmName",
              placeholder: "",
            },
            {
              label: "填報時間",
              prop: "fillingDate",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              placeholder: "",
            },
            {
              label: "確認人",
              prop: "personName",
            },
            {
              label: "確認人員工號",
              prop: "personNo",
            },
            {
              label: "審批時間",
              prop: "approveTime",
            },
          ]
        }],
        returnsGroup: [{
          label: "新開戶退件登記表",
          column: [
            {
              label: "業務類型",
              prop: "isPublic",
              type: "select",
              search: true,
              searchSpan: 4,
              dataType: "string",
              dicUrl: `/api/blade-system/dict/dictionary?code=business_type`,
              props: {
                label: "dictValue",
                value: "dictKey"
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
            },
            {
              label: "支行",
              prop: "subBank",
            },
            {
              label: "支行機構號",
              prop: "subOrgNo",
            },
            {
              label: "客戶名稱",
              prop: "customerName",
            },
            {
              label: "狀態",
              prop: "status",
              type: "select",
              dataType: "string",
              dicUrl: `/api/blade-system/dict/dictionary?code=returns_status`,
              props: {
                label: "dictValue",
                value: "dictKey"
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "退件原因",
              prop: "reason",
            },
            {
              label: "備註",
              prop: "remark",
            },
            {
              label: "條碼",
              prop: "barCode",
            },
            {
              label: "接辦行經辦",
              prop: "handlingBank",
            },
            {
              label: "接辦行覆核",
              prop: "handlingBankReview",
            },
            {
              label: "處理日期",
              prop: "handlingDate",
              type: "datetime",
              format: "yyyy-MM-dd",
              // valueFormat: "yyyy-MM-dd",
            },
            {
              label: "經辦",
              prop: "handler",
            },
            {
              label: "跟進情況",
              prop: "handlingStatus",
              type: "select",
              dataType: "string",
              dicUrl: `/api/blade-system/dict/dictionary?code=processing_status`,
              props: {
                label: "dictValue",
                value: "dictKey"
              },dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },

            },
            {
              label: "支行備註",
              prop: "bankRemark",
            },
            {
              label: "支行確認人員工號",
              prop: "bankConfirmNo",
            },
            {
              label: "支行確認人姓名",
              prop: "bankConfirmName",
            },
            {
              label: "確認日期",
              prop: "bankConfirmTime",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              // valueFormat: "yyyy-MM-dd HH:mm:ss",
            },
            /*{
              label: "待辦人",
              prop: 'personNo'
            },*/
          ]
        }],
        cardswallowGroup: [{
          label: "自助設備吞卡資料",
          column: [
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "發送日期",
              prop: "sendDate",
              type: "datetime"
            },
            {
              label: "發送支行",
              prop: "sendBank",
            },
            /*{
              label: "發送支行機構號",
              prop: "sendOrgNo",
            },*/
            {
              label: "卡號",
              prop: "cardNo",
            },
            {
              label: "卡序號",
              prop: "cardSerialNo",
            },
            {
              label: "其他",
              prop: "machine",
            },
            {
              label: "機號",
              prop: "machineNo",
            },
            {
              label: "沒收卡日期",
              prop: "swallowDate",
              type: "date",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
            },
            {
              label: "卡狀態",
              prop: "cardStatus",
            },
            {
              label: "發送狀態",
              prop: "sendStatus",
              type: "select",
              dicUrl: `/api/blade-system/dict/dictionary?code=send_status`,
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
            },
            {
              label: "備註",
              prop: "remark",
            },
            {
              label: "支行確認人員工號",
              prop: "bankConfirmNo",
            },
            {
              label: "支行確認人姓名",
              prop: "bankConfirmName",
            },
            {
              label: "確認日期",
              prop: "bankConfirmTime",
            },
          ]
        }],
        messageGroup: [{
          label: "信息發佈",
          column: [
            {
              label: "標題",
              prop: "title",
              span: 24,
            },
            {
              label: "內文",
              prop: "content",
              type: "textarea",
            },
            {
              label: "查閱部門",
              prop: "deptId",
              type: "tree",
              // multiple: true,
              dicData: [],
              props: {
                label: "title"
              },
            },
            {
              label: "附件原名",
              prop: "originalName",
            },
            {
              label: "附件拓展名",
              prop: "extension",
            },
            {
              label: "附件大小",
              prop: "attachSize",
              append: "KB",
            },
          ]
        }],
      }
    },
    created() {
      this.initDict().then(res => {
        this.initForm(res);
        this.formVisible = true;
      });
    },
    methods: {
      initDict(){
        return new Promise((resolve, reject) => {
          let codeArr = ['business_type','returns_status','processing_status','send_status', 'seal_type', 'key_type', 'unit_type', 'check_purpose', 'check_content_warehouse', 'check_content_tellertrunk', 'check_type', 'check_result', 'check_category', 'check_item', 'check_content_normal', 'voucher_type'];
          let dictObj = {};
          getDictByCodes(codeArr.join()).then(res => {
            let data = res.data.data;
            for (let j = 0; j < data.length; j++) {
              let item = data[j];
              dictObj['' + item.code + item.dictKey] = item.dictValue;
            }
            resolve(dictObj);
          })
          // }
        })
      },
      initForm(dictObj) {
        const newData = JSON.parse(!this.form.newData ? "{}" : this.form.newData);
        const oldData = JSON.parse(!this.form.oldData ? "{}" : this.form.oldData);
        const tableName = this.form.tableName;
        let arr = this[tableName + 'Group'][0].column;
        if (this.form.operationType == 'edit') {
          for (let i = 0; i < arr.length; i++) {
            let item = arr[i];
            item.disabled = true;
            let prop = item.prop;

            let newVal = newData['' + prop];
            let oldVal = oldData['' + prop];
            if (newVal && newVal != oldVal) {
              item.labelTip = oldVal;
              if (item.type == 'select'){
                item.labelTip = dictObj['' + item.dicUrl.split('code=')[1] + oldVal]
              }
            } else {
              delete item.labelTip;
            }
          }
        } else {
          for (let i = 0; i < arr.length; i++) {
            let item = arr[i];
            item.disabled = true;
            item.placeholder = " ";
            delete item.labelTip;
          }
        }
        this[tableName + 'Group'][0].column = arr;
        delete this.option.group;
        this.option.group = this[tableName + 'Group'];
        if (this.form.operationType == 'del'){
          Object.assign(this.form, oldData)
        }else{
          Object.assign(this.form, newData)
        }

      },
      handleSubmit(form) {
        this.$message.success(JSON.stringify(this.form))
      },
      handleTabClick(event) {
        this.$message.success(event);
      }
    }
  }
</script>

<style scoped>

</style>
