EditBankDialog.vue
12.9 KB
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
437
438
439
440
<!-- 修改到账模式 -->
<template>
<div>
<glsx-combi-form ref="editFormRef"
class="edit-form-container"
default-width="370px"
label-width="100px"
:form-data="editFormData"
:form-obj="editData"
:form-ref="editChildRef"
:form-rules="formRules">
<div slot="merchantId" slot-scope="scope">
<el-select v-model="editData[scope.scope.name]"
v-el-select-loadmore="interestsLoadmoreMerchant"
v-loading="merchantLoading"
style="width: 370px;"
filterable
remote
:placeholder="scope.scope.placeholder"
:remote-method="(event) => remoteMethod(event, scope.scope.searchKey)"
@change="scope.scope.changeAttr($event, scope.scope)"
@visible-change="(event) => selectVisibleChange(event, scope.scope)">
<el-option v-for="(subItem, subIdx) in scope.scope.optionList"
:key="subIdx"
:label="subItem[scope.scope.optionLabel]"
:value="subItem[scope.scope.optionId]">
</el-option>
</el-select>
</div>
</glsx-combi-form>
<div v-if="oprType != 'add'" class="log-box">
<div>操作记录</div>
<div v-for="(item, index) in editData.logList"
:key="index"
class="log-row">
<div v-for="(subItem, subIdx) in recordList"
:key="subIdx"
class="log-item">
{{ subItem.label }}:{{ item[subItem.name] }}
</div>
</div>
</div>
</div>
</template>
<script>
import { listWithPageAccountStatuses } from "@/api/publicAccount";
import { getBankById, updateBankAccount } from "@/api/specialBankAccount";
import { deepClone, Util } from "@/common/util";
export default {
name: "EditBankDialog",
directives: {
"el-select-loadmore": {
bind(el, binding) {
const SELECTWRAP_DOM = el.querySelector(
".el-select-dropdown .el-select-dropdown__wrap",
);
SELECTWRAP_DOM.addEventListener("scroll", function () {
const condition
= this.scrollHeight - this.scrollTop <= this.clientHeight;
if (condition) {
binding.value();
}
});
},
},
},
props: {
merchantRow: {
type: Object,
default: () => { },
},
oprType: {
type: String,
default: "add",
},
},
data() {
return {
editChildRef: "editChildRef",
merchantLoading: false,
currentPage: 1,
pageSize: 10,
merchantTotalPage: 0,
merchantNameKeyword: "",
formRules: {
accountType: [{ required: true, message: "请选择账号类型", trigger: "change" }],
merchantId: [{ required: false, message: "请选择商户名称", trigger: "change" }],
openAccBankName: [{ required: true, message: "请填写开户银行", trigger: "blur" }],
bankAccountNo: [{ required: true, message: "请填写银行账号", trigger: "blur" }],
bankAccountName: [{ required: true, message: "请填写账户名称", trigger: "blur" }],
remark: [{ required: false, message: "请填写备注", trigger: "blur" }],
},
editData: {
accountType: "",
merchantId: "",
merchantType: "",
remark: "",
},
editFormData: [{
label: "账号类型",
name: "accountType",
type: "select",
style: { width: "46%" },
optionId: "value",
optionLabel: "name",
optionList: [],
optionsName: "accountTypeList",
changeAttr: () => {
this.handleAccountTypeChange();
},
formatter: (cellValue) => {
return this.baseData.accountTypeShow[cellValue.accountType] || "";
},
}, {
label: "商户名称",
name: "merchantId",
addHtml: "merchantId",
style: { width: "46%" },
type: "select",
placeholder: "请选择商户",
isHide: ({ formModel }) => {
return formModel.accountType != "2";
},
optionList: [],
optionId: "merchantId",
optionLabel: "merchantName",
optionsName: "merchantOpt",
searchKey: "merchantNameKeyword",
changeAttr: (value, targetItem) => {
if (value) {
const findItem = targetItem.optionList.find((item) => {
return value == item.merchantId;
});
if (findItem) {
this.editData.merchantName = findItem.merchantName;
}
}
},
}, {
label: "开户银行",
name: "openAccBankName",
type: "input",
style: { width: "46%" },
maxlength: 50,
}, {
label: "银行账号",
name: "bankAccountNo",
type: "input",
style: { width: "46%" },
maxlength: 50,
inputFn: (event) => {
// 只允许:数字 0-9、英文字母 A-Za-z、常见特殊字符(如 !@#$%^&*()_+-=[]{}|;:'",.<>/?`~)
// 排除:中文、空格、换行符、制表符等
const allowedPattern = /[^\w!@#$%^&*()+\-=[\]{}|;:'",.<>?/`~]/g;
const cleanedInput = event.replace(allowedPattern, "");
// 更新银行账号数据
this.editData.bankAccountNo = cleanedInput;
this.editData.bankAccountNo = this.editData.bankAccountNo
.replace(/\s/g, "")
.replace(/(.{4})/g, "$1 ");
let arr = this.editData.bankAccountNo.split("");
if (arr[arr.length - 1] == " ") {
arr.splice(arr.length - 1, 1);
this.editData.bankAccountNo = arr.join("");
}
},
}, {
label: "账户名称",
name: "bankAccountName",
type: "input",
style: { width: "46%" },
maxlength: 50,
}, {
label: "备注",
name: "remark",
type: "input",
style: { width: "46%" },
maxlength: 200,
isHide: ({ formModel }) => {
return !["1", "3"].includes(`${formModel.accountType}`);
},
}, {
label: "录入时间",
name: "createdDate",
type: "showTxt",
isHide: true,
style: { width: "46%" },
}],
recordList: [{
label: "操作项",
name: "operTxt",
}, {
label: "操作时间",
name: "createdDateTxt",
}, {
label: "操作人",
name: "createdBy",
}],
baseData: {
merchantOpt: [],
accountTypeList: [{
name: "灵工平台",
value: 1,
}, {
name: "个体工商户",
value: 2,
}, {
name: "其他",
value: 3,
}],
accountTypeShow: {
1: "灵工平台",
2: "个体工商户",
3: "其他",
},
oprTypeObj: {
1: "新增特殊银行账号",
2: "修改特殊银行账号",
3: "删除特殊银行账号",
},
},
};
},
mounted() {
this.getMerchantList();
this.getOptionsList("editFormData", false, "accountType");
this.oprType !== "detail" && this.setAccountTypeRequired();
this.getInfo();
},
methods: {
setAccountTypeRequired() {
this.$set(this.formRules.merchantId[0], "required", this.editData.accountType == "2");
this.$set(this.formRules.remark[0], "required", ["1", "3"].includes(`${this.editData.accountType}`));
},
handleAccountTypeChange() {
this.setAccountTypeRequired();
this.appendCurrentMerchantOption();
this.$nextTick(() => {
const formRef = this.$refs.editFormRef && this.$refs.editFormRef.$refs[this.editChildRef];
if (formRef) {
formRef.clearValidate(["merchantId", "remark"]);
}
});
},
appendCurrentMerchantOption() {
if (!this.editData.merchantId || !this.editData.merchantName) {
return;
}
const hasCurrentMerchant = this.baseData.merchantOpt.some((item) => {
return item.merchantId == this.editData.merchantId;
});
if (!hasCurrentMerchant) {
this.baseData.merchantOpt.unshift({
merchantId: this.editData.merchantId,
merchantName: this.editData.merchantName,
merchantType: this.editData.merchantType,
});
this.getOptionsList("editFormData", false, "merchantId");
}
},
formatterTxt(attr) {
let idx = this.editFormData.findIndex(item => item.name == attr);
if (idx == -1) {
return true;
}
this.editFormData[idx].formatter && this.editFormData[idx].formatter(this.editData);
},
getInfo() {
const idx = this.editFormData.findIndex(item => item.name == "createdDate");
this.editFormData[idx].isHide = this.oprType == "add";
if (this.oprType == "add") {
return true;
}
if (this.oprType == "detail") {
this.editFormData.forEach((item, idx) => {
this.editFormData[idx].type = "showTxt";
this.editFormData[idx].isHide = false;
if (item.name == "merchantId") {
delete this.editFormData[idx].addHtml;
this.editFormData[idx].name = "merchantName";
}
this.formRules = {};
});
}
if (this.oprType == "edit") {
const notEditList = ["accountType"];
this.editFormData.forEach((item, idx) => {
if (notEditList.includes(item.name)) {
this.editFormData[idx].type = "showTxt";
}
});
}
this.loading = true;
getBankById({ id: this.merchantRow.id }).then((res) => {
this.editData = deepClone(res);
if (this.oprType !== "detail") {
this.setAccountTypeRequired();
}
this.appendCurrentMerchantOption();
this.editData.logList.forEach((item, idx) => {
this.editData.logList[idx].operTxt = this.baseData.oprTypeObj[item.operType];
this.editData.logList[idx].createdDateTxt = Util.dateFormate(item.createdDate, "YYYY-MM-DD HH:mm:ss");
});
}).finally(() => {
this.loading = false;
});
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
let item = this[formName].find(k => k.name == refreshSigle);
let index = this[formName].findIndex(k => k.name == refreshSigle);
if (!item || index == -1) {
return;
}
this.$set(this[formName][index], "optionList", deepClone(this.baseData[item.optionsName]));
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== "全部") {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
} else {
this[formName].forEach((item, index) => {
if (item.type === "select" && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], "optionList", deepClone(this.baseData[item.optionsName]));
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== "全部") {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
}
});
}
},
getMerchantList() {
this.merchantLoading = true;
let params = { currentPage: this.currentPage, pageSize: this.pageSize, merchantName: this.merchantNameKeyword, merchantTypeList: [2, 7, -1] };
listWithPageAccountStatuses(params).then((res) => {
if (res.list) {
res.list = res.list.map((item) => {
return {
merchantId: item.merchantId,
merchantName: item.merchantName,
merchantType: item.merchantType,
};
});
}
this.merchantTotalPage = res.total;
this.baseData.merchantOpt = this.baseData.merchantOpt ? this.baseData.merchantOpt.concat(res.list || []) : res.list;
this.appendCurrentMerchantOption();
this.getOptionsList("editFormData", false, "merchantId");
}).finally(() => {
this.merchantLoading = false;
});
},
// 获取更多4s店数据
interestsLoadmoreMerchant() {
setTimeout(() => {
if (this.merchantLoading) {
return true;
}
this.currentPage = this.currentPage + 1;
if (this.merchantTotalPage < this.currentPage) {
this.currentPage = this.merchantTotalPage;
return;
}
this.getMerchantList();
}, 10);
},
selectVisibleChange(event, item) {
if (event && item.name == "merchantId") {
if (this.merchantNameKeyword) {
this.remoteMethod("", "merchantNameKeyword");
}
}
},
remoteMethod(query, searchKey) {
this[searchKey] = query;
this.currentPage = 1;
this.baseData.merchantOpt = [];
this.getOptionsList("editFormData", false, "merchantId");
this.getMerchantList();
},
// 保存提交
submitForm() {
if (this.oprType == "detail") {
this.$emit("handleBankClose");
} else {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
if (valid) {
this.loading = true;
let params = deepClone(this.editData);
params.bankAccountNo = params.bankAccountNo.replace(/\s*/g, "");
updateBankAccount(params).then((res) => {
this.notice.okTips(this.oprType == "add" ? "新增成功" : "修改成功");
// 刷新列表页
this.$emit("handleBankClose", true);
}).finally(() => {
this.loading = false;
});
}
});
}
},
},
};
</script>
<style lang="scss" scoped>
.title-tips {
margin: 30px 0 0 45px;
color: #999;
}
.log-box {
padding: 16px 20px;
background: #fafafa;
color: #333333;
font-size: 16px;
.log-row {
display: flex;
color: #333333;
font-size: 14px;
margin-top: 20px;
.log-item {
width: 30%;
}
}
}
</style>