commonApi.js 7.91 KB
Newer Older
fukai committed
1
import Vue from "vue"
fukai committed
2
import Api from "~/service/Api"
潘际乾 committed
3
import { display } from "~/service/business/file"
4
import { getTrnNameByInr } from "~/service/business/common"
fukai committed
5
import Utils from "../utils"
6
import CodeTable from "~/config/CodeTable";
zhengxiaokui committed
7

fukai committed
8
export default {
zhengxiaokui committed
9
    data() {
fukai committed
10
    },
潘际乾 committed
11 12
    created() {
        if (this.root) {
fukai committed
13 14 15
            //非顶级vue实例,不需要执行
            return;
        }
潘际乾 committed
16 17
        if (this.codes) {
            Vue.set(this.codes, "codeSet", {})
fukai committed
18
        }
fukai committed
19
    },
zhengxiaokui committed
20
    mounted() {
fukai committed
21
        //this.restoreDisplay()
fukai committed
22
    },
zhengxiaokui committed
23
    methods: {
潘际乾 committed
24 25
        updateValueSet(values) {
            if (!values) {
fukai committed
26 27
                return
            }
fukai committed
28
            //顶级实例,进入设置
潘际乾 committed
29 30 31
            if (!this.root) {
                for (let key in values) {
                    Vue.set(this.codes.codeSet, key, values[key])
fukai committed
32 33
                }
            }
潘际乾 committed
34 35
            else {
                this.root.updateValueSet(values)
fukai committed
36 37
            }
        },
38 39
        /*
        获取后台setValues、setCodeValues传来的动态码,并自动转为码表值。
LiRui committed
40 41
        key:为后端传来的CodeSet的字段path,如'bddgrp.rec.docprbrol'
        tableName:src下的全局静态码表中的码表名称,如'rolall'
42 43 44 45
        如后端传来的CodeSet下该字段值为"value+lable",则不用传参数tableName
        如后端传来的CodeSet下该字段值仅有"value",则需传参数tableName,去全局静态码表中找到相应码表,根据value值找到lable值
        */
        getValues(key, tableName) {
fukai committed
46
            let arr = this.codes.codeSet[key]
潘际乾 committed
47
            if (!arr)
48
                return undefined
潘际乾 committed
49 50
            return arr.map(item => {
                let itemArr = item.split("\t")
51 52 53 54 55 56 57 58 59 60 61
                if (itemArr.length > 1) {
                  return { label: item, value: itemArr[0] }
                } else {
                  if (tableName && CodeTable[tableName]) {
                    const r = CodeTable[tableName].find(code => code.value === itemArr[0])
                    if (r) {
                      return { label: r.label, value: itemArr[0] }
                    }
                  }
                  return { label: itemArr[0], value: itemArr[0] }
                }
62 63
            })
        },
潘际乾 committed
64
        showBackendErrors(fieldErrors) {
fukai committed
65
            // 清除之前的校验状态
潘际乾 committed
66
            if (!this.getRoot().$refs.modelForm) {
fukai committed
67 68
                return
            }
69 70 71 72 73 74
            if (!this.isChecking) {
                this.getRoot().$refs.modelForm.clearValidate();
            } else {
                // 当 checkAll 操作时,由面板切换所触发的 executeRule 请求时,不清空 checkAll 的错误信息
                this.isChecking = false;
            }
fukai committed
75 76 77 78
            const fields = this.getRoot().$refs.modelForm.fields;
            const tab = Utils.positioningErrorMsg(fieldErrors, fields);
            return tab;
        },
潘际乾 committed
79
        loading(text) {
80 81 82 83 84 85 86 87
            const loading = this.$loading({
                lock: true,
                text,
                spinner: 'el-icon-loading',
                background: 'rgba(200, 200, 200, 0.3)'
            });
            return loading
        },
潘际乾 committed
88
        getRoot() {
fukai committed
89 90
            return (this.root || this)
        },
fukai committed
91
        async init(params) {
92
            const loading = this.loading("交易加载中")
潘际乾 committed
93 94 95
            let rtnmsg = await Api.post(this.requestPrefix + "/init", { params })
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
96
            }
97
            loading.close()
fukai committed
98
            return rtnmsg
fukai committed
99
        },
100 101
        async save(params) {
            const loading = this.loading("正在保存交易")
潘际乾 committed
102
            let rtnmsg = await Api.post(this.requestPrefix + "/saveData", this.wrapper(params))
103 104
            loading.close()
            return rtnmsg
fukai committed
105
        },
jianglong committed
106 107 108 109 110 111 112 113

        async confirm(params) {
            const loading = this.loading("正在保存交易")
            let rtnmsg = await Api.post(this.requestPrefix + "/confirmData", this.wrapper(params))
            loading.close()
            return rtnmsg
        },

潘际乾 committed
114
        async executeCheck(rulePath, params) {
115
            const loading = this.loading("校验进行中")
潘际乾 committed
116 117 118
            let rtnmsg = await Api.post(this.requestPrefix + "/executeCheck/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
119
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
120
            }
121
            loading.close()
fukai committed
122
            return rtnmsg
fukai committed
123
        },
fukai committed
124
        async executeDefault(rulePath, params) {
潘际乾 committed
125 126 127
            let rtnmsg = await Api.post(this.requestPrefix + "/executeDefault/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
128
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
129 130
            }
            return rtnmsg
fukai committed
131
        },
潘际乾 committed
132
        async executeRule(rulePath, params, delayCb) {
133
            const loading = this.loading("正在请求数据")
潘际乾 committed
134 135 136
            let rtnmsg = await Api.post(this.requestPrefix + "/executeRule/" + rulePath, this.wrapper(params, delayCb))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
137
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
138
            }
139
            loading.close()
fukai committed
140
            return rtnmsg
fukai committed
141
        },
liuxin committed
142 143 144 145 146 147 148 149 150 151 152 153 154
        async executeCustomRule(rulePath, params, delayCb) {
            const loading = this.loading("正在请求数据")
            //copy
            Utils.copyCustomFromModel(this.customModel, this.model)
            console.log(this.customModel)
            let rtnmsg = await Api.post(this.requestPrefix + "/executeRule/" + rulePath, this.wrapperCustom(params, delayCb))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
                this.showBackendErrors(rtnmsg.fieldErrors)
            }
            loading.close()
            return rtnmsg
        },
zhengxiaokui committed
155
        async checkAll(params) {
156
            const loading = this.loading("正在校验数据")
潘际乾 committed
157 158 159
            const rtnmsg = await Api.post(this.requestPrefix + "/checkAll", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
160
            }
161
            loading.close()
fukai committed
162
            return rtnmsg
fukai committed
163
        },
164 165
        async pedding(params) {
            const loading = this.loading("正在暂存数据")
潘际乾 committed
166 167 168
            const rtnmsg = await Api.post(this.requestPrefix + "/pending", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
169 170 171
            }
            loading.close()
            return rtnmsg
fukai committed
172
        },
zhengxiaokui committed
173
        async restoreDisplay() {
fukai committed
174
            let inr = this.$route.query.trn
zhengxiaokui committed
175
            if (!inr)
fukai committed
176
                return
177
            const loading = this.loading("快照数据加载中")
潘际乾 committed
178 179
            let data = await display(inr)
            if (data.data) {
fukai committed
180
                Utils.copyValueFromVO(this.model, JSON.parse(data.data))
潘际乾 committed
181 182
            } else {
                this.$notify.error({ title: '错误', message: '快照文件加载失败!' });
fukai committed
183
            }
184
            loading.close()
185
        },
fukai committed
186
        async executeNotify(params) {
潘际乾 committed
187 188 189
            const rtnmsg = await Api.post(this.requestPrefix + "/executeNotify", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
190 191
            }
            return rtnmsg
192
        },
193 194 195 196 197 198 199 200 201 202 203 204 205
        /**
         * 打开详情页面
         * @param {string} inr 
         */
        display(inr) {
            getTrnNameByInr({ inr }).then((res) => {
                if (res.respCode == SUCCESS) {
                    const trnName = res.data.toLowerCase();
                    let viewurl = "/#/display/" + trnName + "?trn=" + inr
                    window.open(viewurl, 'newwindow', 'height=1500,width=1200,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
                }
            });
        }
fukai committed
206
    }
zhengxiaokui committed
207
}