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
// 此文件存放交易流转的一些公共方法
import Api from '~/service/Api';
import Utils from "../utils"
export default {
methods: {
// 提交
handleSubmit() {
this.handleCheck(true).then(async () => {
let params = {
...this.model,
// gidgrp: {
// ...this.model.gidgrp,
// ...this.model.gitp
// },
transName: this.trnName,
userId: window.sessionStorage.userId || 'ZL',
}
// 精简cfagit
if (params.cfagit && params.cfagit.cfaflg !== '1') {
delete params.cfagit
}
// 精简cnybop
if (params.cnybop && params.cnybop.vouflg !== '1') {
delete params.cnybop.cnyvou
}
const res = await Api.post(`/service/${this.trnName}/save`, params);
if (res.respCode === SUCCESS) {
this.$notify({
title: '成功',
message: '提交成功',
type: 'success',
});
this.$router.push('/taskList')
this.$store.commit("setTaskListTabVal", 'trnrel');
}
})
},
// 检核
handleCheck(isSubmit) {
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',
});
loading.close()
if (rtnmsg.respCode === SUCCESS) {
let errorRules = rtnmsg.data;
let keysList = Object.keys(errorRules)
// 如果后端返回的对象为空,则后端校验成功
if (errorRules && !keysList.length) {
// 清除之前的校验状态
this.$refs['modelForm'].clearValidate();
if (!isSubmit) {
this.$notify({
title: "成功",
message: "校验成功",
type: "success",
});
}
resolve()
return
}
const tab = this.showBackendErrors(errorRules)
if (tab) {
// tab切换之后,需出发tab-click的事件
if (tab.name !== this.tabVal) {
this.isChecking = true
this.tabClick(tab);
}
this.$notify({
title: "错误",
message: "校核失败",
type: "error",
});
return
}
}
} else {
// 前端校验失败
this.$notify({
title: '失败',
message: '校验失败',
type: 'error',
});
this.showFrontendErrors()
}
})
})
},
// 前端校验失败时候,tab和Collapse组件效果处理
showFrontendErrors () {
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'
})
})
},
// 后端校验
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;
console.log('backFileds', fields)
const tab = Utils.positioningErrorMsg(fieldErrors, fields);
return tab;
},
// 暂存
async handleStash() {
const loading = this.loading('正在暂存数据');
let params = {
...this.model,
transName: this.trnName,
userId: window.sessionStorage.userId || 'ZL',
spt: JSON.parse(localStorage.getItem('row_' + this.trnName)) || {},
}
const res = await Api.post(`/service/${this.trnName}/txnHold`, params);
if (res.respCode === SUCCESS) {
this.$notify({
title: '成功',
message: '暂存成功',
type: 'success',
});
this.$router.push('/taskList')
}
loading.close();
},
async handlePass(data) {
this.$store.state.Transaction.operateFuns[data.operateId]["pass"]()
},
async handleRefuse(data) {
this.$store.state.Transaction.operateFuns[data.operateId]["refuse"]()
},
}
}