trade:优化运费模版的实现

(cherry picked from commit a9bbbc7b0a)
This commit is contained in:
YunaiV 2023-10-02 18:30:22 +08:00 committed by shizhong
parent de47866f49
commit 7d44b98116
5 changed files with 58 additions and 179 deletions

View File

@ -5,14 +5,6 @@ export const getAreaTree = async () => {
return await request.get({ url: '/system/area/tree' }) return await request.get({ url: '/system/area/tree' })
} }
export const getChildrenArea = async (id: number) => {
return await request.get({ url: '/system/area/get-children?id=' + id })
}
export const getAreaListByIds = async (ids) => {
return await request.get({ url: '/system/area/get-by-ids?ids=' + ids })
}
// 获得 IP 对应的地区名 // 获得 IP 对应的地区名
export const getAreaByIp = async (ip: string) => { export const getAreaByIp = async (ip: string) => {
return await request.get({ url: '/system/area/get-by-ip?ip=' + ip }) return await request.get({ url: '/system/area/get-by-ip?ip=' + ip })

View File

@ -7,17 +7,17 @@
label-width="120px" label-width="120px"
v-loading="formLoading" v-loading="formLoading"
> >
<el-form-item label="快递公司编码" prop="code"> <el-form-item label="公司编码" prop="code">
<el-input v-model="formData.code" placeholder="请输入快递编码" /> <el-input v-model="formData.code" placeholder="请输入快递编码" />
</el-form-item> </el-form-item>
<el-form-item label="快递公司名称" prop="name"> <el-form-item label="公司名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入快递名称" /> <el-input v-model="formData.name" placeholder="请输入快递名称" />
</el-form-item> </el-form-item>
<el-form-item label="快递公司 logo" prop="logo"> <el-form-item label="公司 logo" prop="logo">
<UploadImg v-model="formData.logo" :limit="1" :is-show-tip="false" /> <UploadImg v-model="formData.logo" :limit="1" :is-show-tip="false" />
<div style="font-size: 10px" class="pl-10px">推荐 180x180 图片分辨率</div> <div style="font-size: 10px" class="pl-10px">推荐 180x180 图片分辨率</div>
</el-form-item> </el-form-item>
<el-form-item label="分类排序" prop="sort"> <el-form-item label="排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" /> <el-input-number v-model="formData.sort" controls-position="right" :min="0" />
</el-form-item> </el-form-item>
<el-form-item label="开启状态" prop="status"> <el-form-item label="开启状态" prop="status">

View File

@ -53,11 +53,11 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="快递公司编号" prop="code" /> <el-table-column label="公司编码" prop="code" />
<el-table-column label="快递公司名称" prop="name" /> <el-table-column label="公司名称" prop="name" />
<el-table-column label="快递公司 logo " prop="logo"> <el-table-column label="公司 logo " prop="logo">
<template #default="scope"> <template #default="scope">
<img v-if="scope.row.logo" :src="scope.row.logo" alt="快递公司logo" class="h-100px" /> <img v-if="scope.row.logo" :src="scope.row.logo" alt="公司logo" class="h-40px" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="排序" align="center" prop="sort" /> <el-table-column label="排序" align="center" prop="sort" />

View File

@ -1,5 +1,5 @@
<template> <template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="80%"> <Dialog :title="dialogTitle" v-model="dialogVisible" width="1300px">
<el-form <el-form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@ -21,23 +21,19 @@
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="运费" prop="templateCharge"> <el-form-item label="运费" prop="charges">
<el-table border style="width: 100%" :data="formData.templateCharge"> <el-table border style="width: 100%" :data="formData.charges">
<el-table-column align="center" label="区域" width="180"> <el-table-column align="center" label="区域" width="360">
<template #default="{ row }"> <template #default="{ row }">
<!-- 区域数据太多用赖加载方式要不然性能有问题 --> <el-cascader
<el-tree-select
v-model="row.areaIds" v-model="row.areaIds"
:load="loadChargeArea" :options="areaTree"
:props="defaultProps" :props="defaultProps2"
node-key="id" class="w-1/1"
multiple clearable
check-strictly placeholder="请选择商品分类"
show-checkbox filterable
lazy collapse-tags
check-on-click-node
:render-after-expand="false"
:cache-data="areaCache"
/> />
</template> </template>
</el-table-column> </el-table-column>
@ -85,23 +81,19 @@
<Icon icon="ep:plus" class="mr-5px" /> 添加区域 <Icon icon="ep:plus" class="mr-5px" /> 添加区域
</el-button> </el-button>
</el-form-item> </el-form-item>
<el-form-item label="包邮区域" prop="templateFree"> <el-form-item label="包邮区域" prop="frees">
<el-table border style="width: 100%" :data="formData.templateFree"> <el-table border style="width: 100%" :data="formData.frees">
<el-table-column align="center" label="区域"> <el-table-column align="center" label="区域" width="360">
<template #default="{ row }"> <template #default="{ row }">
<!-- 区域数据太多用赖加载方式要不然性能有问题 --> <el-cascader
<el-tree-select
v-model="row.areaIds" v-model="row.areaIds"
multiple :options="areaTree"
lazy :props="defaultProps2"
:load="loadFreeArea" class="w-1/1"
:props="defaultProps" clearable
node-key="id" placeholder="请选择商品分类"
check-strictly filterable
show-checkbox collapse-tags
check-on-click-node
:render-after-expand="true"
:cache-data="areaCache"
/> />
</template> </template>
</el-table-column> </el-table-column>
@ -140,13 +132,18 @@
<script lang="ts" setup> <script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as DeliveryExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate' import * as DeliveryExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
import * as AreaApi from '@/api/system/area'
import { defaultProps } from '@/utils/tree' import { defaultProps } from '@/utils/tree'
import { yuanToFen, fenToYuan } from '@/utils' import { yuanToFen, fenToYuan } from '@/utils'
import { getChildrenArea, getAreaListByIds } from '@/api/system/area'
import { cloneDeep } from 'lodash-es' import { cloneDeep } from 'lodash-es'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const defaultProps2 = {
...defaultProps,
multiple: true
}
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('') // const dialogTitle = ref('') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
@ -156,8 +153,8 @@ const formData = ref({
name: '', name: '',
chargeMode: 1, chargeMode: 1,
sort: 0, sort: 0,
templateCharge: [], charges: [],
templateFree: [] frees: []
}) })
const columnTitleMap = new Map() const columnTitleMap = new Map()
const columnTitle = ref({ const columnTitle = ref({
@ -171,9 +168,6 @@ const formRules = reactive({
sort: [{ required: true, message: '分类排序不能为空', trigger: 'blur' }] sort: [{ required: true, message: '分类排序不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const areaCache = ref([]) //
// TODO @jason
// TODO @jaosn
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
@ -187,30 +181,14 @@ const open = async (type: string, id?: number) => {
formLoading.value = true formLoading.value = true
formData.value = await DeliveryExpressTemplateApi.getDeliveryExpressTemplate(id) formData.value = await DeliveryExpressTemplateApi.getDeliveryExpressTemplate(id)
columnTitle.value = columnTitleMap.get(formData.value.chargeMode) columnTitle.value = columnTitleMap.get(formData.value.chargeMode)
const chargeAreaIds = [] formData.value.charges.forEach((item) => {
const freeAreaIds = []
formData.value.templateCharge.forEach((item) => {
for (let i = 0; i < item.areaIds.length; i++) {
if (!chargeAreaIds.includes(item.areaIds[i])) {
chargeAreaIds.push(item.areaIds[i])
}
}
// //
item.startPrice = fenToYuan(item.startPrice) item.startPrice = fenToYuan(item.startPrice)
item.extraPrice = fenToYuan(item.extraPrice) item.extraPrice = fenToYuan(item.extraPrice)
}) })
formData.value.templateFree.forEach((item) => { formData.value.frees.forEach((item) => {
for (let i = 0; i < item.areaIds.length; i++) {
if (!chargeAreaIds.includes(item.areaIds[i]) && !freeAreaIds.includes(item.areaIds[i])) {
freeAreaIds.push(item.areaIds[i])
}
}
item.freePrice = fenToYuan(item.freePrice) item.freePrice = fenToYuan(item.freePrice)
}) })
//
const areaIds = chargeAreaIds.concat(freeAreaIds)
//
areaCache.value = await getAreaListByIds(areaIds.join(','))
} }
} finally { } finally {
formLoading.value = false formLoading.value = false
@ -228,14 +206,13 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value as DeliveryExpressTemplateApi.DeliveryExpressTemplateVO const data = cloneDeep(formData.value) as DeliveryExpressTemplateApi.DeliveryExpressTemplateVO
// //
// TODO @jason data.charges.forEach((item) => {
data.templateCharge.forEach((item) => {
item.startPrice = yuanToFen(item.startPrice) item.startPrice = yuanToFen(item.startPrice)
item.extraPrice = yuanToFen(item.extraPrice) item.extraPrice = yuanToFen(item.extraPrice)
}) })
data.templateFree.forEach((item) => { data.frees.forEach((item) => {
item.freePrice = yuanToFen(item.freePrice) item.freePrice = yuanToFen(item.freePrice)
}) })
if (formType.value === 'create') { if (formType.value === 'create') {
@ -259,7 +236,7 @@ const resetForm = () => {
id: undefined, id: undefined,
name: '', name: '',
chargeMode: 1, chargeMode: 1,
templateCharge: [ charges: [
{ {
areaIds: [1], areaIds: [1],
startCount: 2, startCount: 2,
@ -268,7 +245,7 @@ const resetForm = () => {
extraPrice: 10 extraPrice: 10
} }
], ],
templateFree: [], frees: [],
sort: 0 sort: 0
} }
columnTitle.value = columnTitleMap.get(1) columnTitle.value = columnTitleMap.get(1)
@ -279,37 +256,10 @@ const resetForm = () => {
const changeChargeMode = (chargeMode: number) => { const changeChargeMode = (chargeMode: number) => {
columnTitle.value = columnTitleMap.get(chargeMode) columnTitle.value = columnTitleMap.get(chargeMode)
} }
const defaultArea = [{ id: 1, name: '全国', disabled: false }]
/** 初始化数据 */ /** 初始化数据 */
// TODO @jasoncolumnTitleMap const areaTree = ref([])
// const columnTitleMap = {
// '1': {
// startCountTitle: '',
// extraCountTitle: '',
// freeCountTitle: ''
// },
// '2': {
// startCountTitle: '(kg)',
// extraCountTitle: '(kg)',
// freeCountTitle: '(kg)'
// },
// '3': {
// startCountTitle: '(m³)',
// extraCountTitle: '(m³)',
// freeCountTitle: '(m³)'
// }
// }
const initData = async () => { const initData = async () => {
// TODO
// formLoading.value = true
// try {
// const data = await getAreaTree()
// areaTree = data
// console.log('areaTree', areaTree)
// } finally {
// formLoading.value = false
// }
// //
columnTitleMap.set(1, { columnTitleMap.set(1, {
startCountTitle: '首件', startCountTitle: '首件',
@ -326,77 +276,14 @@ const initData = async () => {
extraCountTitle: '续件体积(m³)', extraCountTitle: '续件体积(m³)',
freeCountTitle: '包邮体积(m³)' freeCountTitle: '包邮体积(m³)'
}) })
//
areaTree.value = await AreaApi.getAreaTree()
} }
/** 懒加载运费区域树 */
const loadChargeArea = async (node, resolve) => {
//
const areaIds = []
formData.value.templateCharge.forEach((item) => {
if (item.areaIds.length > 0) {
item.areaIds.forEach((areaId) => areaIds.push(areaId))
}
})
if (node.isLeaf) return resolve([])
const length = node.data.length
if (length === 0) {
const data = cloneDeep(defaultArea)
const item = data[0]
if (areaIds.includes(item.id)) {
// TODO @
// TODO @jason
//item.disabled = true
}
resolve(data)
} else {
const id = node.data.id
const data = await getChildrenArea(id)
data.forEach((item) => {
if (areaIds.includes(item.id)) {
//item.disabled = true
}
})
resolve(data)
}
}
/** 懒加载包邮区域树 */
const loadFreeArea = async (node, resolve) => {
if (node.isLeaf) return resolve([])
//
const areaIds = []
formData.value.templateFree.forEach((item) => {
if (item.areaIds.length > 0) {
item.areaIds.forEach((areaId) => areaIds.push(areaId))
}
})
const length = node.data.length
if (length === 0) {
// id == 1
const data = cloneDeep(defaultArea)
const item = data[0]
if (areaIds.includes(item.id)) {
//item.disabled = true
}
resolve(data)
} else {
const id = node.data.id
const data = await getChildrenArea(id)
//
data.forEach((item) => {
if (areaIds.includes(item.id)) {
// TODO @
// TODO @jason
//item.disabled = true
}
})
resolve(data)
}
}
/** 添加计费区域 */ /** 添加计费区域 */
const addChargeArea = () => { const addChargeArea = () => {
const data = formData.value const data = formData.value
data.templateCharge.push({ data.charges.push({
areaIds: [], areaIds: [],
startCount: 1, startCount: 1,
startPrice: 1, startPrice: 1,
@ -408,13 +295,13 @@ const addChargeArea = () => {
/** 删除计费区域 */ /** 删除计费区域 */
const deleteChargeArea = (index) => { const deleteChargeArea = (index) => {
const data = formData.value const data = formData.value
data.templateCharge.splice(index, 1) data.charges.splice(index, 1)
} }
/** 添加包邮区域 */ /** 添加包邮区域 */
const addFreeArea = () => { const addFreeArea = () => {
const data = formData.value const data = formData.value
data.templateFree.push({ data.frees.push({
areaIds: [], areaIds: [],
freeCount: 1, freeCount: 1,
freePrice: 1 freePrice: 1
@ -424,7 +311,7 @@ const addFreeArea = () => {
/** 删除包邮区域 */ /** 删除包邮区域 */
const deleteFreeArea = (index) => { const deleteFreeArea = (index) => {
const data = formData.value const data = formData.value
data.templateFree.splice(index, 1) data.frees.splice(index, 1)
} }
/** 初始化 **/ /** 初始化 **/

View File

@ -51,14 +51,14 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="编号" prop="id" /> <el-table-column label="编号" min-width="60" prop="id" />
<el-table-column label="模板名称" prop="name" /> <el-table-column label="模板名称" min-width="100" prop="name" />
<el-table-column label="计费方式" prop="chargeMode" align="center"> <el-table-column label="计费方式" prop="chargeMode" min-width="100" align="center">
<template #default="scope"> <template #default="scope">
<dict-tag :type="DICT_TYPE.EXPRESS_CHARGE_MODE" :value="scope.row.chargeMode" /> <dict-tag :type="DICT_TYPE.EXPRESS_CHARGE_MODE" :value="scope.row.chargeMode" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="排序" prop="sort" /> <el-table-column label="排序" min-width="100" prop="sort" />
<el-table-column <el-table-column
label="创建时间" label="创建时间"
align="center" align="center"