1
1
<template >
2
- <Dialog :title =" dialogTitle" v-model =" dialogVisible" width =" 80% " >
2
+ <Dialog :title =" dialogTitle" v-model =" dialogVisible" width =" 1300px " >
3
3
<el-form
4
4
ref =" formRef"
5
5
:model =" formData"
21
21
</el-radio >
22
22
</el-radio-group >
23
23
</el-form-item >
24
- <el-form-item label =" 运费" prop =" templateCharge " >
25
- <el-table border style =" width : 100% " :data =" formData.templateCharge " >
26
- <el-table-column align =" center" label =" 区域" width =" 180 " >
24
+ <el-form-item label =" 运费" prop =" charges " >
25
+ <el-table border style =" width : 100% " :data =" formData.charges " >
26
+ <el-table-column align =" center" label =" 区域" width =" 360 " >
27
27
<template #default =" { row } " >
28
- <!-- 区域数据太多,用赖加载方式,要不然性能有问题 -->
29
- <el-tree-select
28
+ <el-cascader
30
29
v-model =" row.areaIds"
31
- :load =" loadChargeArea"
32
- :props =" defaultProps"
33
- node-key =" id"
34
- multiple
35
- check-strictly
36
- show-checkbox
37
- lazy
38
- check-on-click-node
39
- :render-after-expand =" false"
40
- :cache-data =" areaCache"
30
+ :options =" areaTree"
31
+ :props =" defaultProps2"
32
+ class =" w-1/1"
33
+ clearable
34
+ placeholder =" 请选择商品分类"
35
+ filterable
36
+ collapse-tags
41
37
/>
42
38
</template >
43
39
</el-table-column >
85
81
<Icon icon =" ep:plus" class =" mr-5px" /> 添加区域
86
82
</el-button >
87
83
</el-form-item >
88
- <el-form-item label =" 包邮区域" prop =" templateFree " >
89
- <el-table border style =" width : 100% " :data =" formData.templateFree " >
90
- <el-table-column align =" center" label =" 区域" >
84
+ <el-form-item label =" 包邮区域" prop =" frees " >
85
+ <el-table border style =" width : 100% " :data =" formData.frees " >
86
+ <el-table-column align =" center" label =" 区域" width = " 360 " >
91
87
<template #default =" { row } " >
92
- <!-- 区域数据太多,用赖加载方式,要不然性能有问题 -->
93
- <el-tree-select
88
+ <el-cascader
94
89
v-model =" row.areaIds"
95
- multiple
96
- lazy
97
- :load =" loadFreeArea"
98
- :props =" defaultProps"
99
- node-key =" id"
100
- check-strictly
101
- show-checkbox
102
- check-on-click-node
103
- :render-after-expand =" true"
104
- :cache-data =" areaCache"
90
+ :options =" areaTree"
91
+ :props =" defaultProps2"
92
+ class =" w-1/1"
93
+ clearable
94
+ placeholder =" 请选择商品分类"
95
+ filterable
96
+ collapse-tags
105
97
/>
106
98
</template >
107
99
</el-table-column >
140
132
<script lang="ts" setup>
141
133
import { DICT_TYPE , getIntDictOptions } from ' @/utils/dict'
142
134
import * as DeliveryExpressTemplateApi from ' @/api/mall/trade/delivery/expressTemplate'
135
+ import * as AreaApi from ' @/api/system/area'
143
136
import { defaultProps } from ' @/utils/tree'
144
137
import { yuanToFen , fenToYuan } from ' @/utils'
145
- import { getChildrenArea , getAreaListByIds } from ' @/api/system/area'
146
138
import { cloneDeep } from ' lodash-es'
147
139
const { t } = useI18n () // 国际化
148
140
const message = useMessage () // 消息弹窗
149
141
142
+ const defaultProps2 = {
143
+ ... defaultProps ,
144
+ multiple: true
145
+ }
146
+
150
147
const dialogVisible = ref (false ) // 弹窗的是否展示
151
148
const dialogTitle = ref (' ' ) // 弹窗的标题
152
149
const formLoading = ref (false ) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
@@ -156,8 +153,8 @@ const formData = ref({
156
153
name: ' ' ,
157
154
chargeMode: 1 ,
158
155
sort: 0 ,
159
- templateCharge : [],
160
- templateFree : []
156
+ charges : [],
157
+ frees : []
161
158
})
162
159
const columnTitleMap = new Map ()
163
160
const columnTitle = ref ({
@@ -171,9 +168,6 @@ const formRules = reactive({
171
168
sort: [{ required: true , message: ' 分类排序不能为空' , trigger: ' blur' }]
172
169
})
173
170
const formRef = ref () // 表单 Ref
174
- const areaCache = ref ([]) // 由于区域节点懒加载,已选区域节点需要缓存展示
175
- // TODO @jason:配送的时候,只允许选择省市级别,不允许选择区;如果这样的话,是不是打开弹窗,直接把城市都请求过来;
176
- // TODO @jaosn:因为只有省市两级,感觉就不用特殊做全国逻辑;选择全国,就默认把子节点都选择上;另外,选择父节点,要把子节点选中哈;
177
171
178
172
/** 打开弹窗 */
179
173
const open = async (type : string , id ? : number ) => {
@@ -187,30 +181,14 @@ const open = async (type: string, id?: number) => {
187
181
formLoading .value = true
188
182
formData .value = await DeliveryExpressTemplateApi .getDeliveryExpressTemplate (id )
189
183
columnTitle .value = columnTitleMap .get (formData .value .chargeMode )
190
- const chargeAreaIds = []
191
- const freeAreaIds = []
192
- formData .value .templateCharge .forEach ((item ) => {
193
- for (let i = 0 ; i < item .areaIds .length ; i ++ ) {
194
- if (! chargeAreaIds .includes (item .areaIds [i ])) {
195
- chargeAreaIds .push (item .areaIds [i ])
196
- }
197
- }
198
- // 前端价格以元展示
184
+ formData .value .charges .forEach ((item ) => {
185
+ // 前端价格以元展示
199
186
item .startPrice = fenToYuan (item .startPrice )
200
187
item .extraPrice = fenToYuan (item .extraPrice )
201
188
})
202
- formData .value .templateFree .forEach ((item ) => {
203
- for (let i = 0 ; i < item .areaIds .length ; i ++ ) {
204
- if (! chargeAreaIds .includes (item .areaIds [i ]) && ! freeAreaIds .includes (item .areaIds [i ])) {
205
- freeAreaIds .push (item .areaIds [i ])
206
- }
207
- }
189
+ formData .value .frees .forEach ((item ) => {
208
190
item .freePrice = fenToYuan (item .freePrice )
209
191
})
210
- // 已选的区域节点
211
- const areaIds = chargeAreaIds .concat (freeAreaIds )
212
- // 区域节点,懒加载方式。已选节点需要缓存展示
213
- areaCache .value = await getAreaListByIds (areaIds .join (' ,' ))
214
192
}
215
193
} finally {
216
194
formLoading .value = false
@@ -228,14 +206,13 @@ const submitForm = async () => {
228
206
// 提交请求
229
207
formLoading .value = true
230
208
try {
231
- const data = formData .value as DeliveryExpressTemplateApi .DeliveryExpressTemplateVO
209
+ const data = cloneDeep ( formData .value ) as DeliveryExpressTemplateApi .DeliveryExpressTemplateVO
232
210
// 前端价格以元展示,提交到后端。用分计算
233
- // TODO @jason:不能直接这样改,要复制出来改。不然后端操作失败,数据已经被改了
234
- data .templateCharge .forEach ((item ) => {
211
+ data .charges .forEach ((item ) => {
235
212
item .startPrice = yuanToFen (item .startPrice )
236
213
item .extraPrice = yuanToFen (item .extraPrice )
237
214
})
238
- data .templateFree .forEach ((item ) => {
215
+ data .frees .forEach ((item ) => {
239
216
item .freePrice = yuanToFen (item .freePrice )
240
217
})
241
218
if (formType .value === ' create' ) {
@@ -259,7 +236,7 @@ const resetForm = () => {
259
236
id: undefined ,
260
237
name: ' ' ,
261
238
chargeMode: 1 ,
262
- templateCharge : [
239
+ charges : [
263
240
{
264
241
areaIds: [1 ],
265
242
startCount: 2 ,
@@ -268,7 +245,7 @@ const resetForm = () => {
268
245
extraPrice: 10
269
246
}
270
247
],
271
- templateFree : [],
248
+ frees : [],
272
249
sort: 0
273
250
}
274
251
columnTitle .value = columnTitleMap .get (1 )
@@ -279,37 +256,10 @@ const resetForm = () => {
279
256
const changeChargeMode = (chargeMode : number ) => {
280
257
columnTitle .value = columnTitleMap .get (chargeMode )
281
258
}
282
- const defaultArea = [{ id: 1 , name: ' 全国' , disabled: false }]
283
259
284
260
/** 初始化数据 */
285
- // TODO @jason:是不是不用写这样一个初始化方法,columnTitleMap 直接就可以了呀
286
- // const columnTitleMap = {
287
- // '1': {
288
- // startCountTitle: '首件',
289
- // extraCountTitle: '续件',
290
- // freeCountTitle: '包邮件数'
291
- // },
292
- // '2': {
293
- // startCountTitle: '首件重量(kg)',
294
- // extraCountTitle: '续件重量(kg)',
295
- // freeCountTitle: '包邮重量(kg)'
296
- // },
297
- // '3': {
298
- // startCountTitle: '首件体积(m³)',
299
- // extraCountTitle: '续件体积(m³)',
300
- // freeCountTitle: '包邮体积(m³)'
301
- // }
302
- // }
261
+ const areaTree = ref ([])
303
262
const initData = async () => {
304
- // TODO 从服务端全量加载数据, 后面看懒加载是不是可以从前端获取数据。 目前从后端获取数据
305
- // formLoading.value = true
306
- // try {
307
- // const data = await getAreaTree()
308
- // areaTree = data
309
- // console.log('areaTree', areaTree)
310
- // } finally {
311
- // formLoading.value = false
312
- // }
313
263
// 表头标题和计费方式的映射
314
264
columnTitleMap .set (1 , {
315
265
startCountTitle: ' 首件' ,
@@ -326,77 +276,14 @@ const initData = async () => {
326
276
extraCountTitle: ' 续件体积(m³)' ,
327
277
freeCountTitle: ' 包邮体积(m³)'
328
278
})
279
+ // 加载区域数据
280
+ areaTree .value = await AreaApi .getAreaTree ()
329
281
}
330
282
331
- /** 懒加载运费区域树 */
332
- const loadChargeArea = async (node , resolve ) => {
333
- // 已选区域需要禁止再次选择
334
- const areaIds = []
335
- formData .value .templateCharge .forEach ((item ) => {
336
- if (item .areaIds .length > 0 ) {
337
- item .areaIds .forEach ((areaId ) => areaIds .push (areaId ))
338
- }
339
- })
340
- if (node .isLeaf ) return resolve ([])
341
- const length = node .data .length
342
- if (length === 0 ) {
343
- const data = cloneDeep (defaultArea )
344
- const item = data [0 ]
345
- if (areaIds .includes (item .id )) {
346
- // TODO 禁止选中的区域有些问题, 导致修改时候不能重新选择 不知道如何处理。 暂时注释掉 @芋艿 有空瞅瞅
347
- // TODO @jason:先不做这个功能哈。
348
- // item.disabled = true
349
- }
350
- resolve (data )
351
- } else {
352
- const id = node .data .id
353
- const data = await getChildrenArea (id )
354
- data .forEach ((item ) => {
355
- if (areaIds .includes (item .id )) {
356
- // item.disabled = true
357
- }
358
- })
359
- resolve (data )
360
- }
361
- }
362
-
363
- /** 懒加载包邮区域树 */
364
- const loadFreeArea = async (node , resolve ) => {
365
- if (node .isLeaf ) return resolve ([])
366
- // 已选区域需要禁止再次选择
367
- const areaIds = []
368
- formData .value .templateFree .forEach ((item ) => {
369
- if (item .areaIds .length > 0 ) {
370
- item .areaIds .forEach ((areaId ) => areaIds .push (areaId ))
371
- }
372
- })
373
- const length = node .data .length
374
- if (length === 0 ) {
375
- // 为空,从全国开始选择。全国 id == 1
376
- const data = cloneDeep (defaultArea )
377
- const item = data [0 ]
378
- if (areaIds .includes (item .id )) {
379
- // item.disabled = true
380
- }
381
- resolve (data )
382
- } else {
383
- const id = node .data .id
384
- const data = await getChildrenArea (id )
385
- // 已选区域需要禁止再次选择
386
- data .forEach ((item ) => {
387
- if (areaIds .includes (item .id )) {
388
- // TODO 禁止选中的区域有些问题, 导致修改时候不能重新选择 不知道如何处理。 暂时注释掉 @芋艿 有空瞅瞅
389
- // TODO @jason:先不做这个功能哈。
390
- // item.disabled = true
391
- }
392
- })
393
- resolve (data )
394
- }
395
- }
396
283
/** 添加计费区域 */
397
284
const addChargeArea = () => {
398
285
const data = formData .value
399
- data .templateCharge .push ({
286
+ data .charges .push ({
400
287
areaIds: [],
401
288
startCount: 1 ,
402
289
startPrice: 1 ,
@@ -408,13 +295,13 @@ const addChargeArea = () => {
408
295
/** 删除计费区域 */
409
296
const deleteChargeArea = (index ) => {
410
297
const data = formData .value
411
- data .templateCharge .splice (index , 1 )
298
+ data .charges .splice (index , 1 )
412
299
}
413
300
414
301
/** 添加包邮区域 */
415
302
const addFreeArea = () => {
416
303
const data = formData .value
417
- data .templateFree .push ({
304
+ data .frees .push ({
418
305
areaIds: [],
419
306
freeCount: 1 ,
420
307
freePrice: 1
@@ -424,7 +311,7 @@ const addFreeArea = () => {
424
311
/** 删除包邮区域 */
425
312
const deleteFreeArea = (index ) => {
426
313
const data = formData .value
427
- data .templateFree .splice (index , 1 )
314
+ data .frees .splice (index , 1 )
428
315
}
429
316
430
317
/** 初始化 **/
0 commit comments