import {
  summaryListData,
  voucherSaveOrUpdate,
  subjectData,
  voucherGetCurrentNum,
  voucherDetail,
  assistListByAssist,
  getBySubjectId,
  listByDeptId,
  getUserProfile
} from "@/api/dataScreen/voucher/add";
import { getLoginBook, delVoucher } from "@/api/dataScreen/voucher/list";
import {array_toMap, CHECK } from "@/utils/common.js";
export default {
  props: {
    data: {}
  },
  data () {
    return {
      isLoad: false,
      permanentDetail: {},
      initialIndex:0,
      voucherTitle: "记账凭证", //凭证标题
      savaBtnText: "保存并新增",
      searchFormField: {
        voucherId: "", //凭证号
        voucherWord: "1", //凭证字 记
        selectDate: "", //日期
        attachedNum: 0, //附单据
        noteText: "", //备注
        userName: "", //制单人
        checkedBy: "", //审核人
        qrCode: "", //附件二维码
        barCodeList:'',  //审批人
        checkedTime:'',  //审批时间
        accountedBy: '', // 记账人
      },
      voucherAttachmentAmount:'0',  //用户是否可以自己编辑上传附件数  0不可编辑 1可编辑
      chargeItme: {
        //记账凭证表单数据
        items: [
          // {
          //   voucherSummary: '', //摘要
          //   subjectNameAll: '', //会计科目名称
          //   jieAmount: '', //借方金额
          //   daiAmount: '', //贷方金额
          //   subjectId: '', //会计科目Id
          //   subjectMoney: "",
          // }
        ],
        dataStatus: [
          //   {
          //   voucherSummary: true, //摘要
          //   subjectNameAll: true, //会计科目
          //   jieAmount: true, //借方金额
          //   daiAmount: true, //贷方金额
          //   assistState: true, //辅助核算
          //   assistType: t, //辅助核算-显示类型
          // }
        ],
      },
      voucherComputeIpt:'',  //凭证计算的值
      voucherComputeWidth:'220',  //凭证计算的值-宽度
      //当前选择凭证行数据
      vocherListSelect: {
        currentLine: 0, // 当前选择凭证行
        currentField:'', //当前选择列
      },
      debitAmount: 0, //借方总金额
      lenderAmount: 0, //贷方总金额
      capitalAmount: "", //大写总金额
      noteStatue: false, //备注显示状态
      visiblePop: {
        uploadTitle: "添加附件",
        uploadPermission: false, //上传附件状态
        uploadVisible: false, //上传附件显示状态 false
        uploadVisible_gpy: false, //上传附件高拍仪
        addTemplateVisible: false, //新增模版显示状态
        selectTemplateVisible: false, //选择模版显示状态
      },
      ButtonState: {
        saveBtn: true, //保存按钮
        addSaveBtn: true, //保存并新增按钮
      },
      fileListImg: [], //上传附件图片列表
      fileList: [], //上传附件图片列表
      fileListData: [], //上传附件图片列表参数
      uploadImg: {
        //上传图片配置
        uploadImgUrl: "/api/finance/voucher/upload",
        uploadImgHeaders: {
          // Authorization: "Bearer " + getToken(),
        },
        uploadImgData: {
          id: "", //凭证id
          fileType: "", //当前选择凭证类型
          token: null,  // 外部文件上传服务身份标识
        },
        shotMeterDisabled: 4,   //成者高拍仪
        shotMeterDisabled_km: 4,  //科密高拍仪
        shotMeterDisabled_lt:4,  //良田高拍仪
        attachmentLoading: false, // 上传图片请求loading
        fileTypeOptions: [], //上传图片类型
        dealWithFileList: [], //处理后图片的list
        baseRoutingUrl: '/api', //图片默认显示地址
        //附件旋转角度
        rotationAngle:0,
      },

      vouterTime: 0,
      AnewData: 0, //处理多按键事件冲突
      BnewData: 0, //处理多按键事件冲突
      thisEventKey: 0, //当前按键事件
      AbstractList: [], //摘要显示列表
      SubjectsList: [], //会计科目显示列表
      SubjectsMap: {}, //会计科目显示映射
      //是否禁用编辑
      isCheckedBy: false,
      //是否已审核凭证
      approvedcredentials: false,
      //是否是修改凭证
      isModifyType: false,

      focusVisible: false, //点击图片方法
      focusImgUrl: "", //图片Url
      isTemplate: false, //是否是模版
      isModifyVoucher: false, //是否是修改组件
      templateList: {
        //图片列表
        id: "",
        saveBtndisabled: false,
      },
      //辅助核算
      assistAccounting: {
        accordingState: false, //辅助核算显隐
        unitSelectList: [], //单位选项
        personalSelectList: [], //个人选项
        numSelectList: [], //部门选项
        projectSelectList: [], //项目选项
        dataList: [], //数据存储
        numRows: "", //当前点击行数
        accordingType: "", //当前可选选项
        allDataList: [], //默认全部辅助核算数据
      },
      voucherType: "", //凭证类型
      addVoucherTemplate: "", //修改凭证－数据

      isLastVoucher: true, //切换凭证按钮状态 false 可切换 true不可以切换
      isFirstVoucher: false, //切换凭证按钮状态 false 可切换 true不可以切换
      voucherWord: [], //凭证字 字典
      printerType: true, //是否能点打印按钮
      // ----打印凭证 开始
      printObj: {
        //凭证数据
        list: [],
        //弹窗显示隐藏
        visible: false,
        chiefAccountant: "", //账套审核人
        qrCode: "",
      },
      // ----打印凭证 结束

      //选择摘要弹窗
      bookSummary: {
        visible: false,
        tite: "",
        row: "", //点击行数
      },
      subjectsMore: {
        visible: false,
        tite: "",
        row: "", //点击行数
      },
      highShotMeter: {
        currentMeter: "", //当前选择高拍仪
        selectList: [], //高拍仪选项
      },
      isOnlySave: false, //是否只是保存
      isCtrlSActive: true, //是否允许ctrl+s快捷键保存 true允许
      //是否是关联合同收款科目   科目isContraction:Y显示弹窗
      contraction:{
        visible:false,  //弹窗显隐
        currentIndex:0, //当前选择凭证行
        contractionFundPlanIdList: [],
      },
      //凭证审批人
      scanCode: {
        visible: false,
        voucherId: null
      },
      //固定资产弹窗相关信息
      fixedAssets:{
        open:false,
        list:[],
        //currentIndex:'',  //当前显示tab页签
      },
      balanceVoucher: {
        visible: false,
      },
      multiSelectSubject: {
        visible: false,
      },
      paste: false,
      insertVoucher: 0,
      accountant: '',
      redDashedItems: '',
    };
  },
  beforeDestroy() { // 在组件生命周期结束的时候销毁。
    window.removeEventListener('keydown', this.keyDownOther, false)
    window.removeEventListener('click', this.clickOther, false)
  },
  watch: {
    "$route.query": function (newVal, oldVal) {
      if (newVal.type == "modify") {
        this.isModifyType = true;
      } else {
        this.isModifyType = false;
      }
    },
    chargeItme: {
      handler(newValue, oldValue) {
        let routeType = 'view';
        if (
            !(
                routeType == "view" ||
                routeType == "modify" ||
                this.redDashedItems != undefined
            )
        ) {
          // don't update watch value in handler
          var listData = JSON.parse(JSON.stringify(newValue));
          listData.date = new Date().getTime();
          listData = JSON.stringify(listData);
          var addMinute = new Date(new Date().getTime() + 10 * 60 * 1000);
          // Cookies.set("voucherList", listData, { expires: addMinute });
          window.localStorage.setItem("voucherList", listData);
          this.assistAccounting.date = new Date().getTime();
          var assistAccountingString = JSON.stringify(this.assistAccounting);
          // debugger;
          window.localStorage.setItem(
              "voucherAssistAccounting",
              assistAccountingString
          );
        }
      },
      deep: true,
    },
    // "$route.path": function (newVal, oldVal) {
    //   if (newVal == "/voucher/add") {
    //     if (this.$route.query.id) {
    //       this.$set(this.ButtonState, "saveBtn", false);
    //       this.$set(this.ButtonState, "addSaveBtn", false);
    //       this.$set(this.assistAccounting, "accordingState", false);
    //       this.$set(this.assistAccounting, "numRows", "");
    //       this.isCheckedBy = false;
    //       this.approvedcredentials = false;
    //       this.editorData();
    //     } else {
    //       console.log('22')
    //       this.initData();
    //       //初始化新增接口数据
    //       this.initAddAxios();
    //       //初始化当前日期
    //       this.getNowTime();
    //     }
    //   }
    // },
    redDashedItems: function (newVal, oldVal) {
      if (newVal == undefined) {
        return false;
      }

      this.redDashed(newVal);
    },
    modifyAddVoucher: function (newVal, oldVal) {
      if (newVal == undefined) {
        return false;
      }
      this.addVoucherTemplate = this.addVouchers;
      this.modifyAddVoucherFun(this.modifyAddVoucher);
    },
    modifyTemplate: function (newVal, oldVal) {
      if (newVal == undefined) {
        return false;
      }
      this.modifyTemplateFun(newVal);
    },
    // addVouchers: function (newVal, oldVal) {
    //   if (newVal == undefined) {
    //     return false;
    //   }
    //   this.addVoucherTemplate = newVal;
    //   console.log(newVal);
    //   this.modifyAddVoucherFun(this.modifyAddVoucher);
    // },
  },
  computed: {
    computeStyle() {
      return function (local, data) {
        if (
            data.includes("1") &&
            data.includes("2") &&
            data.includes("3") &&
            data.includes("4")
        ) {
          //单位
          if (local == "dw") {
            return "calc((100% - 442px) * 0.3)";
          }
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.2)";
          }
          //部门
          if (local == "sl") {
            return "calc((100% - 442px) * 0.2)";
          }
          //项目
          if (local == "xm") {
            return "calc((100% - 442px) * 0.3)";
          }
        } else if (
            data.includes("1") &&
            data.includes("2") &&
            data.includes("3")
        ) {
          //单位
          if (local == "dw") {
            return "calc((100% - 442px) * 0.5)";
          }
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.3)";
          }
          //部门
          if (local == "sl") {
            return "calc((100% - 442px) * 0.2)";
          }
        } else if (
            data.includes("2") &&
            data.includes("3") &&
            data.includes("4")
        ) {
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.4)";
          }
          //部门
          if (local == "sl") {
            return "calc((100% - 442px) * 0.2)";
          }
          //项目
          if (local == "xm") {
            return "calc((100% - 442px) * 0.4)";
          }
        } else if (data.includes("1") && data.includes("2")) {
          //单位
          if (local == "dw") {
            return "calc((100% - 442px) * 0.6)";
          }
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.4)";
          }
        } else if (data.includes("2") && data.includes("3")) {
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.6)";
          }
          //部门
          if (local == "sl") {
            return "calc((100% - 442px) * 0.4)";
          }
        } else if (data.includes("3") && data.includes("4")) {
          //项目
          if (local == "xm") {
            return "calc((100% - 442px) * 0.6)";
          }
          //部门
          if (local == "sl") {
            return "calc((100% - 442px) * 0.4)";
          }
        }else if (data.includes("2") && data.includes("4")) {
          //个人
          if (local == "gr") {
            return "calc((100% - 442px) * 0.6)";
          }
          //项目
          if (local == "xm") {
            return "calc((100% - 442px) * 0.4)";
          }

        }else if (data.includes("1") && data.includes("4")) {

          //单位
          if (local == "dw") {
            return "calc((100% - 442px) * 0.6)";
          }
          //项目
          if (local == "xm") {
            return "calc((100% - 442px) * 0.4)";
          }

        }else if (data.includes("1") && data.includes("3")) {

          //单位
          if (local == "dw") {
            return "calc((100% - 442px) * 0.6)";
          }
          //项目
          if (local == "sl") {
            return "calc((100% - 442px) * 0.4)";
          }

        }  else if (data.includes("1")) {
          if (local == "dw") {
            return "calc((100% - 442px) )";
          }
        } else if (data.includes("2")) {
          if (local == "gr") {
            return "calc((100% - 442px) )";
          }
        } else if (data.includes("3")) {
          if (local == "sl") {
            return "calc((100% - 442px) )";
          }
        } else if (data.includes("4")) {
          if (local == "xm") {
            return "calc((100% - 442px) )";
          }
        }
      };
    },
    isSaved(){
      return !!this.uploadImg.uploadImgData.id;
    },
    isView() {
      return "view" === "view";
    },
  },
  created () {
    let voucherType =  this.$route.query.voucherType;
    //初始化公用接口数据
    this.initAxios();
    if (this.$route.query.voucherType != undefined ) {
      this.voucherType = voucherType;
    }
    if (this.data.voucherId) {
      this.editorData();
      this.$set(this.uploadImg.uploadImgData, "id", this.data.voucherId);
    } else {
      const voucherList = window.localStorage.getItem("voucherList");
      if (voucherList) {
        var voucherArr = JSON.parse(voucherList);
        let currentDate = new Date().getTime();
        if (currentDate - voucherArr.date < FINANCE.VOUCHER_CACHE_LIFECYCLE) {
          this.chargeItme = voucherArr;
          this.$set(this.ButtonState, "saveBtn", false);
          this.$set(this.ButtonState, "addSaveBtn", false);
          this.combinedNum();
        } else {
          this.initData();
        }
      } else {
        this.initData();
      }
      //初始化新增接口数据
      if(this.$route.query.num > 0) // 插入凭证
      {
        this.insertVoucher = this.$route.query.num;
        this.$set(this.searchFormField, "voucherId", this.$route.query.num);
      }
      else
        this.initAddAxios();
      console.log("插入凭证: " + this.insertVoucher);
      //初始化当前日期
      this.getNowTime().then(() => {
        this.$set(this.searchFormField, 'accountedBy', this.accountant);
      });
    }
    const voucherAssistAccounting = window.localStorage.getItem(
        "voucherAssistAccounting"
    );

    if (voucherAssistAccounting) {
      var voucherAssistAccountingArr = JSON.parse(voucherAssistAccounting);
      let currentDate = new Date().getTime();
      if (currentDate - voucherAssistAccountingArr.date < FINANCE.VOUCHER_CACHE_LIFECYCLE) {
        voucherAssistAccountingArr.accordingState = false;
        this.assistAccounting = voucherAssistAccountingArr;
      }
    }
    if ("view" == "modify") {
      this.isModifyType = true;
    }

    //凭证字-字典
    this.getDicts("voucher_word").then((response) => {
      this.voucherWord = response.data;
    });

    //初始化事件
    this.globalEvent();
    //红冲初始化
    this.redDashed(this.redDashedItems);
    //修改初始化
    this.modifyAddVoucherFun(this.modifyAddVoucher);
    //修改模版初始化
    this.modifyTemplateFun(this.modifyTemplate);
    //禁用外部上传 this.checkUsingExternalUploadService();
  },
  mounted () {
  },
  methods: {
    close () {
      this.$emit('close')
    },
    changeAuxiliaryFun(name, index) {
      let baseDate =
          this.assistAccounting.dataList[this.assistAccounting.numRows];
      if (name == "jieAmount") {
        this.$set(baseDate[index], "daiAmount", "");
      } else if (name == "daiAmount") {
        this.$set(baseDate[index], "jieAmount", "");
      }
      //借方金额
      let jieAllMoney = 0;
      //贷方金额
      let daiAllMoney = 0;
      for (let i = 0; i < baseDate.length; i++) {
        jieAllMoney += Number(baseDate[i].jieAmount);
        daiAllMoney += Number(baseDate[i].daiAmount);
      }
      if (jieAllMoney < daiAllMoney) {
        //借小于贷
        let num = daiAllMoney - jieAllMoney;
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "jieAmount",
            ""
        );
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "daiAmount",
            num
        );
      } else if (jieAllMoney == daiAllMoney) {
        //借等于贷
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "jieAmount",
            0
        );
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "daiAmount",
            ""
        );
      } else {
        //借大于贷
        let num = jieAllMoney - daiAllMoney;
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "jieAmount",
            num
        );
        this.$set(
            this.chargeItme.items[this.assistAccounting.numRows],
            "daiAmount",
            ""
        );
      }
      this.$forceUpdate();
      this.combinedNum();
    },
    editorData(oId) {
      let uId = {};
      if (oId) {
        uId = { id: oId };
      } else {
        uId = { id: this.data.voucherId };
      }
      const loading = this.$loading({
        lock: true,
        text: "正在查询",
        spinner: "el-icon-loading",
        background: "rgba(255,255,255,0.76)",
      });
      voucherDetail(uId).then((res) => {
        loading.close();
        if (res.code == 200) {
          let content = res.data;
          this.printerType = false;
          this.PageRendering(content);
        }
      });

      //查询该账套审核人
      let loginDeptId = this.$store.state.user.loginDeptId;
      let bookType = this.$store.getters.bookType;
      listByDeptId({ loginDeptID: loginDeptId }).then((response) => {
        const data = response.rows;
        for (let i = 0; i < data.length; i++) {
          if (data[i].bookType == bookType) {
            this.printObj.chiefAccountant = data[i].chiefAccountant;
            break;
          }
        }
        let checkedBy = this.searchFormField.checkedBy;
        let checkedByData = "";
        if (
            typeof checkedBy == undefined ||
            checkedBy == 0 ||
            checkedBy == "" ||
            checkedBy == null
        ) {
          checkedByData = this.printObj.chiefAccountant;
        } else {
          checkedByData = checkedBy;
        }
        //审核人
        this.$set(this.searchFormField, "checkedBy", checkedByData);
      });
    },
    PageRendering(content) {
      let routeType = "view";
      const baseImgUrl = '/api';
      //页面渲染
      if (content.checkedBy != null) {
        this.isCheckedBy = true;
        this.approvedcredentials = true;
      }
      this.$set(this.searchFormField, "voucherId", content.num); //凭证号
      this.$set(this.searchFormField, "selectDate", content.bookDate); //记账日期
      this.$set(this.searchFormField, "voucherWord", content.voucherWord || '1'); //记账日期
      if(this.voucherAttachmentAmount == 0){  //自动计算附件数
        this.$set(
            this.searchFormField,
            "attachedNum",
            content.attachmentList.length
        ); //附单据
      }
      this.$set(this.searchFormField, "noteText", content.remarks); //备注
      this.$set(this.searchFormField, "attachedNum", content.attachmentAccount); //用户上传附件数

      //制单人
      this.$set(this.searchFormField, "userName", content.preparedBy);

      //记账人
      this.$set(this.searchFormField, "accountedBy", content.accountedBy);

      let checkedBy = content.checkedBy; // ??? let checkedBy = this.searchFormField.checkedBy;
      let checkedByData = "";
      if (
          typeof checkedBy == "undefined" ||
          checkedBy == 0 ||
          checkedBy == "" ||
          checkedBy == null
      ) {
        checkedByData = this.printObj.chiefAccountant;
      } else {
        checkedByData = content.checkedBy;
      }
      // //审核人
      this.$set(this.searchFormField, "checkedBy", checkedByData);

      //id
      this.$set(this.uploadImg.uploadImgData, "id", content.id);

      //附件二维码图片
      this.$set(this.searchFormField, "qrCode", content.qrCode);

      //审批人
      let str = [];
      content.barCodeList.forEach((v,i)=>{
        str.push(v.userName)
      })
      this.$set(this.searchFormField, "barCodeList",  str.join(","));

      //审批时间
      this.$set(this.searchFormField, "checkedTime", content.checkedTime);

      //凭证数据
      let credentialsData = [];
      let credentialsDataStatus = [];
      let assistAccounList = [];
      let allAssistAccounList = []; //全部辅助核算数据
      let UdetailList = content.detailList;
      console.log(UdetailList)
      for (let i = 0; i < UdetailList.length; i++) {

        credentialsData.push({
          voucherSummary: UdetailList[i].voucherSummary, //摘要
          subjectNameAll: UdetailList[i].subjectNameAll, //会计科目名称
          jieAmount:
              UdetailList[i].jieAmount == null ? "" : UdetailList[i].jieAmount, //借方金额
          daiAmount:
              UdetailList[i].daiAmount == null ? "" : UdetailList[i].daiAmount, //贷方金额
          subjectId: UdetailList[i].subjectId, //会计科目Id
          subjectMoney: "",
          quantityNum:  UdetailList[i].quantityNum, //数量核算科目-数量
          quantityUnit: UdetailList[i].quantityUnit, //数量核算科目-单位
          contractionFundPlanId:UdetailList[i].contractionFundPlanId //关联合同Id
        });
        //修改凭证默认加载科目余额
        // if (routeType == "modify") {
        //   getBySubjectId({ subjectId: UdetailList[i].subjectId }).then(
        //     (res) => {
        //       if (res.code == 200) {
        //         let bybalance = res.data.qmye;
        //         let endBalance = bybalance == null ? 0 : bybalance;
        //         this.$set(this.chargeItme.items[i], "subjectMoney", endBalance);
        //       }
        //     }
        //   );
        // }

        let whetherNotAuxiliary = false;
        let auxiliaryType = "";

        if (!UdetailList[i].assistList){UdetailList[i].assistList = [];}

        if (UdetailList[i].assistList.length > 0) {
          whetherNotAuxiliary = true;
          auxiliaryType = UdetailList[i].assistList[0].assist;
        }

        credentialsDataStatus.push({
          voucherSummary: true, //摘要
          subjectNameAll: true, //会计科目
          jieComputeAmount:true,  //借方金额计算弹窗
          jieAmount: true, //借方金额
          daiComputeAmount:true,  //贷方金额计算弹窗
          daiAmount: true, //贷方金额
          assistState: whetherNotAuxiliary, //辅助核算
          assistType: auxiliaryType, //辅助核算-显示类型
          isQuantity: ((UdetailList[i].quantityNum == null || UdetailList[i].quantityNum == '') && (UdetailList[i].quantityUnit == null || UdetailList[i].quantityUnit == '')) ?false:true, //是否显示数量核算科目
          // isContraction:newList[0].isContraction=='Y'?true:false //是否显示关联合同收款科目
          isContraction:false //是否显示关联合同收款科目
        });

        //辅助核算相关
        assistAccounList.push(UdetailList[i].assistList);
        //全部辅助核算数据
        // allAssistAccounList
        for (let a = 0; a < UdetailList[i].assistList.length; a++) {
          allAssistAccounList.push(UdetailList[i].assistList[a]);
        }
      }
      this.assistAccounting.dataList = assistAccounList;
      this.assistAccounting.allDataList = allAssistAccounList;
      this.chargeItme.items = credentialsData;
      this.chargeItme.dataStatus = credentialsDataStatus;
      //上传图片数据
      let UattachmentList = content.attachmentList;
      let UfileList = []; //上传图片列表
      let UfileListData = []; //上传附件图片列表参数
      for (let i = 0; i < UattachmentList.length; i++) {
        let fileName = UattachmentList[i].fileName;
        let subIndex = fileName.lastIndexOf(".");
        let ext = fileName.substring(subIndex + 1, fileName.length);
        let urls = "";
        if (ext == "xlsx" || ext == "xls") {
          urls = require("./icon_excel.jpg");
        } else if (ext == "doc" || ext == "docx") {
          urls = require("./icon_word.jpg");
        } else if (ext == "pdf") {
          urls = require("./icon_pdf.jpg");
        } else if (ext == "zip") {
          urls = require("./icon_zip.jpg");
        } else {
          urls = baseImgUrl + (UattachmentList[i].thumUrl || UattachmentList[i].fileUrl);
        }
        UfileList.push({
          name: UattachmentList[i].fileName,
          fileUrl: UattachmentList[i].fileUrl,
          url: urls,
          id: UattachmentList[i].id,
          fileType: UattachmentList[i].fileType,
          listIndex:parseInt(UattachmentList[i].fileType)-1,
          thumUrl: UattachmentList[i].thumUrl || UattachmentList[i].fileUrl,
        });
        UfileListData.push({
          id: UattachmentList[i].id,
        });
      }
      if (content.checkedBy == null) {
        if (routeType == "view") {
          this.isCheckedBy = true;
          this.$set(this.ButtonState, "saveBtn", true);
          this.$set(this.ButtonState, "addSaveBtn", true);
          this.approvedcredentials = false;
        } else {
          this.approvedcredentials = false;
          this.isCheckedBy = false;
          this.$set(this.ButtonState, "saveBtn", false);
          this.$set(this.ButtonState, "addSaveBtn", false);
        }
      } else {
        this.isCheckedBy = true;
        this.approvedcredentials = true;
        this.$set(this.ButtonState, "saveBtn", true);
        this.$set(this.ButtonState, "addSaveBtn", true);
      }
      this.fileList = UfileList;
      this.fileListData = UfileListData;
      this.dealWithFile();
      this.combinedNum();
    },
    redDashed(item) {
      if (item == undefined) {
        return false;
      }
      let content = item;
      this.$set(this.uploadImg.uploadImgData, "id", content.id);

      this.$set(this.searchFormField, "selectDate", content.bookDate); //记账日期
      if(this.voucherAttachmentAmount == 0){  //自动计算附件数
        this.$set(
            this.searchFormField,
            "attachedNum",
            content.attachmentList.length
        ); //附单据
      }
      this.$set(this.searchFormField, "noteText", content.remarks); //备注
      this.$set(this.searchFormField, "attachedNum", content.attachmentAccount); //用户上传附件数
      //能否打印
      this.printerType = false;

      //审核人
      this.$set(this.searchFormField, "checkedBy", content.checkedBy);
      //审批人
      let str = [];
      content.barCodeList.forEach((v,i)=>{
        str.push(v.userName)
      })
      this.$set(this.searchFormField, "barCodeList",  str.join(","));
      //审批时间
      this.$set(this.searchFormField, "checkedTime", content.checkedTime);

      // console.log(this.SubjectsList)
      //获取会计科目列表数据
      //凭证数据
      let credentialsData = [];
      let credentialsDataStatus = [];
      let allAssistAccounList = []; //全部辅助核算数据
      let UdetailList = content.detailList;
      for (let i = 0; i < UdetailList.length; i++) {
        credentialsData.push({
          voucherSummary: UdetailList[i].voucherSummary, //摘要
          subjectNameAll: UdetailList[i].subjectNameAll, //会计科目名称
          jieAmount:
              UdetailList[i].jieAmount == null ? "" : UdetailList[i].jieAmount, //借方金额
          daiAmount:
              UdetailList[i].daiAmount == null ? "" : UdetailList[i].daiAmount, //贷方金额
          subjectId: UdetailList[i].subjectId, //会计科目Id
          subjectMoney: "",
          quantityNum:  UdetailList[i].quantityNum, //数量核算科目-数量
          quantityUnit: UdetailList[i].quantityUnit, //数量核算科目-单位
          contractionFundPlanId:UdetailList[i].contractionFundPlanId  //关联合同收款科目
        });
        credentialsDataStatus.push({
          voucherSummary: true, //摘要
          subjectNameAll: true, //会计科目
          jieAmount: true, //借方金额
          jieComputeAmount:true,  //借方金额计算弹窗
          daiAmount: true, //贷方金额
          daiComputeAmount:true,  //贷方金额计算弹窗
          assistState: false, //辅助核算
          assistType: "", //辅助核算-显示类型
          isQuantity: ((UdetailList[i].quantityNum == null || UdetailList[i].quantityNum == '') && (UdetailList[i].quantityUnit == null || UdetailList[i].quantityUnit == '')) ?false:true, //是否显示数量核算科目
          // isContraction:newList[0].isContraction=='Y'?true:false //是否显示关联合同收款科目
          isContraction:false  //是否显示关联合同收款科目
        });
        //全部辅助核算数据
        // allAssistAccounList
        for (let a = 0; a < UdetailList[i].assistList.length; a++) {
          allAssistAccounList.push(UdetailList[i].assistList[a]);
        }
      }
      this.assistAccounting.allDataList = allAssistAccounList;
      this.chargeItme.items = credentialsData;
      this.chargeItme.dataStatus = credentialsDataStatus;
      //上传图片数据
      let UattachmentList = content.attachmentList;
      let UfileList = []; //上传图片列表
      let UfileListData = []; //上传附件图片列表参数
      for (let i = 0; i < UattachmentList.length; i++) {
        let fileName = UattachmentList[i].fileName;
        let subIndex = fileName.lastIndexOf(".");
        let ext = fileName.substring(subIndex + 1, fileName.length);
        let urls = "";
        if (ext == "xlsx" || ext == "xls") {
          urls = require("./icon_excel.jpg");
        } else if (ext == "doc" || ext == "docx") {
          urls = require("./icon_word.jpg");
        } else if (ext == "pdf") {
          urls = require("./icon_pdf.jpg");
        } else if (ext == "zip") {
          urls = require("./icon_zip.jpg");
        } else {
          urls = this.uploadImg.baseRoutingUrl + (UattachmentList[i].thumUrl || UattachmentList[i].fileUrl);
        }
        UfileList.push({
          name: UattachmentList[i].fileName,
          fileUrl: UattachmentList[i].fileUrl,
          url: urls,
          id: UattachmentList[i].id,
          fileType: UattachmentList[i].fileType,
          listIndex:parseInt(UattachmentList[i].fileType)-1,
          thumUrl: UattachmentList[i].thumUrl || UattachmentList[i].fileUrl,
        });
        UfileListData.push({
          id: UattachmentList[i].id,
        });
      }
      if (content.checkedBy == null) {
        this.isCheckedBy = true;
        this.approvedcredentials = false;
      } else {
        this.isCheckedBy = true;
        this.approvedcredentials = true;
      }
      this.fileList = UfileList;
      this.fileListData = UfileListData;
      this.$set(this.ButtonState, "saveBtn", false);
      this.$set(this.ButtonState, "addSaveBtn", false);
      this.combinedNum();
      this.dealWithFile();
    },
    modifyAddVoucherFun(item) {
      //数据 item
      if (item == undefined) {
        return false;
      }
      this.addVoucherTemplate = this.addVouchers;
      let content = item;
      this.$set(this.uploadImg.uploadImgData, "id", item.id);
      this.isModifyVoucher = true;

      if (this.addVoucherTemplate.voucherId == null) {
        this.voucherType = this.voucherTypes;

        //初始化新增接口数据
        this.initAddAxios();
        //初始化当前日期
        this.getNowTime();
        //凭证数据
        //??? this.SubjectsList = res.rows;
        let credentialsData = [];
        let credentialsDataStatus = [];

        for (let i = 0; i < content.length; i++) {
          credentialsData.push({
            voucherSummary: content[i].voucherSummary, //摘要
            subjectNameAll: content[i].subjectNameAll, //会计科目名称
            jieAmount: content[i].jieAmount == null ? "" : content[i].jieAmount, //借方金额
            daiAmount: content[i].daiAmount == null ? "" : content[i].daiAmount, //贷方金额
            subjectId: content[i].subjectId, //会计科目Id
            subjectMoney: "",
            quantityNum: content[i].quantityNum || null, //数量核算科目-数量
            quantityUnit: content[i].quantityUnit || null, //数量核算科目-单位
            contractionFundPlanId: null  //关联合同收款科目
          });
          credentialsDataStatus.push({
            voucherSummary: true, //摘要
            subjectNameAll: true, //会计科目
            jieAmount: true, //借方金额
            jieComputeAmount:true,  //借方金额计算弹窗
            daiAmount: true, //贷方金额
            daiComputeAmount:true,  //贷方金额计算弹窗
            assistState: false, //辅助核算
            assistType: "", //辅助核算-显示类型
            isQuantity: ((content[i].quantityNum == null || content[i].quantityNum == '') && (content[i].quantityUnit == null || content[i].quantityUnit == '')) ?false:true, //是否显示数量核算科目
            // isContraction:newList[0].isContraction=='Y'?true:false //是否显示关联合同收款科目
            isContraction:false  //是否显示关联合同收款科目
          });
        }
        // this.chargeItme.items = credentialsData;
        this.$set(this.chargeItme, "items", credentialsData);
        this.chargeItme.dataStatus = credentialsDataStatus;
        //上传图片数据
        let UattachmentList = this.voucherAttachment;
        let UfileList = []; //上传图片列表
        let UfileListData = []; //上传附件图片列表参数
        for (let i = 0; i < UattachmentList.length; i++) {
          let fileName = UattachmentList[i].fileName;
          let subIndex = fileName.lastIndexOf(".");
          let ext = fileName.substring(subIndex + 1, fileName.length);
          let urls = "";
          if (ext == "xlsx" || ext == "xls") {
            urls = require("./icon_excel.jpg");
          } else if (ext == "doc" || ext == "docx") {
            urls = require("./icon_word.jpg");
          } else if (ext == "pdf") {
            urls = require("./icon_pdf.jpg");
          } else if (ext == "zip") {
            urls = require("./icon_zip.jpg");
          } else {
            urls = this.uploadImg.baseRoutingUrl + UattachmentList[i].fileUrl;
          }
          UfileList.push({
            name: UattachmentList[i].fileName,
            fileUrl: UattachmentList[i].fileUrl,
            url: urls,
            id: UattachmentList[i].id,
            fileType: UattachmentList[i].fileType,
            listIndex:parseInt(UattachmentList[i].fileType)-1
          });
          UfileListData.push({
            id: UattachmentList[i].id,
          });
        }
        this.fileList = UfileList;
        this.fileListData = UfileListData;
        if(this.voucherAttachmentAmount == 0){  //自动计算附件数
          this.$set(this.searchFormField, "attachedNum", UattachmentList.length); //附单据
        }
        this.$set(this.ButtonState, "saveBtn", false);
        this.$set(this.ButtonState, "addSaveBtn", false);
        this.dealWithFile();
        //加入生成组件

        if (this.SubjectsList.length != 0) {
          let chargeItmes = JSON.parse(JSON.stringify(this.chargeItme.items));
          for (let i = 0; i < chargeItmes.length; i++) {
            if (chargeItmes[i].subjectId != undefined) {
              CHECK(this.SubjectsMap);
              var obj = this.SubjectsMap[chargeItmes[i].subjectId];
              CHECK(obj);
              if(!obj) obj = this.SubjectsList.find(function (obj) {
                return obj.subjectId === chargeItmes[i].subjectId;
              })
              if(obj) // 某科目可能不存在, 或已经是非明细
                chargeItmes[i].subjectNameAll = obj.subjectNameAll;
            }
          }
          this.$set(this.chargeItme, "items", chargeItmes);
        }
        this.combinedNum();
      } else {
        this.editorData(this.addVoucherTemplate.voucherId);
      }
    },
    modifyTemplateFun(item) {
      if (item == undefined || item.attachmentList) {
        return false;
      }
      this.$set(this.templateList, "saveBtndisabled", false);
      this.isTemplate = true;
      let content = item;
      //获取科目列表
      this.SubjectsList = res.rows;
      //凭证数据
      let credentialsData = [];
      let credentialsDataStatus = [];
      let UdetailList = content.detailList;
      for (let i = 0; i < UdetailList.length; i++) {
        credentialsData.push({
          voucherSummary: UdetailList[i].voucherSummary, //摘要
          subjectNameAll: UdetailList[i].subjectNameAll, //会计科目名称
          jieAmount:
              UdetailList[i].jieAmount == null ? "" : UdetailList[i].jieAmount, //借方金额
          daiAmount:
              UdetailList[i].daiAmount == null ? "" : UdetailList[i].daiAmount, //贷方金额
          subjectId: UdetailList[i].subjectId, //会计科目Id
          subjectMoney: "",
          quantityNum:  UdetailList[i].quantityNum, //数量核算科目-数量
          quantityUnit: UdetailList[i].quantityUnit, //数量核算科目-单位
          contractionFundPlanId:UdetailList[i].contractionFundPlanId  //关联合同收款科目
        });
        credentialsDataStatus.push({
          voucherSummary: true, //摘要
          subjectNameAll: true, //会计科目
          jieAmount: true, //借方金额
          jieComputeAmount:true,  //借方金额计算弹窗
          daiAmount: true, //贷方金额
          daiComputeAmount:true,  //贷方金额计算弹窗
          assistState: false, //辅助核算
          assistType: "", //辅助核算-显示类型
          // isQuantity:newList[0].isQuantity=='Y'?true:false, //是否显示数量核算科目
          isQuantity: ((UdetailList[i].quantityNum == null || UdetailList[i].quantityNum == '') && (UdetailList[i].quantityUnit == null || UdetailList[i].quantityUnit == '')), //是否显示数量核算科目
        });
      }
      this.chargeItme.items = credentialsData;
      this.chargeItme.dataStatus = credentialsDataStatus;
      this.$set(this.templateList, "id", content.id);
    },
    initData() {
      //创建基础数据
      let credentialsData = [];
      let credentialsDataStatus = [];
      //辅助核算基础数据
      let assistAccountingNum = [];

      for (let i = 0; i <= 4; i++) {
        credentialsData.push({
          voucherSummary: "", //摘要
          subjectNameAll: "", //会计科目名称
          jieAmount: "", //借方金额
          daiAmount: "", //贷方金额
          subjectId: "", //会计科目Id
          subjectMoney: "", //会计科目余额
          quantityNum:'', //数量核算科目-数量
          quantityUnit:'', //数量核算科目-单位
          contractionFundPlanId:null, //关联合同收款科目
        });
        credentialsDataStatus.push({
          voucherSummary: true, //摘要
          subjectNameAll: true, //会计科目
          jieAmount: true, //借方金额
          jieComputeAmount:true,  //借方金额计算弹窗
          daiAmount: true, //贷方金额
          daiComputeAmount:true,  //贷方金额计算弹窗
          assistState: false, //辅助核算
          assistType: "", //辅助核算-显示类型
          isQuantity:false, //是否显示数量核算科目
          isContraction:false, //是否显示关联合同收款科目
        });
        assistAccountingNum.push([]);
      }

      this.chargeItme.items = credentialsData;
      this.chargeItme.dataStatus = credentialsDataStatus;
      this.assistAccounting.dataList = assistAccountingNum;

      //初始化图片数据
      this.fileList = [];
      this.fileListData = [];
      this.dealWithFile();
      //初始化表单数据
      this.$set(this.searchFormField, "voucherId", "");
      this.$set(this.searchFormField, "selectDate", "");
      this.$set(this.searchFormField, "attachedNum", 0);
      this.$set(this.searchFormField, "noteText", "");
      this.$set(this.searchFormField, "checkedBy", "");
      this.$set(this.searchFormField, "voucherWord", "1"); // 记
      //审批人
      this.$set(this.searchFormField, "barCodeList", '');
      //审批时间
      this.$set(this.searchFormField, "checkedTime", '');
      //初始化借贷总金额
      this.debitAmount = 0;
      this.lenderAmount = 0;
      this.capitalAmount = "";
      //是否是模板
      this.isTemplate = false;
      //是否是编辑
      this.isModifyVoucher = false;
      this.isCheckedBy = false;
      this.approvedcredentials = false;
      //初始化id
      this.uploadImg.uploadImgData.id = "";
      //辅助核算
      this.$set(this.assistAccounting, "accordingState", false);
      this.$set(this.assistAccounting, "numRows", "");
      this.$set(this.assistAccounting, "accordingType", "");
      this.$set(this.assistAccounting, "allDataList", []);
      //是否允许ctrl+s保存
      this.isCtrlSActive = true;
    },

    globalEvent() {
      // document.onkeydown = function (e) {
      //   let key = window.event.keyCode;
      //   //事件中keycode=13为回车事件
      //   // if (key == 13) {
      //   //_this.changeInput("keydown");
      //   console.log(key);
      //   this.thisEventKey = "enter";
      //   // }
      // };
      window.addEventListener("keydown", this.keyDownOther);
      window.addEventListener("click", this.clickOther);
      // document.onclick = function (e) {

      //   this.thisEventKey = "click";
      // };

      //点击页面其他区域隐藏备注弹窗
      document.addEventListener("click", (e) => {
        if (e.target.className != "el-textarea__inner") {
          this.noteStatue = false;
        }
      });
    },
    clickOther() {
      // console.log(this.visiblePop.addTemplateVisible)
      this.thisEventKey = "click";
      // console.log("click");
    },
    keyDownOther(event) {
      let routeType = "view";
      if (routeType == "view") {
        if (event.altKey == true && event.keyCode == 80) {
          //alt+p 打印
          if (!this.isTemplate && !this.isModifyType) {
            this.voucherPrint();
          }
        }
      }
      if (this.isCheckedBy == true) {
        // this.approvedTipsFun();
        return false;
      }
      //ctrl+s保存触发
      if (event.ctrlKey == true && event.keyCode == 83) {
        if (this.isCtrlSActive == true) {
          // if (this.savaBtnText == "新增" && this.voucherType == "") {
          // }else{
          this.saveVoucher("save", 'ctrls');
          // }
        }
        // 或者 return false;
        event.preventDefault();
        return false;
      } else if (event.keyCode == 120) {
        //F9保存触发
        this.saveVoucher("addSave");
        // 或者 return false;
        event.preventDefault();
        return false;

      } else if (event.altKey == true && event.keyCode == 78) {
        //alt + n新增
        this.saveVoucher("add");
      } else if (event.altKey == true && event.keyCode == 80) {
        if (this.printerType == false) {
          this.voucherPrint();
        }
        event.preventDefault();
        return false;
      } else if (event.keyCode == 39) {
        //键盘--右键
        this.keyFunStatus('right')
        event.preventDefault();
        return false;
      } else if (event.keyCode == 37) {
        //键盘--左键
        this.keyFunStatus('left')
        event.preventDefault();
        return false;
      } else if (event.keyCode == 40) {
        //键盘-下键
        this.keyFunStatus('bottom')
        event.preventDefault();
        return false;
      } else if (event.keyCode == 38) {
        //键盘-上键
        this.keyFunStatus('top')
        event.preventDefault();
        return false;
      }

      else if (event.shiftKey && event.altKey && String.fromCharCode(event.keyCode).toLowerCase() == 'v')
      {
        this.parseClipboard();
        return false;
      }

      this.thisEventKey = "enter";
    },
    //上下左右键盘按钮控制凭证切换
    keyFunStatus(type) {
      let currentLine = this.vocherListSelect.currentLine; //当前选中行
      let currentField = this.vocherListSelect.currentField; //当前选中列
      if(currentField == ''){
        return false;
      }
      let voucherList = this.chargeItme.dataStatus;
      const numFildArr = ['voucherSummary','subjectNameAll','jieAmount','daiAmount']
      const numField = {
        voucherSummary: {ids: 0, type:'input'},
        subjectNameAll: { ids: 1, type: 'select' },
        jieAmount: {ids: 2, type:'input'},
        daiAmount: { ids: 3, type:'input'}
      }
      //右键方法
      if (type == 'right') {
        //获取下一步选中列
        let nextIndex = numField[currentField].ids + 1;
        //当前行动作
        if (nextIndex <= 3) {
          this.changeText(numFildArr[nextIndex], currentLine, numField[numFildArr[nextIndex]].type)
        } else if (currentLine < voucherList.length-1) {
          //需要换行 行动作
          this.changeText(numFildArr[0], currentLine+1, numField.voucherSummary.type)
        }
      }
      //左键方法
      if (type == 'left') {
        //获取下一步选中列
        let nextIndex = numField[currentField].ids -1;
        //当前行动作
        if (nextIndex >= 0) {
          this.changeText(numFildArr[nextIndex], currentLine, numField[numFildArr[nextIndex]].type)
        } else if (currentLine > 0) {
          this.changeText(numFildArr[3], currentLine-1, numField.daiAmount.type)
        }
      }
      //下键方法
      if (type == 'bottom') {
        let nextIndex = currentLine + 1;
        if (currentLine < voucherList.length-1) {
          this.changeText(currentField, nextIndex, numField[currentField].type)
        }
      }
      //上键方法
      if (type == 'top') {
        let nextIndex = currentLine - 1;
        if (currentLine > 0) {
          this.changeText(currentField, nextIndex, numField[currentField].type)
        }
      }
    },
    getNowTime() {
      return getLoginBook().then((res) => {
        if (res.code == 200) {
          let currentDays = res.data.currentDay;
          let voucherAttachmentAmount = res.data.voucherAttachmentAmount;
          this.voucherAttachmentAmount = voucherAttachmentAmount == null?0:voucherAttachmentAmount;
          let dealDays = this.getLastDay(currentDays + "-01");
          let lastDays =
              dealDays.getFullYear() +
              "-" +
              (dealDays.getMonth() + 1).toString().padStart(2, "0") +
              "-" +
              dealDays.getDate().toString().padStart(2, "0");
          this.$set(this.searchFormField, "selectDate", lastDays);
          this.accountant = res.data.accountant;
        }
      });
    },
    initAxios() {
      //获取摘要接口
      summaryListData().then((res) => {
        // console.log(res);
        if (res.code == 200) {
          this.AbstractList = res.rows;
        }
      });
      //获取会计科目列表数据
      subjectData({status: 'N'}).then((res) => {
        if (res.code == 200) {
          this.SubjectsList = res.rows;
          this.SubjectsMap = array_toMap(this.SubjectsList, (x) => x.subjectId);
          //加入生成组件
          if (this.modifyAddVoucher != undefined) {
            if (this.addVoucherTemplate.voucherId == null) {
              let chargeItme = JSON.parse(
                  JSON.stringify(this.chargeItme.items)
              );
              for (let i = 0; i < chargeItme.length; i++) {
                if (chargeItme[i].subjectId != undefined) {
                  CHECK(this.SubjectsMap);
                  var obj = this.SubjectsMap[chargeItme[i].subjectId];
                  CHECK(obj);
                  if(!obj) obj = res.rows.find(function (obj) {
                    return obj.subjectId === chargeItme[i].subjectId;
                  });
                  if(obj) // 某科目可能不存在, 或已经是非明细
                    chargeItme[i].subjectNameAll = obj.subjectNameAll;
                }
              }
              this.$set(this.chargeItme, "items", chargeItme);
            }
          }
        }
      });

      //获取制单人信息
      getUserProfile().then((res) => {
        if (res.code == 200) {
          let user = res.data.nickName;
          this.$set(this.searchFormField, "userName", user);
        }
      });

      //获取辅助核算-单位
      let AssistNum1 = {
        assist: 1,
      };
      assistListByAssist(AssistNum1).then((res) => {
        if (res.code == 200) {
          this.$set(this.assistAccounting, "unitSelectList", res.rows);
        }
      });
      //获取辅助核算-个人
      let AssistNum2 = {
        assist: 2,
      };
      assistListByAssist(AssistNum2).then((res) => {
        if (res.code == 200) {
          this.$set(this.assistAccounting, "personalSelectList", res.rows);
        }
      });
      //获取辅助核算-部门
      let AssistNum3 = {
        assist: 3,
      };
      assistListByAssist(AssistNum3).then((res) => {
        if (res.code == 200) {
          this.$set(this.assistAccounting, "numSelectList", res.rows);
        }
      });
      //获取辅助核算-项目
      let AssistNum4 = {
        assist: 4,
      };
      assistListByAssist(AssistNum4).then((res) => {
        if (res.code == 200) {
          this.$set(this.assistAccounting, "projectSelectList", res.rows);
        }
      });
      //获取上传附件附件类型

      this.getDicts("voucher_attach").then((response) => {
        this.uploadImg.fileTypeOptions = response.data;
        if (response.data.length > 0) {
          this.uploadImg.uploadImgData.fileType = response.data[0].dictValue;
        }
      });

      // 获取附件高拍仪列表
      this.getDicts("high_picture").then((response) => {
        this.highShotMeter.selectList = response.data;
        if (response.data.length != 0) {
          this.highShotMeter.currentMeter = response.data[0].dictLabel;
        }
      });
    },
    initAddAxios() {
      //获取获取最大凭证号
      voucherGetCurrentNum().then((res) => {
        if (res.code == 200) {
          this.$set(this.searchFormField, "voucherId", res.data);
        }
      });
    },
    changeText(name, index, type) {
      if ("view" == "view") {
        return false;
      }
      this.$set(this.vocherListSelect, 'currentLine', index); //当前选择凭证行
      this.$set(this.vocherListSelect, 'currentField', name); //当前选择凭证列
      let lineType = this.assistAccounting.numRows;
      let selectType = this.assistAccounting.accordingType;
      if (selectType != "") {
        let calculateDate = this.assistAccounting.dataList[lineType];
        if (
            calculateDate.length == 1 &&
            calculateDate[0].assistTypeId1 == "" &&
            calculateDate[0].assistTypeId2 == "" &&
            calculateDate[0].assistTypeId3 == "" &&
            calculateDate[0].assistTypeId4 == "" &&
            calculateDate[0].jieAmount == "" &&
            calculateDate[0].daiAmount == ""
        ) {
        } else {
          let selectArr = selectType.split(",");
          for (var i = 0; i < calculateDate.length; i++) {
            if (
                calculateDate[i].daiAmount == "" &&
                calculateDate[i].jieAmount == ""
            ) {
              this.assistAccounting.accordingState = true;
              this.$message({
                message: "辅助核算信息不完整，请补充完整!",
                type: "warning",
              });
              return false;
            }
            for (let m = 0; m < selectArr.length; m++) {
              let numColumn = "assistTypeId" + selectArr[m];
              if (calculateDate[i][numColumn] == "") {
                this.assistAccounting.accordingState = true;
                this.$message({
                  message: "辅助核算信息不完整，请补充完整!",
                  type: "warning",
                });
                return false;
              }
            }
          }
        }
      }

      //是否显示隐藏项目
      let assistStateStr = this.chargeItme.dataStatus[index].assistState;
      this.$set(this.assistAccounting, "accordingState", assistStateStr);

      //会计科目是辅助核算
      if (assistStateStr) {
        let assistStateType = this.chargeItme.dataStatus[index].assistType;
        this.$set(this.assistAccounting, "accordingType", assistStateType);
      } else {
        this.$set(this.assistAccounting, "accordingType", "");
      }
      //当前行数
      this.$set(this.assistAccounting, "numRows", index);
      if (this.isCheckedBy == true) {
        this.approvedTipsFun();
        return false;
      }

      if (assistStateStr) {
        if (name == "jieAmount" || name == "daiAmount") {
          return false;
        }
      }

      //name 当前名称  index 行数  type 类型
      this.$set(this.chargeItme.dataStatus[index], name, false);
      if (type == "select") {
        this.$nextTick(() => {
          this.$refs[name + index][0].toggleMenu();
        });
      } else if (type == "input") {
        this.$nextTick(() => {
          this.$refs[name + index][0].focus();
          if (name == "jieAmount" || name == "daiAmount") {
            this.$refs[name + index][0].select();
          }
        });
      }
    },
    blurInput(name, index, line) {
      //name 当前名称  index 行数 line 列数
      let _this = this;
      setTimeout(() => {
        _this.$set(_this.chargeItme.dataStatus[index], name, true);
        if (name == "subjectNameAll") {
          if (_this.chargeItme.items[index].subjectId != "") {
            /*#if 0
            _this.SubjectsList.forEach((v, i) => {
              if (v.subjectId == _this.chargeItme.items[index].subjectId) {
                _this.$set(
                  _this.chargeItme.items[index],
                  "subjectNameAll",
                  v.subjectNameAll
                );
              }
            });
            #endif*/
            CHECK(_this.SubjectsMap);
            let v = _this.SubjectsMap[_this.chargeItme.items[index].subjectId];
            CHECK(v);
            if(v)
            {
              _this.$set(
                  _this.chargeItme.items[index],
                  "subjectNameAll",
                  v.subjectNameAll
              );
            }

          }
        }
        this.combinedNum();
      }, 200);
    },
    changeInput(event, name, index, line, item) {
      if (item != undefined) {
        let selectValue = item.subjectId;
        //通过科目id获取余额
        if (selectValue) {
          getBySubjectId({ subjectId: selectValue }).then((res) => {
            if (res.code == 200) {
              let bybalance = res.data.qmye;
              let endBalance = bybalance == null ? 0 : bybalance;

              this.$set(
                  this.chargeItme.items[index],
                  "subjectMoney",
                  endBalance
              );
              this.$set(this.chargeItme.items[index], "balanceDirection", res.data.balanceDirection);
            }
          });
        }

        CHECK(this.SubjectsMap);
        let newList = this.SubjectsMap[selectValue] ? [this.SubjectsMap[selectValue]] : [];
        CHECK(newList);
        if (!newList.length) newList = this.SubjectsList.filter(
            (val) => selectValue == val.subjectId
        );
        if (newList.length != 0) {
          //if (newList[0].isAssist == "Y") {
          //是否辅助核算
          if (newList[0].assist != null && newList[0].assist != "") {
            //当前行数
            this.$set(this.assistAccounting, "numRows", index);
            //常用辅助核算
            this.$set(this.chargeItme.dataStatus[index], "assistState", true);
            this.$set(this.assistAccounting, "accordingState", true);
            this.$set(this.chargeItme.items[index], "daiAmount", "");
            this.$set(this.chargeItme.items[index], "jieAmount", "");

            let assistList = [];
            //设置辅助核算类型
            this.$set(
                this.chargeItme.dataStatus[index],
                "assistType",
                newList[0].assist
            );
            this.$set(
                this.assistAccounting,
                "accordingType",
                newList[0].assist
            );
            assistList.push({
              assist: this.chargeItme.dataStatus[index].assistType,
              assistTypeId1: "",
              assistTypeId2: "",
              assistTypeId3: "",
              assistTypeId4: "",
              daiAmount: "",
              jieAmount: "",
            });
            this.assistAccounting.dataList[index] = assistList;
            if (name == "subjectNameAll") {
              let assistList = newList[0].assist.split(",");
              this.$nextTick(() => {
                if (
                    this.$refs["assistTypeId" + assistList[0] + "0"] != undefined
                ) {
                  this.$refs[
                  "assistTypeId" + assistList[0] + "0"
                      ][0].toggleMenu();
                }
              });
              return false;
            }
          } else {
            this.assistAccounting.dataList[index] = [];

            //不是常用辅助核算
            this.$set(this.chargeItme.dataStatus[index], "assistState", false);
            this.$set(this.assistAccounting, "accordingState", false);
            this.$set(this.chargeItme.dataStatus[index], "assistType", "");
          }
          //是否是数量核算科目
          if(newList[0].isQuantity && newList[0].isQuantity == 'Y'){
            //显示数量核算科目
            this.$set(
                this.chargeItme.dataStatus[index],
                "isQuantity",
                true
            );
          }else{
            //隐藏数量核算科目
            this.$set(
                this.chargeItme.dataStatus[index],
                "isQuantity",
                false
            );
            //数量
            this.$set(
                this.chargeItme.items[index],
                "quantityNum",
                ''
            );
            //单位
            this.$set(
                this.chargeItme.items[index],
                "quantityUnit",
                ''
            );
          }
          //是否是关联合同收款科目
          if(newList[0].isContraction && newList[0].isContraction =='Y'){
            this.contractionFun(event, name, index, line, item)
            this.$set(
                this.chargeItme.dataStatus[index],
                "isContraction",
                true
            );
          }else{
            this.$set(
                this.chargeItme.dataStatus[index],
                "isContraction",
                false
            );
            this.$set(
                this.chargeItme.items[index],
                "contractionFundPlanId",
                null
            );
          }

          if (name == "subjectNameAll") {
            this.$set(
                this.chargeItme.items[index],
                "subjectNameAll",
                newList[0].subjectNameAll
            );
          }
        }
      }
      let timestamp = Date.parse(new Date());

      if (event == "change") {
        this.vouterTime = timestamp;
        this.$set(this.ButtonState, "saveBtn", false);
        this.$set(this.ButtonState, "addSaveBtn", false);
        this.savaBtnText = "保存并新增";
      } else if (event == "keydown") {
        if (name == "jieAmount") {
          this.combinedNum();
        } else if (timestamp - this.vouterTime == 0) {
          if (name == "voucherSummary") {
            let oItems = this.chargeItme.items;
            let debitAmount = 0; //借方金额
            let lenderAmount = 0; //贷方金额
            for (let i = 0; i < oItems.length; i++) {
              debitAmount += Number(oItems[i].jieAmount);
              if (index == i) {
                continue;
              }
              lenderAmount += Number(oItems[i].daiAmount);
            }

            if (debitAmount < lenderAmount) {
              //显示下方借方金额
              let amountNum = lenderAmount - debitAmount;

              if (this.chargeItme.items[index].jieAmount == "") {
                this.$set(this.chargeItme.items[index], "jieAmount", amountNum);
                this.$set(this.chargeItme.items[index], "daiAmount", "");
              }
            } else if (debitAmount > lenderAmount) {
              //显示下方贷方金额
              let amountNum = debitAmount - lenderAmount;
              if (this.chargeItme.items[index].daiAmount == "") {
                this.$set(this.chargeItme.items[index], "daiAmount", amountNum);
                this.$set(this.chargeItme.items[index], "jieAmount", "");
              }
            }
          }
          this.combinedNum();
          return false;
        }
      }
      if (this.AnewData == 0 && this.BnewData == 0) {
        this.changeInputFun(event, name, index, line);
      } else if (
          (this.BnewData - this.AnewData <= 400 &&
              this.BnewData - this.AnewData >= 160000000000) ||
          (this.AnewData - this.BnewData <= 400 &&
              this.AnewData - this.BnewData >= 160000000000)
      ) {
      } else {
        //   console.log("33333");
        this.changeInputFun(event, name, index, line);
      }
    },
    changeInputFun(event, name, index, line) {
      let timestamp = new Date().getTime();
      // console.log(event);
      // console.log(this.AnewData - this.BnewData);
      if (event == "keydown") {
        this.AnewData = new Date().getTime();
        if (this.AnewData - this.BnewData <= 400 && this.BnewData != 0) {
          return false;
        }
        this.enterInput();
      } else {
        this.BnewData = new Date().getTime();
        if (this.BnewData - this.AnewData <= 400 && this.AnewData != 0) {
          return false;
        }
        // console.log('B:'+this.BnewData )
        // name 当前名称  index 行数  //line 当前列数  type 类型
        let statusItem = [
          "voucherSummary",
          "subjectNameAll",
          "jieAmount",
          "daiAmount",
        ];
        this.$set(this.chargeItme.dataStatus[index], name, true);
        if (index == this.chargeItme.items.length - 1) {
          this.chargeItme.items.push({
            voucherSummary: "", //摘要
            subjectNameAll: "", //会计科目
            jieAmount: "", //借方金额
            daiAmount: "", //贷方金额
            subjectId: "", //会计科目Id
            subjectMoney: "", //会计科目余额
            quantityNum:'', //数量核算科目-数量
            quantityUnit:'', //数量核算科目-单位
            contractionFundPlanId:null, //关联合同收款科目
          });
          this.chargeItme.dataStatus.push({
            voucherSummary: true, //摘要
            subjectNameAll: true, //会计科目
            jieAmount: true, //借方金额
            jieComputeAmount:true,  //借方金额计算弹窗
            daiAmount: true, //贷方金额
            daiComputeAmount:true,  //贷方金额计算弹窗
            assistState: false, //辅助核算
            assistType: "", //辅助核算-显示类型
            isQuantity:false, //是否显示数量核算科目
            isContraction:false, //是否显示关联合同收款科目
          });
        }
        //选择当前行,自动跳到下一行
        if (name == "voucherSummary" || name == "subjectNameAll") {
          this.$nextTick(() => {
            if (name == "voucherSummary") {
              this.$refs[statusItem[line + 1] + index][0].toggleMenu();
            } else {
              this.$refs[statusItem[line + 1] + index][0].focus();
            }
          });
          this.$set(
              this.chargeItme.dataStatus[index],
              statusItem[line + 1],
              false
          );
        }

        /*
        if (name == "jieAmount") {
          this.$set(this.chargeItme.items[index], "daiAmount", " ");
          let oItems = this.chargeItme.items;
          //不是最后一行
          if (index != oItems.length - 1) {
            //借方金额=空
            if (oItems[index].jieAmount == "") {
              this.$set(
                this.chargeItme.dataStatus[index],
                statusItem[line + 1],
                false
              );
              this.$nextTick(() => {
                this.$refs[statusItem[line + 1] + index][0].focus();
              });
            } else {
              let _this = this;

              setTimeout(() => {
                console.log(_this.thisEventKey);
                if (_this.thisEventKey == "enter") {
                  _this.$set(
                    _this.chargeItme.dataStatus[index + 1],
                    "voucherSummary",
                    false
                  );
                  _this.$nextTick(() => {
                    _this.$refs[statusItem[0] + (index + 1)][0].toggleMenu();
                  });
                  _this.jieAmountCalculate(name, index, line);
                  _this.combinedNum();
                }
              }, 150);
            }
          }
        } else if (name == "daiAmount") {
          this.$set(this.chargeItme.items[index], "jieAmount", " ");
          let oItems = this.chargeItme.items;
          //不是最后一行
          if (index != oItems.length - 1) {
            if (
              oItems[index].jieAmount == "" &&
              oItems[index].daiAmount == ""
            ) {
            } else {
              let _this = this;
              setTimeout(() => {
                console.log(_this.thisEventKey);
                if (_this.thisEventKey == "enter") {
                  _this.$set(
                    _this.chargeItme.dataStatus[index + 1],
                    "voucherSummary",
                    false
                  );
                  _this.$nextTick(() => {
                    _this.$refs[statusItem[0] + (index + 1)][0].toggleMenu();
                  });
                  _this.daiAmountCalculate(name, index, line);
                  _this.combinedNum();
                }
              }, 150);
            }
          }
        }

        */
      }
      this.combinedNum();
    },
    visibleInput(callback, name, index, line) {
      // if (callback == false) {
      //   let statusItem = [
      //     "voucherSummary",
      //     "subjectNameAll",
      //     "jieAmount",
      //     "daiAmount",
      //   ];
      //   if (name == "voucherSummary") {
      //     this.$set(this.chargeItme.dataStatus[index], statusItem[line], true);
      //     this.$set(
      //       this.chargeItme.dataStatus[index],
      //       statusItem[line + 1],
      //       false
      //     );
      //     this.$refs[statusItem[line + 1] + index][0].toggleMenu();
      //   } else if (name == "subjectNameAll") {
      //     this.$set(this.chargeItme.dataStatus[index], statusItem[line], true);
      //     this.$set(
      //       this.chargeItme.dataStatus[index],
      //       statusItem[line + 1],
      //       false
      //     );
      //     this.$nextTick(() => {
      //       this.$refs["jieAmount" + index][0].focus();
      //     });
      //   }
      // }
    },
    enterInput() {
      let dataStatus = this.chargeItme.dataStatus;
      for (let i = 0; i <= dataStatus.length - 1; i++) {
        if (dataStatus[i].voucherSummary == false) {
          this.enterInputDeal("voucherSummary", i, 0);
          break;
        } else if (dataStatus[i].subjectNameAll == false) {
          this.enterInputDeal("subjectNameAll", i, 1);
          break;
        } else if (dataStatus[i].jieAmount == false) {
          this.enterInputDeal("jieAmount", i, 2);
          break;
        } else if (dataStatus[i].daiAmount == false) {
          this.enterInputDeal("daiAmount", i, 3);
          break;
        }
      }
      this.combinedNum();
    },
    enterInputDeal(name, index, line) {
      //当前名称  行数   当前列数
      let statusItem = [
        "voucherSummary",
        "subjectNameAll",
        "jieAmount",
        "daiAmount",
      ];
      if (name == "voucherSummary") {
        this.$set(this.chargeItme.dataStatus[index], name, true);
        this.$set(
            this.chargeItme.dataStatus[index],
            statusItem[line + 1],
            false
        );
        this.$nextTick(() => {
          this.$refs[statusItem[line + 1] + index][0].toggleMenu();
        });
      } else if (name == "subjectNameAll") {
        this.$set(this.chargeItme.dataStatus[index], name, true);
        this.$set(
            this.chargeItme.dataStatus[index],
            statusItem[line + 1],
            false
        );

        this.$nextTick(() => {
          this.$refs[statusItem[line + 1] + index][0].focus();
          this.$refs[statusItem[line + 1] + index][0].select();
        });
      } else if (name == "jieAmount") {
        this.$set(this.chargeItme.dataStatus[index], name, true);
        let oItems = this.chargeItme.items;
        //不是最后一行
        if (index != (oItems.length - 1)) {
          if (oItems[index].jieAmount == "") {
            this.$set(
                this.chargeItme.dataStatus[index],
                statusItem[line + 1],
                false
            );
            this.$nextTick(() => {
              this.$refs[statusItem[line + 1] + index][0].focus();
              this.$refs[statusItem[line + 1] + index][0].select();
            });
          } else {
            this.$set(
                this.chargeItme.dataStatus[index + 1],
                "voucherSummary",
                false
            );

            this.$set(
                this.chargeItme.items[index + 1],
                "voucherSummary",
                this.chargeItme.items[index].voucherSummary
            );

            this.$nextTick(() => {
              this.$refs[statusItem[0] + (index + 1)][0].focus();
              this.$nextTick(() => {
                try {
                  this.$refs[statusItem[0] + (index + 1)][0].$el.querySelector("input").select();
                } catch(e) { console.error(e) }
              });
            });
            let _this = this;

            setTimeout(() => {
              _this.jieAmountCalculate(name, index, line);
            }, 150);
          }
        } else {
          this.$set(
              this.chargeItme.dataStatus[index],
              statusItem[line + 1],
              false
          );

          this.$nextTick(() => {
            this.$refs[statusItem[line + 1] + index][0].focus();
            this.$refs[statusItem[line + 1] + index][0].select();
          });
        }
      } else if (name == "daiAmount") {
        let oItems = this.chargeItme.items;
        //不是最后一行
        if (index != (oItems.length - 1)) {
          if (oItems[index].jieAmount == "" && oItems[index].daiAmount == "") {
          } else {
            this.$set(this.chargeItme.dataStatus[index], name, true);
            this.$set(
                this.chargeItme.dataStatus[index + 1],
                "voucherSummary",
                false
            );
            this.$set(
                this.chargeItme.items[index + 1],
                "voucherSummary",
                this.chargeItme.items[index].voucherSummary
            );
            this.$nextTick(() => {
              this.$refs[statusItem[0] + (index + 1)][0].focus();
              this.$nextTick(() => {
                try {
                  this.$refs[statusItem[0] + (index + 1)][0].$el.querySelector("input").select();
                } catch(e) { console.error(e) }
              });
            });
            let _this = this;
            setTimeout(() => {
              _this.daiAmountCalculate(name, index, line);
            }, 150);
          }
        }
      }
      // if (name == "jieAmount") {
      //   this.$set(this.chargeItme.items[index], "daiAmount", " ");
      // } else if (name == "daiAmount") {
      //   this.$set(this.chargeItme.items[index], "jieAmount", " ");
      // }
      this.combinedNum();
    },
    //借－ 计算换行金额
    jieAmountCalculate(name, index, line) {
      let oItems = this.chargeItme.items;
      //新增计算方法
      let debitAmount = 0; //借方金额
      let lenderAmount = 0; //贷方金额
      for (let i = 0; i < oItems.length; i++) {
        debitAmount += Number(oItems[i].jieAmount);
        if (index + 1 == i) {
          continue;
        }
        lenderAmount += Number(oItems[i].daiAmount);
      }

      if (debitAmount < lenderAmount) {
        //显示下方借方金额
        let amountNum =
            (Number(lenderAmount - debitAmount) * 100).toFixed(0) / 100;
        if (this.chargeItme.items[index + 1].jieAmount == "") {
          this.$set(this.chargeItme.items[index + 1], "jieAmount", amountNum);
          this.$set(this.chargeItme.items[index + 1], "daiAmount", "");
        }
      } else if (debitAmount > lenderAmount) {
        //显示下方贷方金额
        let amountNum =
            (Number(debitAmount - lenderAmount) * 100).toFixed(0) / 100;
        if (this.chargeItme.items[index + 1].daiAmount == "") {
          this.$set(this.chargeItme.items[index + 1], "daiAmount", amountNum);
          this.$set(this.chargeItme.items[index + 1], "jieAmount", "");
        }
      }
    },
    //贷－计算换行金额
    daiAmountCalculate(name, index, line) {
      let oItems = this.chargeItme.items;
      //新增计算方法
      let debitAmount = 0; //借方金额
      let lenderAmount = 0; //贷方金额
      for (let i = 0; i < oItems.length; i++) {
        lenderAmount += Number(oItems[i].daiAmount);
        if (index + 1 == i) {
          continue;
        }
        debitAmount += Number(oItems[i].jieAmount);
      }

      if (debitAmount < lenderAmount) {
        //显示下方借方金额
        let amountNum =
            (Number(lenderAmount - debitAmount) * 100).toFixed(0) / 100;

        if (this.chargeItme.items[index + 1].jieAmount == "") {
          this.$set(this.chargeItme.items[index + 1], "jieAmount", amountNum);
          this.$set(this.chargeItme.items[index + 1], "daiAmount", "");
        }
      } else if (debitAmount > lenderAmount) {
        //显示下方贷方金额
        let amountNum =
            (Number(debitAmount - lenderAmount) * 100).toFixed(0) / 100;
        if (this.chargeItme.items[index + 1].daiAmount == "") {
          this.$set(this.chargeItme.items[index + 1], "daiAmount", amountNum);
          this.$set(this.chargeItme.items[index + 1], "jieAmount", "");
        }
      }
    },
    combinedNum() {
      setTimeout(() => {
        let oItems = this.chargeItme.items;
        let debitAmount = 0; //借方金额
        let lenderAmount = 0; //贷方金额
        oItems.forEach((value, index) => {
          if (value.jieAmount != "=" && value.daiAmount != "=") {
            debitAmount += Number(value.jieAmount);
            lenderAmount += Number(value.daiAmount);
          }
        });
        this.debitAmount = debitAmount;
        this.lenderAmount = lenderAmount;

        let convertNum = 0;
        let disposeNum = "";
        if (debitAmount < 0) {
          convertNum = -debitAmount;
          disposeNum = "负";
        } else {
          convertNum = debitAmount;
        }

        this.capitalAmount = disposeNum + this.convertCurrency(convertNum);
        // let routeType = "view";
        // if (routeType == "modify") {
        //   var listData = JSON.stringify(this.chargeItme);
        //   var addMinute = new Date(new Date().getTime() + 10 * 60 * 1000);
        //   Cookies.set("voucherList", listData, { expires: addMinute });
        // }
      }, 600);
    },
    convertCurrency(money) {
      //汉字的数字
      var cnNums = new Array(
          "零",
          "壹",
          "贰",
          "叁",
          "肆",
          "伍",
          "陆",
          "柒",
          "捌",
          "玖"
      );
      //基本单位
      var cnIntRadice = new Array("", "拾", "佰", "仟");
      //对应整数部分扩展单位
      var cnIntUnits = new Array("", "万", "亿", "兆");
      //对应小数部分单位
      var cnDecUnits = new Array("角", "分", "毫", "厘");
      //整数金额时后面跟的字符
      var cnInteger = "整";
      //整型完以后的单位
      var cnIntLast = "元";
      //最大处理的数字
      var maxNum = 999999999999999.9999;
      //金额整数部分
      var integerNum;
      //金额小数部分
      var decimalNum;
      //输出的中文金额字符串
      var chineseStr = "";
      //分离金额后用的数组，预定义
      var parts;
      if (money == "") {
        return "";
      }
      money = parseFloat(money);
      if (money >= maxNum) {
        //超出最大处理数字
        return "";
      }
      if (money == 0) {
        chineseStr = cnNums[0] + cnIntLast + cnInteger;
        return chineseStr;
      }
      //转换为字符串
      money = money.toString();
      if (money.indexOf(".") == -1) {
        integerNum = money;
        decimalNum = "";
      } else {
        parts = money.split(".");
        integerNum = parts[0];
        decimalNum = parts[1].substr(0, 4);
      }
      //获取整型部分转换
      if (parseInt(integerNum, 10) > 0) {
        var zeroCount = 0;
        var IntLen = integerNum.length;
        for (var i = 0; i < IntLen; i++) {
          var n = integerNum.substr(i, 1);
          var p = IntLen - i - 1;
          var q = p / 4;
          var m = p % 4;
          if (n == "0") {
            zeroCount++;
          } else {
            if (zeroCount > 0) {
              chineseStr += cnNums[0];
            }
            //归零
            zeroCount = 0;
            chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
          }
          if (m == 0 && zeroCount < 4) {
            chineseStr += cnIntUnits[q];
          }
        }
        chineseStr += cnIntLast;
      }
      //小数部分
      if (decimalNum != "") {
        var decLen = decimalNum.length;
        for (var i = 0; i < decLen; i++) {
          var n = decimalNum.substr(i, 1);
          if (n != "0") {
            chineseStr += cnNums[Number(n)] + cnDecUnits[i];
          }
        }
      }
      if (chineseStr == "") {
        chineseStr += cnNums[0] + cnIntLast + cnInteger;
      } else if (decimalNum == "") {
        chineseStr += cnInteger;
      }
      return chineseStr;
    },
    saveVoucher(type, method) {
      //type判断是保存或保存新增
      let vocherId = this.uploadImg.uploadImgData.id;
      //method获取什么方式进行保存
      if (method == 'ctrls') {
        //ctrl+s保存
        this.isCtrlSActive= false;
      }
      this.isOnlySave = false;
      if (type == "add") {
        //新增
        this.initData();
        this.initAddAxios();
        //初始化当前日期
        this.getNowTime().then(() => {
          this.$set(this.searchFormField, 'accountedBy', this.accountant);
        });
      } else {
        //保存并新增 保存
        //不是修改模版  && this.searchFormField.voucherId ==''
        if (this.savaBtnText == "新增" && this.voucherType == "" && type=='addSave') {
          this.initData();
          this.initAddAxios();
          //初始化当前日期
          this.getNowTime();
          this.savaBtnText = "保存并新增";
          this.$set(this.ButtonState, "addSaveBtn", true);
          return false;
        }
        let vData = [];
        let chargeItem = this.chargeItme.items;
        for (let i = 0; i < chargeItem.length; i++) {
          if (
              chargeItem[i].daiAmount == "" &&
              chargeItem[i].jieAmount == "" &&
              chargeItem[i].subjectId == "" &&
              chargeItem[i].voucherSummary == ""
          ) {
            continue;
          }

          if (chargeItem[i].voucherSummary == "") {
            this.$message.error({
              message: "第" + (i + 1) + "行，请输入摘要！",
            });
            this.isCtrlSActive = true;
            return false;
          } else if (chargeItem[i].subjectNameAll == "") {
            this.$message.error({
              message: "第" + (i + 1) + "行，请输入会计科目！",
            });
            this.isCtrlSActive = true;
            return false;
          } else if (
              chargeItem[i].daiAmount == "" &&
              chargeItem[i].jieAmount == ""
          ) {
            this.$message.error({
              message: "第" + (i + 1) + "行，请输入金额！",
            });
            this.isCtrlSActive = true;
            return false;
          }

          chargeItem[i].assistList = this.assistAccounting.dataList[i];
          vData.push(chargeItem[i]);
        }
        console.log(vData.length)
        if (vData.length == 0) {
          this.$message.error({
            message: "第1行不能为空！",
          });
          this.isCtrlSActive = true;
          return false;
        }

        // if (this.debitAmount != this.lenderAmount) {
        //   this.$message.error({
        //     message: "借贷不平衡！",
        //   });
        //   return false;
        // }

        let lineType = this.assistAccounting.numRows;
        let selectType = this.assistAccounting.accordingType;
        if (selectType != "") {
          let calculateDate = this.assistAccounting.dataList[lineType];
          let selectArr = selectType.split(",");
          for (var i = 0; i < calculateDate.length; i++) {
            if (
                calculateDate[i].daiAmount == "" &&
                calculateDate[i].jieAmount == ""
            ) {
              this.$message({
                message: "辅助核算信息不完整，请补充完整!",
                type: "warning",
              });
              this.isCtrlSActive = true;
              return false;
            }
            for (let m = 0; m < selectArr.length; m++) {
              let numColumn = "assistTypeId" + selectArr[m];
              if (calculateDate[i][numColumn] == "") {
                this.$message({
                  message: "辅助核算信息不完整，请补充完整!",
                  type: "warning",
                });
                this.isCtrlSActive = true;
                return false;
              }
            }
          }
        }
        let transmissionData = {};
        if (this.redDashedItems != undefined) { //红冲保存
          transmissionData = {
            detailList: vData,
            remarks: this.searchFormField.noteText,
            bookDate: this.searchFormField.selectDate,
            attachmentList: this.fileListData,
            attachmentAccount:this.searchFormField.attachedNum,
            isHongChong: true,
            voucherWord: this.searchFormField.voucherWord,
          };
        } else if (vocherId!='' && vocherId != null && vocherId != undefined) { //编辑保存
          if(this.voucherType === "21"){
            transmissionData = {
              detailList: vData,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              voucherType: this.voucherType.toString(),
              externalId:this.$route.query.externalId,
              attachmentList: this.fileListData,
              attachmentAccount:this.searchFormField.attachedNum,
              voucherWord: this.searchFormField.voucherWord,
              id: vocherId,
            };
          }else{
            transmissionData = {
              detailList: vData,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              attachmentList: this.fileListData,
              id: vocherId,
              attachmentAccount:this.searchFormField.attachedNum,
              voucherWord: this.searchFormField.voucherWord,
            };
          }
        } else if (this.voucherType != "") { //凭证弹窗组件
          if (this.addVoucherTemplate.voucherId == null) {
            transmissionData = {
              detailList: vData,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              attachmentList: this.fileListData,
              voucherType: this.voucherType.toString(),
              externalId: this.addVoucherTemplate.id,
              attachmentAccount:this.searchFormField.attachedNum,
              externalIds: this.addVoucherTemplate.ids,
              voucherWord: this.searchFormField.voucherWord,
            };
          } else {
            transmissionData = {
              detailList: vData,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              attachmentList: this.fileListData,
              id: this.addVoucherTemplate.voucherId,
              voucherType: this.voucherType.toString(),
              attachmentAccount:this.searchFormField.attachedNum,
              externalId: this.addVoucherTemplate.id,
              externalIds: this.addVoucherTemplate.ids,
              voucherWord: this.searchFormField.voucherWord,
            };
          }
        } else { //新建的凭证
          if(vocherId=='' || vocherId == null || vocherId == undefined){
            transmissionData = {
              detailList: vData,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              attachmentList: this.fileListData,
              attachmentAccount:this.searchFormField.attachedNum,
              voucherWord: this.searchFormField.voucherWord,
            };
            if(this.insertVoucher > 0)
              transmissionData.num = this.insertVoucher;
          } else {
            transmissionData = {
              detailList: vData,
              id: vocherId,
              remarks: this.searchFormField.noteText,
              bookDate: this.searchFormField.selectDate,
              attachmentList: this.fileListData,
              attachmentAccount:this.searchFormField.attachedNum,
              voucherWord: this.searchFormField.voucherWord,
            };
          }
        }

        this.$set(this.ButtonState, "saveBtn", true);
        this.$set(this.ButtonState, "addSaveBtn", true);
        const loading = this.$loading({
          lock: true,
          text: "正在保存",
          spinner: "el-icon-loading",
          background: "rgba(255,255,255,0.76)",
        });
        //console.log(transmissionData);
        voucherSaveOrUpdate(transmissionData)
            .then((response) => {
              if (response.code == 200) {
                this.$set(
                    this.uploadImg.uploadImgData,
                    "id",
                    response.data.voucherId
                );
                //附件二维码图片
                this.$set(this.searchFormField, "qrCode", response.data.qrCode);
                loading.close();
                this.$message({
                  message: "保存成功！",
                  type: "success",
                });
                if (this.voucherType != "") {
                  this.savaBtnText = "新增";
                  this.$set(this.ButtonState, "addSaveBtn", false);
                } else if (type == "addSave") {
                  this.initData();
                  this.initAddAxios();
                  //初始化当前日期
                  this.getNowTime();
                  this.printerType = true;
                } else if (type == "save") {
                  this.printerType = false;
                  this.savaBtnText = "新增";
                  this.$set(this.ButtonState, "addSaveBtn", false);
                  this.isOnlySave = true;
                }
                // if (method == 'ctrls') {
                //   //ctrl+s保存
                //   this.savaBtnText = "保存并新增";
                // }
                window.localStorage.removeItem("voucherList");
                window.localStorage.removeItem("voucherAssistAccounting");
                //查询该账套审核人
                let loginDeptId = this.$store.state.user.loginDeptId;
                let bookType = this.$store.getters.bookType;
                listByDeptId({ loginDeptID: loginDeptId }).then(
                    (responseData) => {
                      const data = responseData.rows;
                      for (let i = 0; i < data.length; i++) {
                        if (data[i].bookType == bookType) {
                          //console.log(data[i]);
                          this.printObj.chiefAccountant = data[i].chiefAccountant;
                          break;
                        }
                      }
                      //待删----
                      let checkedBy = this.searchFormField.checkedBy;
                      let checkedByData = "";
                      if (
                          typeof checkedBy == "undefined" ||
                          checkedBy == 0 ||
                          checkedBy == "" ||
                          checkedBy == null
                      ) {
                        checkedByData = this.printObj.chiefAccountant;
                      } else {
                        checkedByData = checkedBy;
                      }
                      //审核人
                      this.$set(this.searchFormField, "checkedBy", checkedByData);
                      //待删----
                      this.$forceUpdate()
                    }
                );
                this.isCtrlSActive = true;
                if (this.voucherType === 21) {
                  this.$emit("refreshList");
                }
                //金额数量弹窗
                let assetPermanentList = response.data.assetPermanentList;
                if (assetPermanentList != null && assetPermanentList.length!=0){
                  this.fixedAssets.open = true;
                  this.fixedAssets.list = assetPermanentList;
                  this.$forceUpdate()
                }
                this.onInsertFinished();

              } else {
                loading.close();
                this.$message({
                  message: response.msg,
                  type: "error",
                });
                this.isCtrlSActive = true;
                this.$set(this.ButtonState, "saveBtn", false);
                this.$set(this.ButtonState, "addSaveBtn", false);
              }
              this.$forceUpdate()

            })
            .catch((err) => {
              if (this.voucherType == 21) {
                this.$emit("refreshList");
              }
              this.$set(this.ButtonState, "saveBtn", false);
              this.$set(this.ButtonState, "addSaveBtn", false);
              this.isCtrlSActive = true;
              this.$forceUpdate()
              loading.close();
            });
      }
    },
    getLastDay(d) {
      var current = new Date(d);
      var currentMonth = current.getMonth();
      var nextMonth = ++currentMonth;
      var nextMonthDayOne = new Date(current.getFullYear(), nextMonth, 1);
      var minusDate = 1000 * 60 * 60 * 24;
      return new Date(nextMonthDayOne.getTime() - minusDate);
    },
    approvedTipsFun() {
      let oUrlDate = this.$route.query;

      // if (this.redDashedItems != undefined) {
      // oUrlDate.type == "view" &&
      if (this.redDashedItems != undefined) {
        this.$message({
          message: "红冲凭证不能进行编辑!",
          type: "warning",
        });
      } else if (this.approvedcredentials == false) {
        this.$message({
          message: "查看凭证不能进行编辑!",
          type: "warning",
        });
      } else {
        this.$message({
          message: "已审核的凭证不能进行编辑!",
          type: "warning",
        });
      }
    },
    //凭证打印模板
    voucherPrint() {
      let checkedBy = this.searchFormField.checkedBy;
      let checkedByData = "";
      if (
          typeof checkedBy == undefined ||
          checkedBy == 0 ||
          checkedBy == "" ||
          checkedBy == null
      ) {
        checkedByData = this.printObj.chiefAccountant;
      } else {
        checkedByData = checkedBy;
      }

      let oList = [
        {
          attachmentList: this.fileList,
          bookDate: this.searchFormField.selectDate,
          voucherWord: this.searchFormField.voucherWord,
          num: this.searchFormField.voucherId,
          preparedBy: this.searchFormField.userName,
          checkedBy: checkedByData,
          detailList: this.chargeItme.items,
          voucherAmount: this.debitAmount,
          barCodeList:this.searchFormField.barCodeList,
          checkedTime:this.searchFormField.checkedTime,
          attachmentAccount:this.searchFormField.attachedNum
        },
      ];


      this.$set(
          this.printObj,
          "qrCode",
          this.uploadImg.baseRoutingUrl + this.searchFormField.qrCode
      );
      this.$set(this.printObj, "list", oList);
      this.$set(this.printObj, "visible", true);
    },
    dealWithFile() {
      let dealWithArr = this.handlerDatas(this.fileList);
      this.uploadImg.dealWithFileList = dealWithArr;
      this.uploadImg.attachmentLoading = false;
      //console.log(dealWithArr);
      var that = this;

      this.uploadImg.fileTypeOptions.forEach((item,index)=>{
        that.fileListImg[index] = [];
        if (dealWithArr[item.dictValue]){
          //console.log('进入')
          dealWithArr[item.dictValue].forEach((res,i)=>{
            let fileName = res.name || res.fileUrl;
            let subIndex = fileName.lastIndexOf(".");
            let ext = fileName.substring(subIndex + 1, fileName.length);
            if (ext == "jpg" || ext == "png" || ext == "gif" || ext == "jpeg") {

              if (this.uploadImg.fileTypeOptions.length<2){
                that.fileListImg[index].push('/api'+res.fileUrl)
              }else{
                that.fileListImg[index].push('/api'+res.fileUrl)
              }

              //console.log(that.fileListImg)
            }
          })
        }


      })
    },
    handlerDatas(arr) {
      let obj = {};
      arr.forEach((item, index) => {
        let { fileType } = item;
        if (!obj[fileType]) {
          obj[fileType] = {
            fileType,
            children: [],
          };
        }
        obj[fileType].children.push(item);
      });
      let data = Object.values(obj);
      let newData = {};

      data.forEach((item, i) => {
        let key = item.fileType;
        let value = item.children;
        newData[key] = value;
      });
      return newData;
    },
    //是否是关联合同收款科目 显示弹窗
    contractionFun(event, name, index, line, item){
      this.$set(this.contraction,'visible',true)
      this.$set(this.contraction, 'contractionFundPlanIdList', this.chargeItme.items[index].contractionFundPlanId);
      this.$set(this.contraction,'currentIndex',index)
    },
    //凭证数量和价格限制输入框只能数字小数点
    quanNumValid(val,type,index){
      val = val.match(/^0+[1-9]+/) ? val.replace(/^0+/g, "") : val;
      val = val
          .replace(/[^\d.]/g, "")
          .replace(/^0+\./g, "0.")
          .replace(/\.{2,}/g, ".")
          .replace(".", "$#$")
          .replace(/\./g, "")
          .replace("$#$", ".")
          .replace(/^(\-)*(\d+)\.(\d\d\d\d\d).*$/, "$1$2.$3")
          .replace(/^\./g, "");
      this.$set(this.chargeItme.items[index],type,val);
    },
    addVoucherDetails(detailList) {

      if(!detailList || !detailList.length)
        return;
      if(!CHECK(this.SubjectsMap))
        return;

      let chargeItem = this.chargeItme.items;
      let i = chargeItem.length - 1;
      let start = chargeItem.length;
      while(i >= 0)
      {
        let a = chargeItem[i];
        if (
            a.daiAmount ||
            a.jieAmount ||
            a.subjectId ||
            a.voucherSummary ||
            a.subjectNameAll
        ) {
          break;
        }
        start = i;
        i--;
      }

      this.$set(this.assistAccounting, "accordingState", false);
      let chargeItme = JSON.parse(JSON.stringify(this.chargeItme));
      let dataList = JSON.parse(JSON.stringify(this.assistAccounting.dataList));
      let numRows = this.assistAccounting.numRows;
      let accordingType = this.assistAccounting.accordingType;

      let add = (index) => {
        chargeItme.items.splice(index+1, 0, {
          voucherSummary: "", //摘要
          subjectNameAll: "", //会计科目
          jieAmount: "", //借方金额
          daiAmount: "", //贷方金额
          subjectId: "", //会计科目Id
          subjectMoney: "", //会计科目余额
          quantityNum:'', //数量核算科目-数量
          quantityUnit:'', //数量核算科目-单位
          contractionFundPlanId:null, //关联合同收款科目
        });
        chargeItme.dataStatus.splice(index+1, 0, {
          voucherSummary: true, //摘要
          subjectNameAll: true, //会计科目
          jieAmount: true, //借方金额
          jieComputeAmount:true,  //借方金额计算弹窗
          daiAmount: true, //贷方金额
          daiComputeAmount:true,  //贷方金额计算弹窗
          assistState: false, //辅助核算
          assistType: "", //辅助核算-显示类型
          isQuantity:false, //是否显示数量核算科目
          isContraction:false, //是否显示关联合同收款科目
        });
        dataList.splice(index+1, 0, []);

        return index + 1;
      };

      this.paste = true;
      //console.log(start);
      let origLength = chargeItme.items.length;

      getBalanceList().then((res) => {
        if (res.code == 200) {
          let map = array_toMap(res.data, (x) => x.subjectId);

          for(let i in detailList) {
            let v = detailList[i];
            let index;
            if(start < origLength)
              index = start++;
            else
              index = add(chargeItme.items.length - 1);
            let item = chargeItme.items[index];
            let status = chargeItme.dataStatus[index];

            item.voucherSummary = v.voucherSummary;
            item.subjectNameAll = v.subjectNameAll;
            item.jieAmount = v.jieAmount;
            item.daiAmount = v.daiAmount;
            item.subjectId = v.subjectId;
            item.subjectMoney = v.subjectMoney;

            let subject = this.SubjectsMap[v.subjectId];
            CHECK(subject);
            if(subject)
            {
              item.subjectNameAll = subject.subjectNameAll;

              if(subject.isQuantity === 'Y')
              {
                status.isQuantity = true;
                item.quantityNum = v.quantityNum;
                item.quantityUnit = v.quantityUnit;
              }

              if(subject.isContraction === 'Y')
              {
                status.isContraction = true;
              }

              if (subject.assist) {
                numRows = index;
                //常用辅助核算
                status.assistState = true;
                item.daiAmount = "";
                item.jieAmount = "";

                let assistList = [];
                //设置辅助核算类型
                status.assistType = subject.assist;
                accordingType = subject.assist;
                assistList.push({
                  assist: status.assistType,
                  assistTypeId1: "",
                  assistTypeId2: "",
                  assistTypeId3: "",
                  assistTypeId4: "",
                  daiAmount: "",
                  jieAmount: "",
                });
                dataList[index] = assistList;
              }
            }

            let res = map[v.subjectId];
            let bybalance = res.qmye;
            let endBalance = bybalance == null ? 0 : bybalance;
            item.subjectMoney = endBalance;
          }
          this.$nextTick(() => {
            this.chargeItme = chargeItme;
            this.$set(this.assistAccounting, 'dataList', dataList);
            this.$set(this.assistAccounting, 'numRows', numRows);
            this.$set(this.assistAccounting, 'accordingType', accordingType);
            this.combinedNum();
          })
        }
      }).finally(() => {
        this.paste = false;
      });
    },
    parseClipboard() {
      if(this.paste)
        return false;
      if (this.isCheckedBy) {
        return false;
      }

      if(navigator && navigator.clipboard)
      {
        navigator.clipboard
            .readText()
            .then((src) => {
              if(!src)
              {
                this.msgWarning('粘贴板为空');
                return;
              }
              let text = src.replaceAll('\r', '');
              let arr = text.split('\n');
              if(!arr || !arr.length)
              {
                this.msgWarning('无效内容');
                return;
              }
              let detailList = [];
              for(let i in arr)
              {
                let v = arr[i];
                i = Number(i);
                if(!v)
                  continue;
                let obj = v.split('\t');
                if(!obj || obj.length !== 7)
                {
                  this.msgWarning(`无效内容: 第${i + 1}行`);
                  return;
                }
                if(!obj[0])
                {
                  this.msgWarning(`无效内容: 第${i + 1}行摘要缺失`);
                  return;
                }
                if(!obj[1])
                {
                  this.msgWarning(`无效内容: 第${i + 1}行会计科目编码缺失`);
                  return;
                }
                if(!obj[3] && !obj[4])
                {
                  this.msgWarning(`无效内容: 第${i + 1}行借方金额和贷方金额都为空`);
                  return;
                }
                if(obj[3] && obj[4])
                {
                  this.msgWarning(`无效内容: 第${i + 1}行借方金额和贷方金额不能都有值`);
                  return;
                }
                let item = {
                  voucherSummary: obj[0], //摘要
                  subjectNameAll: obj[2], //会计科目名称
                  jieAmount: obj[3] ? Number(obj[3]) : '', //借方金额
                  daiAmount: obj[4] ? Number(obj[4]) : '', //贷方金额
                  subjectId: obj[1], //会计科目Id
                  subjectMoney: "",
                  quantityNum:  obj[5] ? Number(obj[5]) : '', //数量核算科目-数量
                  quantityUnit: obj[6], //数量核算科目-单位
                  contractionFundPlanId: null, //关联合同收款科目
                };
                detailList.push(item);
              }

              if(!detailList || !detailList.length)
              {
                this.msgWarning(`粘贴板内容解析结果为空`);
                return;
              }

              this.addVoucherDetails(detailList);
            }).catch((v) => {
          console.error("获取剪贴板失败: ", v);
        });
      }
      return true;
    },
    onInsertFinished() {
      if(this.insertVoucher > 0)
      {
        this.insertVoucher = 0;
        this.$forceUpdate();
        setTimeout(() => {
          this.$router.replace(this.$route.path); // 页面不会重新初始化
        }, 500);
      }
    },
    calcDetailBalance(item) {
      let balance = item.subjectMoney;
      if(item.balanceDirection === '借')
      {
        if(!!item.jieAmount)
          balance = FINANCE.add(item.subjectMoney, item.jieAmount);
        else if(!!item.daiAmount)
          balance = FINANCE.sub(item.subjectMoney, item.daiAmount);
      }
      else if(item.balanceDirection === '贷')
      {
        if(!!item.daiAmount)
          balance = FINANCE.add(item.subjectMoney, item.daiAmount);
        else if(!!item.jieAmount)
          balance = FINANCE.sub(item.subjectMoney, item.jieAmount);
      }
      return FINANCE.toNumber(balance);
    },
    poploadVisibleFun() {
      if (this.uploadImg.uploadImgData.id == null || this.uploadImg.uploadImgData.id == "") {
        return false;
      }
      let permiArr = ["finance:voucher:edit"];
      let permission = false;
      this.$set(this.visiblePop, "uploadVisible", true);
      this.visiblePop.uploadVisible_gpy = true;
      if (permission == false) {
        this.$set(this.visiblePop, "uploadTitle", "查看附件");
        this.$set(this.visiblePop, "uploadPermission", true);
      }
      setTimeout(() => {
        if(this.highShotMeter.currentMeter == '成者高拍仪'){
          this.$set(this.uploadImg, "shotMeterDisabled_lt", 1);  //关闭良田高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled_km", 1);  //关闭科密高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled", 2);     //启动成者高拍仪
        }else if(this.highShotMeter.currentMeter == '科密高拍仪'){
          this.$set(this.uploadImg, "shotMeterDisabled_lt", 1);  //关闭良田高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled_km", 2);  //开启科密高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled", 1);     //关闭成者高拍仪
        }else if(this.highShotMeter.currentMeter == '良田高拍仪'){
          this.$set(this.uploadImg, "shotMeterDisabled_lt", 2);  //开启良田高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled_km", 1);  //关闭科密高拍仪
          this.$set(this.uploadImg, "shotMeterDisabled", 1);     //关闭成者高拍仪
        }
        this.$set(this.uploadImg, "startTitle", "关闭");
        // this.$set(this.uploadImg, "shotMeterDisabled", 2);
        // this.$set(this.uploadImg, "shotMeterDisabled_km", 2);
        // this.$set(this.uploadImg, "startTitle", "关闭");
      }, 200);
    },
    closeHighShotMeter() {
      this.$set(this.uploadImg, "shotMeterDisabled", 1);
      this.$set(this.uploadImg, "shotMeterDisabled_km", 1);
      this.$set(this.uploadImg, "shotMeterDisabled_lt", 1);
      this.$set(this.uploadImg, "startTitle", "打开");

      setTimeout(() => {
        this.$set(this.visiblePop, "uploadVisible", false);
        this.visiblePop.uploadVisible = false;
        this.visiblePop.uploadVisible_gpy = false;
        console.log(this.voucherAttachmentAmount)
        if(this.voucherAttachmentAmount == 0){ //自动计算附件数
          if(this.uploadImg.uploadImgData.id ==null || this.uploadImg.uploadImgData.id ==''){return false}
          this.editorData(this.uploadImg.uploadImgData.id)
        }
      }, 300);
    },
    previewPreview(file,index,len) {
      const baseImgUrl = '/api';
      if (file.fileUrl) {
        //已上传文件
        // let fileName = file.name;
        let fileName = file.fileUrl;
        let subIndex = fileName.lastIndexOf(".");
        let ext = fileName.substring(subIndex + 1, fileName.length);
        // if (ext == "jpg" || ext == "png" || ext == "gif" || ext == "jpeg") {
        //   let allUrl = baseImgUrl + file.fileUrl;
        //   this.focusImgUrl = allUrl;
        //   this.uploadImg.rotationAngle = 0;
        //   this.focusVisible = true;
        //   if (!eval('this.$refs.preview'+index)){
        //     console.log('尚未加载完成')
        //     return;
        //   }
        //   if (eval('this.$refs.preview'+index)){
        //     this.initialIndex = len;
        //     console.log('aaaaaaaaaaa')
        //     eval('this.$refs.preview'+index)[0].clickHandler();
        //   }
        // } else {
          let allUrl = baseImgUrl + file.fileUrl;
          const link = document.createElement("a");
          link.style.display = "none";
          link.href = allUrl;
          link.target = '_blank';
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        // }
      } else {
        //新上传文件
        let fileName = file.name;
        let subIndex = fileName.lastIndexOf(".");
        let ext = fileName.substring(subIndex + 1, fileName.length);
        if (ext == "jpg" || ext == "png" || ext == "gif") {
          let allUrl = baseImgUrl + file.response.data.fileUrl;
          this.focusImgUrl = allUrl;
          this.uploadImg.rotationAngle = 0;
          this.focusVisible = true;
        } else {
          let allUrl = baseImgUrl + file.response.data.fileUrl;
          const link = document.createElement("a");
          link.style.display = "none";
          link.href = allUrl;
          // link.setAttribute("download", `${name}.xlsx`);
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        }
      }
    },
  }
};
