gh_agreeAction.js 5.57 KB
Newer Older
qiaoyanqi committed
1 2
import Bridge from '../../components-control/util/bridge'
import { compareData } from "../../components-control/util/dataChange"
3
import { saveBill, verifyBill, showCommentModal } from '../util'
qiaoyanqi committed
4
import { BILL_GLOBAL_PARAM } from '../../constant'
qiaoyanqi committed
5 6 7

export default {
  execute: function (bill, param) {
8
    bill = bill.dom || bill
qiaoyanqi committed
9 10 11 12 13
    if (bill) {
      if (!verifyBill(bill)) {
        GMS.$hideContainer.$Message.error('验签失败')
        return
      }
14 15 16 17 18 19 20 21 22 23 24 25

      // if (!bill.getGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT) || !bill.getGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT).taskId) {
      //   GMS.$hideContainer.$Message.error('请配置审批轨迹')
      //   return
      // }

      // if (!this.isApproverEqulloginer(bill, param)) {
      //   GMS.$hideContainer.$Message.error('单据审批状态已发生变化,请刷新界面')
      //   return
      // }
      bill.setControlsSate(param["_control_name_"], "enable", false)

qiaoyanqi committed
26
      let curTagId = window.nros.context.getCurrTag();
27
      let oldObj = curTagId && GMS.oldBillDataMap && GMS.oldBillDataMap[curTagId]?GMS.oldBillDataMap[curTagId]:GMS.oldBillData;
qiaoyanqi committed
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
      const dataChangeFlag = compareData(oldObj, bill.getBuillData())
      const noRunTimeFormula = bill.getGlobalParam("noRunTimeFormula")
      if (noRunTimeFormula) {
        this.approvalLogical(bill, param, this)
      }
      else if (dataChangeFlag) {
        bill.runFormulaCheckData(param, (msg) => {
          if (msg.length == 0) {
            this.approvalLogical(bill, param, this)
          }
          else {
            GMS.vbus.$Modal.warning({
              title: "信息错误",
              content: msg,
            });
          }
        })
      }
      else {
        bill.runFormulaCheckData(param, (msg) => {
          if (msg.length == 0) {
            GMS.$hideContainer.$Modal.confirm({
              title: "信息提示",
              content: "信息发生变化, 是否保存",
              onOk: () => {
                saveBill(bill, param).then(() => {
                  this.approvalLogical(bill, param)
                })
              },
              onCancel: () => {
              }
            })
          } else {
            GMS.vbus.$Modal.warning({
              title: "信息错误",
              content: msg,
            });
          }
        });
      }
    } else {
      GMS.$hideContainer.$Message.error('缺少参数');
    }
  },
  approvalLogical: function (bill, param) {

74 75 76
    const fn = () => {
      showCommentModal(bill, param).then(() => {
        this.executeApproval(bill, param)
qiaoyanqi committed
77
      }).catch(() => {
78 79
        bill.setControlsSate(param["_control_name_"], "enable", true)
        bill.setControlsSate(param["_control_name_"], "loading", false)
qiaoyanqi committed
80 81 82 83 84 85 86 87 88
      })
    }

    if (param.param.actions) {
      let saveParam = {
        actions: param.param.actions
      }
      bill.executeServerAction(saveParam, function (code, data) {
        if (code === 200) {
89
          fn()
qiaoyanqi committed
90 91 92 93 94 95 96 97 98 99 100
        } else {
          bill.setControlsSate(param["_control_name_"], "enable", true)
          if (data.message.includes('还款金额不能大于未还金额')) {
            GMS.$hideContainer.$message.error("还款金额不能大于未还金额!");
          }
          else {
            GMS.$hideContainer.$message.error("操作异常请联系管理员");
          }
        }
      }.bind(this));
    } else {
101
      fn()
qiaoyanqi committed
102 103 104 105 106 107 108 109 110
    }
  },
  executeApproval: function(bill, param) {
    let taskId = bill.getGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT).taskId;
    let comments =
      bill.getGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT).suggestions
      ? bill.getGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT).suggestions
      : '';

111 112 113 114 115 116 117 118
    if (!comments) {
      comments = '同意'
      bill.setGlobalParam(BILL_GLOBAL_PARAM.APPROVAL_COMMENT, {
        taskId,
        suggestions: comments
      })
    }

qiaoyanqi committed
119 120
    const fn = () => {
      saveBill(bill, param).then(() => {
121 122
        GMS.$http.post(
          `/rbc/bill/action/zgh/change/work/${param.define}/bill.Basic.accept`,
123 124 125 126 127
          {
            approvalComments: comments,
            data: bill.getBuillData(),
            detailData: [],
          }
128
        ).then(
qiaoyanqi committed
129
          function (response) {
130
            console.log('response', response)
qiaoyanqi committed
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
            if (response.status == 200 || response.statusText == 'OK') {
              if (response.data.code != 0) {
                GMS.$hideContainer.$Message.error(response.data.message)
                return
              }
              bill.setControlsSate(param["_control_name_"], "enable", true)
              bill.setControlsSate(param["_control_name_"], "loading", false)
              GMS.$hideContainer.$Message.success('审批成功!')
              let curTagId = window.nros.context.getCurrTag();
              GMS.vbus.$emit('change-form-state', { state: 'readOnly'},curTagId)
              
              if (
                window.osConfig.appOpenMode &&
                window.osConfig.appOpenMode == "apploader"
              ) {
                GMS.$hideContainer.$portalAPI.emit('entry-tag-close')
              }
              else if (Bridge.vm) {
                Bridge.vm.modal_visible = false
              }
              window.GMS.vbus.$emit('refresh-workflow-job-view')
            }
          }.bind(this)
        )
        .catch(
          function (error) {
            bill.setControlsSate(param["_control_name_"], "enable", true)
            bill.setControlsSate(param["_control_name_"], "loading", false)
            GMS.$hideContainer.$Message.error('工作流配置错误,请联系管理员')
          }.bind(this)
        );
      })
    }

165
    fn()
qiaoyanqi committed
166 167 168

  },
}