import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from './buildCommons.js';

export default {
  mixins: [commonFunctions],
  methods: {
    // 点击获取按钮拉取当前key字段下的表单数据
    queryFormData(key) {
      console.log(key);
    },
    // 业务信息=》基本信息=》托收业务编号-----获取托收业务编号
    async getCcdgrpOwnRef() {
      let params = {
        ptainr: this.model.ccdgrp.pre.pts.ptainr,
        businessType: 'CC',
        tbl: 'CC',
      };
      const loading = this.loading();
      let res = await Api.post('/service/ccttra/getOwnRef', params);
      if (res.respCode == SUCCESS) {
        loading.close();
        this.model.ccdgrp.rec.ownref = res.data;
      }
    },
    // 点击获取按钮拉取当前key字段下的表单数据
    queryFormData(key) {
      console.log(key);
    },
    // 获取ccttra弹框表格数据
    async queryGridEtyPromptDialogData(type, ptytyp) {
      let params = {
        userId: window.sessionStorage.userId || 'ZL',
        ptytyp: ptytyp,
        extkey: this.model.ccdgrp[type.toLowerCase()].pts.extkey,
      };
      let res = await Api.post('/service/ptspta/list', params);
      if (res.respCode == SUCCESS) {
        this.root.$refs['etyDialog'].show = true;
        this.root.promptData.data = res.data.ptaInfos;
        this.root.promptData.type = type;
      }
    },
    // 选中ccttra弹框表格的行数据
    async selectGridEtyPromptData(row) {
      let params = {
        ...row,
      };
      let res = await Api.post('/service/ptspta/fetch', params);
      if (res.respCode == SUCCESS) {
        this.$set(this.model.ccdgrp, row.role.toLowerCase(), res.data);
      }
    },
    // 业务信息=》基本信息=》支出目的
    purposChange(key, value) {
      this.handleChangeForm(key, value);
    },
    // 初始化保函开立类型码表下拉列表
    async queryHndtypCodeTableList(trnName) {
      let params = {
        cctp: {
          swiftflg: this.model.cctp.swiftflg,
        },
        ccdgrp: {
          rec: {
            purpos: this.model.ccdgrp.rec.purpos,
          },
        },
        transName: trnName.toUpperCase(),
      };
      let res = await Api.post('/service/ccttra/initHndtyp', params);
      if (res.respCode == SUCCESS) {
        this.$set(this.codes, 'voHndtyp', res.data);
      }
    },
    // 是否SWIFT格式修改--联动保函开立类型
    handleChangeSwiftflg() {
      this.queryHndtypCodeTableList(this.root.trnName);
    },
    // 支出目的修改--联动保函开立类型
    handleChangePurpos() {
      this.queryHndtypCodeTableList(this.root.trnName);
    },
    buildLiaccv () {
      let params = {
        ...buildFn.buildCommonData(this.model, this.trnName),
        liaccvg: this.model.liaccv.liaccvg,
        oldamt: this.model.liaccv.oldamt,
        chgamt: this.model.liaccv.chgamt,
        concur: this.model.liaccv.concur,
      };
      
      return params
    },
    // 公共组件setmod处理方式改变触发联动
    changeSetmodModel (emitParams) {
      let reqParams = {}
      switch (emitParams.code) {
        case 'processMethods':
          reqParams = buildFn.buildSetglg(this.model, this.trnName);
          this.calcPayDetail(reqParams)
          break
        case 'changeDsp':
          let index = emitParams.index;
          let setglgRequest = buildFn.buildSetglg(this.model, this.trnName);
          setglgRequest.setglg = {setgll:  emitParams.list};
          this.setgllAccts(setglgRequest, index);
          break
          default:
          return
      }
    }
  },
};