index.js 14.8 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 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
import Api from '~/service/Api';
import Utils from "~/utils/index"
import commonFunctions from "~/mixin/commonFunctions.js";
import commonDepend from "~/mixin/commonDepend.js";

export default {
  mixins: [commonFunctions, commonDepend],
  methods: {
    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;
      }
    },

    onRecpanGetref() {

    },

    //导出Excel
    async onRecpanExport() {
      const loading = this.loading();
      let res = await Api.post("/Financing/dbizxb/exportExcel", {
        ...this.model,
      });
      if (res.respCode === SUCCESS) {
        loading.close();
        let username = this.$store.state.common.username;
        Utils.exportToExcel(res.data, "ZXB_" + username + "_" + this.fileCounter.toString().padStart(3, '0') + ".xlsx", "报关单信息");
        this.fileCounter++;
      }
      loading.close();
    },
    //进入交易初始哈
    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 staMdf() {
      const rtnmsg = await Api.post(`/${this.moduleRouter()}/${this.trnName}/handleModifySta`, this.model);
      if (rtnmsg.respCode === SUCCESS) {
        this.model.disableSet = rtnmsg.data.disableSet;
        // this.model.isenableMdf = false;
        this.model.recpan.buttyp = "MDF";
      }
    },
    isDisabledButton(buttonname) {
      if (this.model.disableSet.includes(buttonname)) {
        return true;
      } else {
        return false;
      }
    },

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

    //详情查询
    async queryDetail() {
      const loading = this.loading('正在调用详情查询接口');
      await this.wait(5000);
      Api.post(`/Financing/dbizxb/queryDetail`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          loading.close();
          this.$notify.success(rtnmsg.respMsg);
          Utils.copyValueFromVoData(this.model.recgrp, rtnmsg.data.recgrp);
          Utils.copyValueFromVoData(this.model.recpan, rtnmsg.data.recpan);
          this.model.info = rtnmsg.data.detailInfo;
          this.model.disableSet = rtnmsg.data.disableSet;
          this.showDetails = true;
        } else {
          loading.close();
          this.$notify.error(rtnmsg.respMsg);
        }
        loading.close();
      });
    },
    //承保通知
    async applyNoticeApl() {
      await Api.post(`/Financing/dbizxb/applyNoticeApl`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          if (rtnmsg.data.result) {
            this.model.recgrp.rec = rtnmsg.data.fin;
            this.model.recgrp.fsa = rtnmsg.data.fsa;
            // this.$notify.success(rtnmsg.data.fsa.hinmsg);
          } else {
            // this.$notify.error({ title: '错误', message: rtnmsg.data.fsa.hinmsg });
          }
          // this.queryDetail();
          this.$alert(rtnmsg.data.fsa.hinmsg, '提示', {
            confirmButtonText: "确认",
            callback: action => {
              if (action == 'confirm') {
                this.initdialog = false;
                this.queryDetail();
              }
            }
          })
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
      });
    },
    //承保下载
    async applyNoticeDown() {
      await Api.post(`/Financing/dbizxb/applyNoticeDown`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          if (rtnmsg.data.result) {
            this.model.recgrp.rec = rtnmsg.data.fin;
            this.model.recgrp.fsa = rtnmsg.data.fsa;
            this.download(this.model.recgrp.rec.wgrref, rtnmsg.data.pdfData);
            // this.$notify.success(rtnmsg.data.fsa.hinmsg);
          } else {
            // this.$notify.error({ title: '错误', message: rtnmsg.data.fsa.hinmsg });
          }
          // this.queryDetail();
          this.$alert(rtnmsg.data.fsa.hinmsg, '提示', {
            confirmButtonText: "确认",
            callback: action => {
              if (action == 'confirm') {
                this.initdialog = false;
                this.queryDetail();
              }
            }
          })
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
      });
    },
    async download(filename, pdfData) {
      let blob = this.base64ToBlob(pdfData)
      const fileURL = URL.createObjectURL(blob);
      let tempLink = document.createElement("a")
      tempLink.href = fileURL
      tempLink.style.display = 'none'
      tempLink.download = filename
      document.body.appendChild(tempLink)
      tempLink.click();
      setTimeout(() => {
        document.body.removeChild(tempLink)
        window.URL.revokeObjectURL(fileURL)
      }, 1000);
    },
    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 sinoPay() {
      await Api.post(`/Financing/dbizxb/sinoPay`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          if (rtnmsg.data.result) {
            this.model.recgrp.rec = rtnmsg.data.fin;
            this.model.recgrp.fsa = rtnmsg.data.fsa;
            // this.$notify.success("放款成功!");
          } else {
            // this.$notify.error({ title: '错误', message: rtnmsg.data.fsa.hinmsg });
          }
          // this.queryDetail();
          this.$alert(rtnmsg.data.fsa.hinmsg, '提示', {
            confirmButtonText: "确认",
            callback: action => {
              if (action == 'confirm') {
                this.initdialog = false;
                this.queryDetail();
              }
            }
          })
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
      });
    },
    //还款登记
    async aplSinoRecOnce() {
      await Api.post(`/Financing/dbizxb/aplSinoRecOnce`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          this.model.recpan.buttyp = "RCV";
          this.model.recgrp.rec.rcvcur = rtnmsg.data.zxbgrp.rec.finloacur;
          this.model.recgrp.rec.rcvamt = rtnmsg.data.zxbgrp.rec.finloaamt;
          this.model.recgrp.rec.facrcvdat = rtnmsg.data.zxbgrp.rec.facrcvdat;
          this.model.disableSet = rtnmsg.data.disableSet;
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
      });
    },
    //点击绑定
    handleAplBund() {
      const loading = this.loading();
      Api.post(`/Financing/dbizxb/aplBund`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          loading.close();
          if (rtnmsg.data.chksta == "C") {
            this.$confirm("关单超额,已使用,请确认是否继续?", "提示", {
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              this.model.recpan.buttyp = "BUN";
              this.model.recgrp = rtnmsg.data.zxbgrp;
              this.model.disableSet = rtnmsg.data.disableSet;
            })
          } else {
            this.model.recpan.buttyp = "BUN";
            this.model.recgrp = rtnmsg.data.zxbgrp;
            this.model.disableSet = rtnmsg.data.disableSet;
          }
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
        loading.close();
      });
    },
    //点击解绑定
    handleAplUnBund() {
      const loading = this.loading();
      Api.post(`/Financing/dbizxb/aplUnBund`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          loading.close();
          this.$confirm("解绑定后该笔融资可能无法再绑定,请确认是否继续解绑定?", "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            this.model.recpan.buttyp = "UNB";
            this.model.disableSet = rtnmsg.data.disableSet;
            this.model.recgrp.rec.relref = rtnmsg.data.zxbgrp.rec.relref;
            this.model.recgrp.rec.finloacur = rtnmsg.data.zxbgrp.rec.finloacur;
            this.model.recgrp.rec.finloaamt = rtnmsg.data.zxbgrp.rec.finloaamt;
            this.model.recgrp.rec.loadat = rtnmsg.data.zxbgrp.rec.loadat;
            this.model.recgrp.rec.prcrepdat = rtnmsg.data.zxbgrp.rec.prcrepdat;
            this.model.recgrp.rec.loalimday = rtnmsg.data.zxbgrp.rec.loalimday;
            this.model.recgrp.rec.remark = rtnmsg.data.zxbgrp.rec.remark;
          })
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
        loading.close();
      });
    },
    //查询融资信息
    searchBpd() {
      const loading = this.loading();
      Api.post(`/Financing/dbizxb/searchBpd`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          loading.close();
          if (rtnmsg.data.warning) {
            this.$notify.warning(rtnmsg.data.warning);
          } else {
            this.model.recgrp = rtnmsg.data.zxbgrp;
            this.model.bpdinr = rtnmsg.data.bpdinr;
          }
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
        loading.close();
      });
    },
    //点击申请废弃
    apldel() {
      this.title = "废弃原因界面";
      this.showDialog = true;
      this.model.recpan.buttyp = "ABA";
    },
    //点击放款冲正
    loaund() {
      this.title = "冲正原因界面";
      this.showDialog = true;
      this.model.recpan.buttyp = "UND";
    },
    //确认
    async handleConfirm() {
      await Api.post(`/Financing/dbizxb/handleConfirm`, this.model).then(rtnmsg => {
        if (rtnmsg.respCode == SUCCESS) {
          if (rtnmsg.data.result) {
            Utils.copyValueFromVoData(this.model.recgrp.rec, rtnmsg.data.fin);
            Utils.copyValueFromVoData(this.model.recgrp.fsa, rtnmsg.data.fsa);
            this.$notify({
              title: '成功',
              message: '提交成功',
              type: 'success',
            });
            this.$store.commit('delTagsArry', this.$route.path)
            this.$router.back()
          } else {
            this.$notify.error({ title: '错误', message: rtnmsg.data.fsa.hinmsg });
          }
          this.queryDetail();
        } else {
          this.$message.info(rtnmsg.respMsg);
        }
      });
      // this.model.isenableMdf = true;
      this.showDialog = false;
    },
    //取消
    handleCancel() {
      this.model.recgrp.rec.rfurea = "";
      this.showDialog = false;
    },
    //提交
    handleSubmit() {
      this.$refs['modelForm'].clearValidate();
      this.$refs["modelForm"].validate(valid => {
        if (valid) {
          const loading = this.loading();
          this.$store.commit('setLoadingSubmit', true);
          Api.post(`/Financing/dbizxb/save`, this.model).then(rtnmsg => {
            if (rtnmsg.respCode == SUCCESS) {
              loading.close();
              if (!rtnmsg.fieldErrors || (rtnmsg.fieldErrors && Object.keys(rtnmsg.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: rtnmsg.respMsg
              });
            }
            loading.close();
            this.$store.commit('setLoadingSubmit', false)
          });
          // this.model.isenableMdf = true;
        } 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);
      })
    },

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