27
27
<template #default =" { row } " >
28
28
<!-- 区域数据太多,用赖加载方式,要不然性能有问题 -->
29
29
<el-tree-select
30
- v-model =" row.areaId "
30
+ v-model =" row.areaIds "
31
31
lazy
32
32
:load =" loadChargeArea"
33
33
:props =" defaultProps"
34
+ multiple
34
35
node-key =" id"
35
36
check-strictly
36
37
show-checkbox
90
91
<template #default =" { row } " >
91
92
<!-- 区域数据太多,用赖加载方式,要不然性能有问题 -->
92
93
<el-tree-select
93
- v-model =" row.areaId"
94
+ v-model =" row.areaIds"
95
+ multiple
94
96
lazy
95
97
:load =" loadFreeArea"
96
98
:props =" defaultProps"
97
99
node-key =" id"
98
100
check-strictly
99
101
show-checkbox
100
102
check-on-click-node
101
- :render-after-expand =" false "
103
+ :render-after-expand =" true "
102
104
:cache-data =" areaCache"
103
105
/>
104
106
</template >
@@ -170,7 +172,6 @@ const formRules = reactive({
170
172
})
171
173
const formRef = ref () // 表单 Ref
172
174
const areaCache = ref ([]) // 由于区域节点懒加载,已选区域节点需要缓存展示
173
- // let areaTree: any[]
174
175
/** 打开弹窗 */
175
176
const open = async (type : string , id ? : number ) => {
176
177
dialogVisible .value = true
@@ -183,25 +184,30 @@ const open = async (type: string, id?: number) => {
183
184
formLoading .value = true
184
185
formData .value = await DeliveryExpressTemplateApi .getDeliveryExpressTemplate (id )
185
186
columnTitle .value = columnTitleMap .get (formData .value .chargeMode )
186
- // 已选的区域节点
187
- const areaIds = []
187
+ const chargeAreaIds = []
188
+ const freeAreaIds = []
188
189
formData .value .templateCharge .forEach ((item ) => {
189
- // 不等于全国的节点
190
- if (item .areaId !== 1 ) {
191
- areaIds .push (item .areaId )
190
+ for (let i = 0 ; i < item .areaIds .length ; i ++ ) {
191
+ if (! chargeAreaIds .includes (item .areaIds [i ])) {
192
+ chargeAreaIds .push (item .areaIds [i ])
193
+ }
192
194
}
193
195
// 前端价格以元展示
194
196
item .startPrice = fenToYuan (item .startPrice )
195
197
item .extraPrice = fenToYuan (item .extraPrice )
196
198
})
197
199
formData .value .templateFree .forEach ((item ) => {
198
- if (item .areaId !== 1 && ! areaIds .includes (item .areaId )) {
199
- areaIds .push (item .areaId )
200
+ for (let i = 0 ; i < item .areaIds .length ; i ++ ) {
201
+ if (! chargeAreaIds .includes (item .areaIds [i ]) && ! freeAreaIds .includes (item .areaIds [i ])) {
202
+ freeAreaIds .push (item .areaIds [i ])
203
+ }
200
204
}
201
205
item .freePrice = fenToYuan (item .freePrice )
202
206
})
207
+ // 已选的区域节点
208
+ const areaIds = chargeAreaIds .concat (freeAreaIds )
203
209
// 区域节点,懒加载方式。 已选节点需要缓存展示
204
- areaCache .value = await getAreaListByIds (areaIds )
210
+ areaCache .value = await getAreaListByIds (areaIds . join ( ' , ' ) )
205
211
}
206
212
} finally {
207
213
formLoading .value = false
@@ -250,7 +256,7 @@ const resetForm = () => {
250
256
chargeMode: 1 ,
251
257
templateCharge: [
252
258
{
253
- areaId: 1 ,
259
+ areaIds: [ 1 ] ,
254
260
startCount: 2 ,
255
261
startPrice: 5 ,
256
262
extraCount: 5 ,
@@ -300,10 +306,11 @@ const initData = async () => {
300
306
301
307
/** 懒加载运费区域树 */
302
308
const loadChargeArea = async (node , resolve ) => {
309
+ // 已选区域需要禁止再次选择
303
310
const areaIds = []
304
311
formData .value .templateCharge .forEach ((item ) => {
305
- if (item .areaId ) {
306
- areaIds .push ( item . areaId )
312
+ if (item .areaIds . length > 0 ) {
313
+ item . areaIds .forEach (( areaId ) => areaIds . push ( areaId ) )
307
314
}
308
315
})
309
316
if (node .isLeaf ) return resolve ([])
@@ -312,15 +319,16 @@ const loadChargeArea = async (node, resolve) => {
312
319
const data = cloneDeep (defaultArea )
313
320
const item = data [0 ]
314
321
if (areaIds .includes (item .id )) {
315
- item .disabled = true
322
+ // TODO 禁止选中的区域有些问题, 导致修改时候不能重新选择 不知道如何处理。 暂时注释掉 @芋艿 有空瞅瞅
323
+ // item.disabled = true
316
324
}
317
325
resolve (data )
318
326
} else {
319
327
const id = node .data .id
320
328
const data = await getChildrenArea (id )
321
329
data .forEach ((item ) => {
322
330
if (areaIds .includes (item .id )) {
323
- item .disabled = true
331
+ // item.disabled = true
324
332
}
325
333
})
326
334
resolve (data )
@@ -330,11 +338,11 @@ const loadChargeArea = async (node, resolve) => {
330
338
/** 懒加载包邮区域树 */
331
339
const loadFreeArea = async (node , resolve ) => {
332
340
if (node .isLeaf ) return resolve ([])
333
- // 已经选择的区域id
341
+ // 已选区域需要禁止再次选择
334
342
const areaIds = []
335
343
formData .value .templateFree .forEach ((item ) => {
336
- if (item .areaId ) {
337
- areaIds .push ( item . areaId )
344
+ if (item .areaIds . length > 0 ) {
345
+ item . areaIds .forEach (( areaId ) => areaIds . push ( areaId ) )
338
346
}
339
347
})
340
348
const length = node .data .length
@@ -343,7 +351,7 @@ const loadFreeArea = async (node, resolve) => {
343
351
const data = cloneDeep (defaultArea )
344
352
const item = data [0 ]
345
353
if (areaIds .includes (item .id )) {
346
- item .disabled = true
354
+ // item.disabled = true
347
355
}
348
356
resolve (data )
349
357
} else {
@@ -352,7 +360,8 @@ const loadFreeArea = async (node, resolve) => {
352
360
// 已选区域需要禁止再次选择
353
361
data .forEach ((item ) => {
354
362
if (areaIds .includes (item .id )) {
355
- item .disabled = true
363
+ // TODO 禁止选中的区域有些问题, 导致修改时候不能重新选择 不知道如何处理。 暂时注释掉 @芋艿 有空瞅瞅
364
+ // item.disabled = true
356
365
}
357
366
})
358
367
resolve (data )
@@ -362,7 +371,7 @@ const loadFreeArea = async (node, resolve) => {
362
371
const addChargeArea = () => {
363
372
const data = formData .value
364
373
data .templateCharge .push ({
365
- areaId: undefined ,
374
+ areaIds: [] ,
366
375
startCount: 1 ,
367
376
startPrice: 1 ,
368
377
extraCount: 1 ,
@@ -378,7 +387,7 @@ const deleteChargeArea = (index) => {
378
387
const addFreeArea = () => {
379
388
const data = formData .value
380
389
data .templateFree .push ({
381
- areaId: undefined ,
390
+ areaIds: [] ,
382
391
freeCount: 1 ,
383
392
freePrice: 1
384
393
})
0 commit comments