index.js 11.3 KB
import Api from '~/service/Api';
import commonFunctions from "~/mixin/commonFunctions.js";
import commonDepend from "~/mixin/commonDepend.js";
import moment from 'moment'
import Utils from "~/utils"

export default {
  mixins: [commonFunctions, commonDepend],
  methods: {
    async init(params) {
      const loading = this.loading();
      const rtnmsg = await Api.post(`/${this.moduleRouter()}/${this.trnName}/init`, params);
      if (rtnmsg.respCode === SUCCESS) {
        loading.close();
        this.model = rtnmsg.data;
      } else if (rtnmsg.respCode === '400001') {
        loading.close();
        this.$store.commit('delTagsArry', this.$route.path);
        this.$router.back()
      }
    },

    async getdbCode(codeType, uil, codeNam) {
      let params = {
        codeType: codeType,
        uil: uil ? uil : "EN"
      };
      let rtnmsg = await Api.post("/manager/dic/listDicInfo", params);
      if (rtnmsg.respCode === SUCCESS) {
        let curList = rtnmsg.data.map(item => ({
          value: item.codeValue,
          label: item.codeName
        }));
        this.dbCodes[codeNam] = curList;
      }
    },

    save() {
      // 前端检验
      this.$refs['modelForm'].clearValidate();
      this.$refs['modelForm'].validate(async (validStatic) => {
        if (validStatic) {
          const loading = this.loading();
          this.$store.commit('setLoadingSubmit', true);
          Api.post(`/Financing/dbiblc/save`, this.model).then((res) => {
            if (res.respCode == "AAAAAA") {
              loading.close();
              if (!res.fieldErrors || (res.fieldErrors && Object.keys(res.fieldErrors).length == 0)) {
                this.$notify({
                  title: '成功',
                  message: '提交成功',
                  type: 'success',
                });
                this.$store.commit('delTagsArry', this.$route.path)
								this.$router.back()
              } else {
                const tab = this.showBackendErrors(res.fieldErrors);
                if (tab) {
                  // 判断校验失败的表单不属于当前的tab,则切换tab到对应报错的tab页面
                  if (tab.name !== this.tabVal) {
                    this.tabClick(tab, '1');
                  }
                }
              }
            } else {
              this.$notify.error({
                title: '错误',
                message: res.respMsg
              });
            }
            loading.close();
            this.$store.commit('setLoadingSubmit', false)
          })
        } else {
          // 前端校验失败
          this.$notify({
            title: '失败',
            message: '校验失败',
            type: 'error',
          });
          this.showFrontendErrors()
        }
      })
    },

    // 前端校验失败时候,tab和Collapse组件效果处理
    showFrontendErrors() {
      this.$nextTick(() => {
        let fields = this.$refs['modelForm'].fields;
        let parentVC = null;
        for (let i = 0; i < fields.length; i++) {
          let fieldItem = fields[i];
          if (fieldItem.validateState === 'error') {
            parentVC = fieldItem;
            break;
          }
        }
        let firstErrorTab = null;
        let collapsePanel = null;
        // while循环找出哪个tab和Collapse中报出的校验失败
        while (true) {
          const vcName = parentVC.$options.componentName;
          // 没有Tabs的表单
          if (vcName === "ElForm") {
            break;
          }
          if (vcName === "ElTabPane") {
            firstErrorTab = parentVC;
            break;
          }
          if (vcName === "ElCollapseItem") {
            collapsePanel = parentVC;
          }
          parentVC = parentVC.$parent;
        }
        if (firstErrorTab && firstErrorTab.name !== this.tabVal) {
          const tabs = firstErrorTab.$parent;
          tabs.currentName = firstErrorTab.name;
        }
        if (collapsePanel && collapsePanel.collapse.activeNames.indexOf(collapsePanel.name) < 0) {
          collapsePanel.collapse.activeNames.push(collapsePanel.name)
        }
        setTimeout(() => {
          let isError = document.querySelectorAll('.is-error');
          isError[0].scrollIntoView({
            block: 'center',
            behavior: 'smooth'
          })
        }, 0);
      })
    },

    //退出
    async handleExit() {
      this.$confirm("确认退出?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        Api.post(`/Financing/dbiblc/exit`, this.model);
        this.$store.commit('delTagsArry', this.$route.path)
        this.$router.back()
      })
    },

    isDisabledButton(buttonname) {
      if (this.model.disableSet.includes(buttonname)) {
        return true;
      } else {
        return false;
      }
    },

    clickButtyp(buttyp) {
      switch (buttyp) {
        case "RFU":
          this.rfudialog = true;
          this.model.recpan.buttyp = buttyp;
          break;
        case "ABA":
          this.abddialog = true;
          this.model.recpan.buttyp = buttyp;
          break;
        case "MDF":
          this.model.recpan.buttyp = buttyp;
          break;
        case "BUN":
          this.handleAplBund();
          break;
        case "UNB":
          this.handleAplUnBund();
          break;
        case "REG":
          this.model.recpan.buttyp = buttyp;
          this.loareg();
          break;
        case "RCV":
          this.model.recpan.buttyp = buttyp;
          this.model.recgrp.rec.rcvcur = this.model.recgrp.rec.finloacur;
          this.model.recgrp.rec.rcvamt = this.model.recgrp.rec.finloaamt;
          this.model.recgrp.rec.facrcvdat = new Date();
          this.rcvreg();
          break;
        case "DET":
          this.model.recpan.buttyp = buttyp;
          this.queryDetail();
          break;
      }
    },



    //点击绑定
    handleAplBund() {
      const loading = this.loading();
      Api.post(`/Financing/dbiblc/aplBund`, this.model).then(res => {
        if (res.respCode == SUCCESS) {
          loading.close();
          if (res.data.chksta == "C") {
            this.$confirm("关单超额,已使用,请确认是否继续?", "提示", {
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              this.model.recpan.buttyp = "BUN";
              this.model.recgrp = res.data.blcgrp;
              this.model.disableSet = res.data.disableSet;
            })
          } else {
            this.model.recpan.buttyp = "BUN";
            this.model.recgrp = res.data.blcgrp;
            this.model.disableSet = res.data.disableSet;
          }
        } else {
          this.$notify.error({
            title: '错误',
            message: res.respMsg
          });
        }
        loading.close();
      });
    },

    blurRelref() {
      this.changeRelref()
    },

    //关联业务编号
    changeRelref() {
      if (!this.model.recgrp.rec.relref) {
        this.model.recgrp.rec.relref = "";
        this.model.recgrp.rec.prcrepdat = "";
        this.model.recgrp.rec.finloacur = "";
        this.model.recgrp.rec.finloaamt = "";
        this.model.recgrp.rec.loacur = "";
        this.model.recgrp.rec.loaamt = "";
        this.model.bpdinr = "";
        return
      }
      if (this.model.recgrp.rec.relref) {
        const loading = this.loading();
        Api.post(`/Financing/dbiblc/bpdQuery`, this.model).then((res) => {
          if (res.respCode == SUCCESS) {
            if (res.data.warning) {
              this.$notify.warning(res.data.warning);
            } else {
              this.model.recgrp = res.data.blcgrp;
              this.model.bpdinr = res.data.bpdinr;
            }
            loading.close();
          } else {
            this.$notify.error({
              title: '错误',
              message: res.respMsg
            });
          }
          loading.close();
        })
      }
    },

    //点击解绑定
    handleAplUnBund() {
      const loading = this.loading();
      Api.post(`/Financing/dbiblc/aplUnBund`, this.model).then(res => {
        if (res.respCode == SUCCESS) {
          loading.close();
          this.$confirm("解绑定后该笔融资可能无法再绑定,请确认是否继续解绑定?", "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            this.model.recpan.buttyp = "UNB";
            this.model.recgrp = res.data.blcgrp;
            this.model.disableSet = res.data.disableSet;
          })
        } else {
          this.$notify.error({
            title: '错误',
            message: res.respMsg
          });
        }
        loading.close();
      });
    },

    //放款登记
    loareg() {
      const loading = this.loading('正在调用接口');
      Api.post(`/Financing/dbiblc/loareg`, this.model).then(res => {
        if (res.respCode == SUCCESS) {
          if (res.data.result) {
            this.model.recgrp.rec = res.data.fin;
            this.model.recgrp.fsa = res.data.fsa;
            this.$alert('接口调用成功!', '提示', {
              confirmButtonText: "确认",
              callback: action => {
                if (action == 'confirm') {
                  this.queryDetail()
                }
              }
            })
            loading.close();
          } else {
            this.$notify.error({
              title: '错误',
              message: res.data.fsa.hinmsg
            });
          }
        } else {
          this.$notify.error({
            title: '错误',
            message: res.respMsg
          });
        }
        loading.close();
      });
    },

    //还款登记
    rcvreg() {
      const loading = this.loading();
      Api.post(`/Financing/dbiblc/rcvreg`, this.model).then(res => {
        if (res.respCode == SUCCESS) {
          this.model.disableSet = res.data.disableSet;
          loading.close();
        } else {
          this.$notify.error({
            title: '错误',
            message: res.respMsg
          });
        }
        loading.close();
      });
    },

    wait(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
    },

    //详情查询
    async queryDetail() {
      const loading = this.loading('正在调用详情查询接口');
      await this.wait(5000);
      Api.post(`/Financing/dbiblc/queryDetail`, this.model).then(res => {
        if (res.respCode == SUCCESS) {
          this.model.recgrp = res.data.blcgrp;
          this.model.recpan = res.data.blcp;
          this.visible = true;
          this.model.info = res.data.detailInfo;
          loading.close();
        } else {
          this.$notify.error({
            title: '错误',
            message: res.respMsg
          });
        }
        loading.close();
      });
    },


    //导出excel
    async exportExcel() {
      const loading = this.loading();
      let res = await Api.post("/Financing/dbiblc/exportExcel", {
        ...this.model,
      });
      if (res.respCode === SUCCESS) {
        loading.close();
        let username = this.$store.state.common.username;
        Utils.exportToExcel(res.data, "BGD_" + username + "_" + this.fileCounter.toString().padStart(3, '0') + ".xlsx", "报关单信息");
        this.fileCounter++;
      }
      loading.close();
    },


  },
};