index.js 9.76 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import BigNumber from 'bignumber.js';



export default {
  mixins: [commonFunctions],
  methods: {

    getDefaultReglstItem() {
      let newRow = {
        itnlincmpaydclrtnno: "",
        txncd: "",
        txnccy: "",
        pymtamt: 0,
        rmk: "",
      };
      let trnName = this.trnName;
      if (this.root) {
        trnName = this.root.trnName;
      }
      if ("CPTOPN".includes(trnName.toUpperCase())) {
        newRow.txnccy = this.model.cpdgrp.cbs.max.cur;
        newRow.pymtamt = this.model.cpdgrp.cbs.max.amt;
      }
      if ("BRTSET".includes(trnName.toUpperCase())) {
        newRow.txnccy = this.model.setmod.doccur;
        newRow.pymtamt = this.model.setmod.docamt;
      }
      if ("BCTSET".includes(trnName.toUpperCase())) {
        newRow.txnccy = this.model.setmod.doccur;
        newRow.pymtamt = this.model.setmod.docamt;
      }
      if ("GITSET".includes(trnName.toUpperCase())) {
        newRow.txnccy = this.model.gidgrp.cbs.max.cur;
        newRow.pymtamt = this.model.gidgrp.cbs.max.amt;
      }
      return newRow;
    },

    buildReqData() {
      let bizInfo = this.root.buildCommonData(this.model, this.root.trnName)
      let trnName = this.trnName;
      if (this.root) {
        trnName = this.root.trnName;
      }
      let rec = {}
      rec.transName = trnName.toUpperCase();
      if ("CPTOPN".includes(trnName.toUpperCase())) {
        rec.cur = this.model.cpdgrp.cbs.max.cur;
        if (rec.cur == '') {
          this.$notify.warning({
            title: '提示',
            message: '请先选择汇款金额币种!'
          });
          return;
        }
        rec.amt = this.model.cpdgrp.cbs.max.amt;
        if (rec.amt == '' || rec.amt == new BigNumber(0)) {
          this.$notify.warning({
            title: '提示',
            message: '请先输入汇款金额!'
          });
          return;
        }
        rec.payeecountcode = this.model.cptp.payeecountcode;
        if (rec.payeecountcode == '') {
          this.$notify.warning({
            title: '提示',
            message: '请先选择收款人常驻国家/地区代码!'
          });
          return;
        }
      }
      if ("BRTSET".includes(trnName.toUpperCase())) {
        rec.cur = this.model.setmod.doccur;
        if (rec.cur == '') {
          this.$notify.warning({
            title: '提示',
            message: '请先选择付款金额币种!'
          });
          return;
        }
        rec.amt = this.model.setmod.docamt;
        if (rec.amt == '' || rec.amt == new BigNumber(0)) {
          this.$notify.warning({
            title: '提示',
            message: '请先输入付款金额!'
          });
          return;
        }
        rec.pntinr = this.model.brdgrp.rec.pntinr;
        if (rec.payeecountcode == '') {
          this.$notify.warning({
            title: '提示',
            message: '所属信用证不存在!'
          });
          return;
        }
      }
      if ("BCTSET".includes(trnName.toUpperCase())) {
        rec.cur = this.model.setmod.doccur;
        if (rec.cur == '') {
          this.$notify.warning({
            title: '提示',
            message: '请先选择付款金额币种!'
          });
          return;
        }
        rec.amt = this.model.setmod.docamt;
        if (rec.amt == '' || rec.amt == new BigNumber(0)) {
          this.$notify.warning({
            title: '提示',
            message: '请先输入付款金额!'
          });
          return;
        }
        rec.stacty = this.model.bcdgrp.rec.stacty;
        if (rec.payeecountcode == '') {
          this.$notify.warning({
            title: '提示',
            message: '请先选择付款人国别!'
          });
          return;
        }
      }
      if ("GITSET".includes(trnName.toUpperCase())) {
        rec.cur = this.model.gidgrp.cbs.max.cur;
        rec.amt = this.model.gidgrp.cbs.max.amt;
        rec.countrycod = this.model.gidgrp.rec.countrycod;
        rec.hndtyp = this.model.gidgrp.rec.hndtyp;
      }
      rec.ptsList = bizInfo.ptsList;
      return rec;
    },

    // 提交核验
    processTxfmod() {
      if(!this.model.txfmod.rcrdno){
        this.$notify.warning("备案表编号不能为空");
        return;
      }
      if(!this.model.txfmod.dataverfcd){
        this.$notify.warning("验证码不能为空");
        return;
      }
      this.processTxfmodInner();
    },

    async processTxfmodInner() {
      let rec = this.buildReqData();
      let request = this.model.txfmod;
      request.rec = rec;
      request.errorMsg = '';
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/txfmod/subtxf`, request);
      loading.close();
      if (res.respCode == SUCCESS) {
        this.model.txfmod = res.data;
        if(this.model.txfmod.txfrst == 'Y'){
          if(this.model.txfmod.txform.sta == '已占用'){
            this.$notify.warning("该备案表已被占用");
            this.model.txfmod.txfrst = '';
          }
          if(this.model.txfmod.txform.sta == '受理中'){
            this.$notify.warning("该笔备案表已业务受理");
            this.payBtnIsShow = "Y";
          }
          // 录入付汇登记信息 初始化置位空
          this.model.txfmod.reglst = [];
          this.model.txfmod.oldreglst = [];
        }
        if(this.model.txfmod.txfrst == 'N'){
          this.$notify.warning(this.model.txfmod.explan);
        }
        if(this.model.txfmod.warningList && this.model.txfmod.warningList.length >0){
          var txt = '';
          for(var i= 0; i<this.model.txfmod.warningList.length;i++){
            var warnItem = this.model.txfmod.warningList[i];
            txt += warnItem.message;
          }
          this.$notify.warning(txt);
        }
      } else {
        this.$notify.error(res.respMsg);
      }
    },

    // 业务受理
    async busacp() {
      let rec = this.buildReqData();
      let request = this.model.txfmod;
      request.rec = rec;
      request.errorMsg = '';
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/txfmod/busacp`, request);
      loading.close();
      if (res.respCode === SUCCESS) {
        this.payBtnIsShow = "Y";
        this.model.txfmod = res.data;
        this.$notify.success("业务受理成功");
        this.processDisabled = 'Y';
        // 录入付汇登记信息
        this.model.txfmod.reglst = this.model.txfmod.oldreglst;
        if (this.model.txfmod.reglst && this.model.txfmod.reglst.length < 1) {
          var newRow = this.getDefaultReglstItem();
          this.model.txfmod.reglst.splice(0, 0, newRow);
        }
        this.selectBopcod();
      } else {
        this.payBtnIsShow = "N";
        this.processDisabled = 'N';
        this.$notify.error(res.respMsg);
      }
    },

    // 付汇取消
    async calpay() {
      let rec = this.buildReqData();
      let request = this.model.txfmod;
      request.rec = rec;
      request.errorMsg = '';
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/txfmod/calpay`, request);
      loading.close();
      if (res.respCode === SUCCESS) {
        this.$notify.success(res.data);
        this.model.txfmod.txfrst = "close";
        this.model.txfmod.hyflg = '';
        this.model.txfmod.acpflg = '';
        this.payBtnIsShow = "N";
        this.processDisabled = 'N';
      } else {
        this.$notify.warning(res.respMsg + "--状态未更新,请稍后再试");
      }
    },

    async downloadInfo() {
      let rec = this.buildReqData();
      let request = this.model.txfmod;
      request.rec = rec;
      request.errorMsg = '';
      let result = await this.showPdf(request);
      if (result == "SUCCESS") {
        this.$refs.downloadA.click();
        this.$notify.success("生成PDF文件成功!");
      } else {
        this.$notify.error("生成PDF文件失败!");
      }
    },

    // 预览
    async showPdf(reqData) {
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/txfmod/showPdf`, reqData);
      loading.close();
      if (res.respCode === SUCCESS) {
        this.viewPdf(res.data.data);
        return "SUCCESS";
      } else {
        this.$notify.error(res.respMsg);
        return "ERROR";
      }
    },

    viewPdf(content) {
      if (!content) {
        this.$message.error("无备案表详情内容");
        return;
      }
      const blob = this.base64ToBlob(content);
      const fileURL = URL.createObjectURL(blob);
      this.viewPdfUrl = fileURL + "#view=FitH,top";
    },

    base64ToBlob(code) {
      code = code.replace(/[\n\r]/g, "");
      const raw = window.atob(code);
      const rawLength = raw.length;
      const uInt8Array = new Uint8Array(rawLength);
      for (let i = 0; i < rawLength; ++i) {
        uInt8Array[i] = raw.charCodeAt(i);
      }
      return new Blob([uInt8Array], {
        type: "application/pdf"
      });
    },

    // 获取交易编码列表
    async selectBopcod() {
      let rec = {
        transName:"DBWTXF"
      };
      let request = this.model.txfmod;
      request.rec = rec;
      request.errorMsg = '';
      const loading = this.loading();
      let res = await Api.post(`/${this.moduleRouter()}/txfmod/selectBopcod`,request);
      loading.close();
      if (res.respCode === SUCCESS) {
        this.txncdList = res.data;
      } else {
        this.txncdList = [];
        this.$notify.error("查询收支申报交易编码报错");
      }
    },
    // 格式化数据
    formatLabel(item) {
      return item.cod + ' - ' + item.txt
    },
    txfflgChange(){
      if(this.model.txfmod.hyflg == 'Y'){
        this.model.txfmod.txfflg = 'X';
        this.$notify.warning("备案表已经核验,请先点击“关闭”按钮,再取消勾选");
      }
    }
  },
};