operationFunc.js 5.9 KB
Newer Older
李少勇 committed
1 2
// 此文件存放交易流转的一些公共方法
import Api from '~/service/Api';
李少勇 committed
3
import Utils from "../utils"
李少勇 committed
4 5 6
export default {
  methods: {
    // 提交
李少勇 committed
7
    handleSubmit() {
8
      this.handleCheck(true).then(async () => {
李少勇 committed
9 10
        let params = {
          ...this.model,
WF1020 committed
11 12 13 14
          // gidgrp: {
          //   ...this.model.gidgrp,
          //   ...this.model.gitp
          // },
李少勇 committed
15 16 17 18
          transName: this.trnName,
          userId: window.sessionStorage.userId || 'ZL',
        }
        // 精简cfagit
suwenhao committed
19
        if (params.cfagit && params.cfagit.cfaflg !== '1') {
李少勇 committed
20 21 22
          delete params.cfagit
        }
        // 精简cnybop
suwenhao committed
23
        if (params.cnybop && params.cnybop.vouflg !== '1') {
李少勇 committed
24 25 26 27 28 29 30 31 32
          delete params.cnybop.cnyvou
        }
        const res = await Api.post(`/service/${this.trnName}/save`, params);
        if (res.respCode === SUCCESS) {
          this.$notify({
            title: '成功',
            message: '提交成功',
            type: 'success',
          });
33
          this.$store.dispatch("TagsView/delView", this.$route)
李少勇 committed
34 35 36 37
          this.$router.push('/taskList')
          this.$store.commit("setTaskListTabVal", 'trnrel');
        }
      })
李少勇 committed
38 39
    },
    // 检核
40
    handleCheck(isSubmit) {
李少勇 committed
41 42 43 44 45 46 47 48 49 50
      return new Promise((resolve) => {
        // 前端检验
        this.$refs['modelForm'].validate(async (validStatic) => {
          if (validStatic) {
            const loading = this.loading('正在校验数据');
            const rtnmsg = await Api.post(`/service/${this.trnName}/checkAll`, {
              ...this.model,
              transName: this.trnName,
              userId: window.sessionStorage.userId || 'ZL',
            });
suwenhao committed
51
            loading.close()
李少勇 committed
52 53 54
            if (rtnmsg.respCode === SUCCESS) {
              let errorRules = rtnmsg.data;
              let keysList = Object.keys(errorRules)
李少勇 committed
55 56 57 58
              // 如果后端返回的对象为空,则后端校验成功
              if (errorRules && !keysList.length) {
                // 清除之前的校验状态
                this.$refs['modelForm'].clearValidate();
59 60 61 62 63 64 65
                if (!isSubmit) {
                  this.$notify({
                    title: "成功",
                    message: "校验成功",
                    type: "success",
                  });
                }
李少勇 committed
66 67
                resolve()
                return
李少勇 committed
68
              }
李少勇 committed
69 70 71 72 73 74
              const tab = this.showBackendErrors(errorRules)
              if (tab) {
                // tab切换之后,需出发tab-click的事件
                if (tab.name !== this.tabVal) {
                  this.isChecking = true
                  this.tabClick(tab);
李少勇 committed
75
                }
李少勇 committed
76 77 78 79 80 81 82
                this.$notify({
                  title: "错误",
                  message: "校核失败",
                  type: "error",
                });
                return
              } 
李少勇 committed
83
            }
李少勇 committed
84
          } else {
李少勇 committed
85
            // 前端校验失败
李少勇 committed
86
            this.$notify({
李少勇 committed
87 88 89
              title: '失败',
              message: '校验失败',
              type: 'error',
李少勇 committed
90
            });
91
            this.showFrontendErrors()
李少勇 committed
92
          }
李少勇 committed
93 94
        })
      })
李少勇 committed
95
    },
96
    // 前端校验失败时候,tab和Collapse组件效果处理
李少勇 committed
97
    showFrontendErrors () {
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
      this.$nextTick(() => {
        let fields = this.$refs['modelForm'].fields
        fields.map((fieldItem) => {
          if (fieldItem.validateState === 'error') {
            let parentVC = fieldItem
            let firstErrorTab = null
            let collapsePanel = null
            while(!firstErrorTab) {
              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) {
              const tabs = firstErrorTab.$parent
              tabs.currentName = firstErrorTab.name
            }
            if (collapsePanel && collapsePanel.collapse.activeNames.indexOf(collapsePanel.name) < 0) {
              collapsePanel.collapse.activeNames.push(collapsePanel.name)
            }
          }
        })
        let isError = document.querySelectorAll('.is-error')
        isError[0].scrollIntoView({
          block: 'center',
          behavior: 'smooth'
        })
      })
李少勇 committed
135
    },
李少勇 committed
136 137 138 139 140 141 142 143 144 145 146 147 148
    // 后端校验
    showBackendErrors(fieldErrors) {
      // 清除之前的校验状态
      if (!this.$refs.modelForm) {
        return
      }
      if (!this.isChecking) {
        this.$refs.modelForm.clearValidate();
      } else {
        // 当 checkAll 操作时,由面板切换所触发的 executeRule 请求时,不清空 checkAll 的错误信息
        this.isChecking = false;
      }
      const fields = this.$refs.modelForm.fields;
149
      console.log('backFileds', fields)
李少勇 committed
150 151 152
      const tab = Utils.positioningErrorMsg(fieldErrors, fields);
      return tab;
    },
李少勇 committed
153 154 155 156
    // 暂存
    async handleStash() {
      const loading = this.loading('正在暂存数据');
      let params = {
WF1020 committed
157 158 159
        ...this.model,
          transName: this.trnName,
          userId: window.sessionStorage.userId || 'ZL',
李少勇 committed
160
        spt: JSON.parse(localStorage.getItem('row_' + this.trnName)) || {},
WF1020 committed
161
  
李少勇 committed
162
      }
李少勇 committed
163
      const res = await Api.post(`/service/${this.trnName}/txnHold`, params);
李少勇 committed
164 165 166 167 168 169 170 171
      if (res.respCode === SUCCESS) {
        this.$notify({
          title: '成功',
          message: '暂存成功',
          type: 'success',
        });
        this.$router.push('/taskList')
      }
李少勇 committed
172
      loading.close();
李少勇 committed
173
    },
WF1020 committed
174 175 176 177 178 179
    async handlePass(data) {
      this.$store.state.Transaction.operateFuns[data.operateId]["pass"]()
    },
    async handleRefuse(data) {
      this.$store.state.Transaction.operateFuns[data.operateId]["refuse"]()
    },
李少勇 committed
180 181
  }
}