import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import buildFn from './buildCommons.js';
import Pts from "~/components/business/commonModel/Pts.js";

export default {
  mixins: [commonFunctions],
  methods: {
    // 支出目的修改--联动保函开立类型
    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
      }
    },
    async getCcdgrpOwnRef() {
      let params = {
        ownref: this.model.ccdgrp.rec.ownref,
        ptainr: this.model.ccdgrp.pre.pts.ptainr,
      };
      const loading = this.loading();
      let res = await Api.post('/Collection/cctdav/getOwnRef', params);
      if (res.respCode == SUCCESS) {
        loading.close();
        this.model.ccdgrp.rec.ownref = res.data;
      } else {
        loading.close();
        this.$message.error(res.respMsg);
      }
    },
    async changeMaxcur() {
      this.model.ccdgrp.cbs.opn1.cur = this.model.ccdgrp.cbs.max.cur;
      if (!this.model.ccdgrp.pre.pts.ptainr) {
        this.$set(this.model.ccdgrp.blk, 'setins', "");
      } else {
        let res = await Api.post('/Collection/cctdav/getSetins', this.model);
        if (res.respCode == SUCCESS) {
          this.$set(this.model.ccdgrp.blk, 'setins', res.data);
        }
      }
    },
    changeMaxamt() {
      this.model.ccdgrp.cbs.opn1.amt = this.model.ccdgrp.cbs.max.amt;
    },
    changemodset() {
      if (this.model.ccdgrp.rec.modset == '2') {
        this.model.ccdgrp.col.pts = new Pts().data;
        this.model.ccdgrp.col.ptainr = "";
        this.model.ccdgrp.col.ptyinr = "";
        this.model.ccdgrp.col.adrblk = "";
        this.model.ccdgrp.col.nam = "";
        this.model.ccdgrp.col.extkey = "";
        this.model.ccdgrp.col.ptytyp = "";
        this.model.ccdgrp.col.cnnam = "";
        this.model.ccdgrp.col.cnadr = "";
        this.model.ccdgrp.col.ennam = "";
        this.model.ccdgrp.col.enadr = "";
        this.model.ccdgrp.col.ref = "";
        this.model.ccdgrp.col.cnnamadr = "";
        this.model.ccdgrp.col.ennamadr = "";
        this.model.ccdgrp.blk.setins = "";
      }
      if (this.model.ccdgrp.rec.modset == '1') {
        this.model.ccdgrp.rec.purflg = 'Z';
      }
    },
    async changePre() {
      if (!this.model.ccdgrp.pre.pts.ptainr) {
        this.$set(this.model.ccdgrp.blk, 'setins', "");
      } else {
        let res = await Api.post('/Collection/cctdav/getSetins', this.model);
        if (res.respCode == SUCCESS) {
          this.$set(this.model.ccdgrp.blk, 'setins', res.data);
        }
      }
    },
  },
};