提交价格功能绑定
This commit is contained in:
@@ -126,21 +126,44 @@
|
||||
|
||||
<el-dialog :title="detailTitle" v-model="detailOpen" width="560px" append-to-body>
|
||||
<el-form ref="detailFormRef" :model="detailForm" :rules="detailRules" label-width="120px">
|
||||
<el-form-item label="产品代码" prop="productCode">
|
||||
<el-input v-model="detailForm.productCode" maxlength="10" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品名称" prop="productName">
|
||||
<el-input v-model="detailForm.productName" maxlength="50" />
|
||||
<el-form-item label="产品" prop="productCode">
|
||||
<el-select
|
||||
v-model="detailForm.productCode"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择产品"
|
||||
style="width: 100%"
|
||||
@change="onDetailProductChange"
|
||||
>
|
||||
<el-option v-for="p in productOptions" :key="p.value" :label="p.label" :value="p.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<template v-if="set.setType === 'FIXED'">
|
||||
<el-form-item label="国家代码" prop="countryCode">
|
||||
<el-input v-model="detailForm.countryCode" maxlength="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="国家名称" prop="countryName">
|
||||
<el-input v-model="detailForm.countryName" maxlength="50" />
|
||||
<el-form-item label="国家" prop="countryCode">
|
||||
<el-select
|
||||
v-model="detailForm._countryKey"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择国家"
|
||||
style="width: 100%"
|
||||
:disabled="!detailForm.productCode"
|
||||
@change="onDetailCountryChange"
|
||||
>
|
||||
<el-option v-for="c in detailCountryOptions" :key="c.key" :label="c.label" :value="c.key" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="重量段" prop="weightLabel">
|
||||
<el-input v-model="detailForm.weightLabel" maxlength="50" />
|
||||
<el-select
|
||||
v-model="detailForm.weightLabel"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择重量段"
|
||||
style="width: 100%"
|
||||
:disabled="!detailForm._countryKey"
|
||||
@change="onDetailWeightChange"
|
||||
>
|
||||
<el-option v-for="w in detailWeightOptions" :key="w.value" :label="w.label" :value="w.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="运费单价" prop="fvValue">
|
||||
<el-input-number v-model="detailForm.fvValue" :min="0" :precision="4" controls-position="right" style="width: 100%" />
|
||||
@@ -194,19 +217,22 @@ import {
|
||||
addSetDetail, updateSetDetail, delSetDetail,
|
||||
addSetCustomer, updateSetCustomer, delSetCustomer
|
||||
} from '@/api/price/set'
|
||||
import { listProduct, listProductCountries } from '@/api/price/product'
|
||||
import { parseTime } from '@/utils/ruoyi'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const set = ref({})
|
||||
const productOptions = ref([])
|
||||
const countryCache = reactive({})
|
||||
|
||||
const detailOpen = ref(false)
|
||||
const detailTitle = ref('')
|
||||
const detailFormRef = ref()
|
||||
const detailForm = ref({})
|
||||
const detailRules = {
|
||||
productCode: [{ required: true, message: '产品代码不能为空', trigger: 'blur' }]
|
||||
productCode: [{ required: true, message: '请选择产品', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const customerOpen = ref(false)
|
||||
@@ -218,6 +244,113 @@ const customerRules = {
|
||||
prBegindate: [{ required: true, message: '生效日期不能为空', trigger: 'change' }]
|
||||
}
|
||||
|
||||
function trimNum(v) {
|
||||
if (v == null || v === '') return ''
|
||||
const n = Number(v)
|
||||
if (Number.isNaN(n)) return String(v)
|
||||
return String(parseFloat(n.toFixed(6)))
|
||||
}
|
||||
|
||||
function formatWeightLabel(min, max) {
|
||||
return `${trimNum(min)}≤W≤${trimNum(max)}`
|
||||
}
|
||||
|
||||
function countryKeyOf(row) {
|
||||
if (!row) return ''
|
||||
if (row.countryCode) return row.countryCode
|
||||
if (row.countryName) return 'N:' + row.countryName
|
||||
return ''
|
||||
}
|
||||
|
||||
function matchCountry(detail, item) {
|
||||
if (detail.countryCode && item.countryCode) return detail.countryCode === item.countryCode
|
||||
return detail.countryName && item.countryName === detail.countryName
|
||||
}
|
||||
|
||||
function ensureCountries(productCode) {
|
||||
if (!productCode) return Promise.resolve([])
|
||||
if (countryCache[productCode]) return Promise.resolve(countryCache[productCode])
|
||||
return listProductCountries(productCode).then(res => {
|
||||
const rows = res.data || []
|
||||
countryCache[productCode] = rows
|
||||
return rows
|
||||
})
|
||||
}
|
||||
|
||||
const detailCountryOptions = computed(() => {
|
||||
const rows = countryCache[detailForm.value.productCode] || []
|
||||
const map = new Map()
|
||||
rows.forEach(item => {
|
||||
const key = countryKeyOf(item)
|
||||
if (!key || map.has(key)) return
|
||||
map.set(key, {
|
||||
key,
|
||||
code: item.countryCode || undefined,
|
||||
name: item.countryName,
|
||||
label: item.countryCode ? `${item.countryName} ${item.countryCode}` : item.countryName
|
||||
})
|
||||
})
|
||||
return [...map.values()]
|
||||
})
|
||||
|
||||
const detailWeightOptions = computed(() => {
|
||||
const form = detailForm.value
|
||||
const rows = (countryCache[form.productCode] || []).filter(item => matchCountry(form, item))
|
||||
const map = new Map()
|
||||
rows.forEach(item => {
|
||||
if (item.weightMin == null && item.weightMax == null) return
|
||||
const value = formatWeightLabel(item.weightMin, item.weightMax)
|
||||
if (map.has(value)) return
|
||||
map.set(value, {
|
||||
value,
|
||||
label: value,
|
||||
freightPrice: item.freightPrice,
|
||||
registrationFee: item.registrationFee
|
||||
})
|
||||
})
|
||||
return [...map.values()]
|
||||
})
|
||||
|
||||
function loadProducts() {
|
||||
listProduct({ status: '0', pageNum: 1, pageSize: 1000 }).then(res => {
|
||||
productOptions.value = (res.rows || []).map(p => ({
|
||||
value: p.productCode,
|
||||
label: `${p.productCode} ${p.productName || ''}`.trim(),
|
||||
name: p.productName
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
function onDetailProductChange() {
|
||||
const found = productOptions.value.find(p => p.value === detailForm.value.productCode)
|
||||
detailForm.value.productName = found ? found.name : detailForm.value.productCode
|
||||
detailForm.value.countryCode = undefined
|
||||
detailForm.value.countryName = undefined
|
||||
detailForm.value._countryKey = undefined
|
||||
detailForm.value.weightLabel = undefined
|
||||
detailForm.value.fvValue = undefined
|
||||
detailForm.value.fvRegistrationFee = undefined
|
||||
if (detailForm.value.productCode && set.value.setType === 'FIXED') {
|
||||
ensureCountries(detailForm.value.productCode)
|
||||
}
|
||||
}
|
||||
|
||||
function onDetailCountryChange() {
|
||||
const opt = detailCountryOptions.value.find(c => c.key === detailForm.value._countryKey)
|
||||
detailForm.value.countryCode = opt ? opt.code : undefined
|
||||
detailForm.value.countryName = opt ? opt.name : undefined
|
||||
detailForm.value.weightLabel = undefined
|
||||
detailForm.value.fvValue = undefined
|
||||
detailForm.value.fvRegistrationFee = undefined
|
||||
}
|
||||
|
||||
function onDetailWeightChange() {
|
||||
const opt = detailWeightOptions.value.find(w => w.value === detailForm.value.weightLabel)
|
||||
if (!opt) return
|
||||
if (opt.freightPrice != null) detailForm.value.fvValue = Number(opt.freightPrice)
|
||||
if (opt.registrationFee != null) detailForm.value.fvRegistrationFee = Number(opt.registrationFee)
|
||||
}
|
||||
|
||||
const childEditable = computed(() => ['D', 'R', 'E'].includes(set.value.status))
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
@@ -296,12 +429,16 @@ function onCopy() {
|
||||
}
|
||||
|
||||
function openDetailDialog(row) {
|
||||
detailForm.value = row ? { ...row } : {
|
||||
detailForm.value = row ? {
|
||||
...row,
|
||||
_countryKey: countryKeyOf(row)
|
||||
} : {
|
||||
priceSetId: set.value.priceSetId,
|
||||
productCode: undefined,
|
||||
productName: undefined,
|
||||
countryCode: undefined,
|
||||
countryName: undefined,
|
||||
_countryKey: undefined,
|
||||
weightLabel: undefined,
|
||||
fvValue: undefined,
|
||||
fvRegistrationFee: undefined,
|
||||
@@ -309,12 +446,19 @@ function openDetailDialog(row) {
|
||||
}
|
||||
detailTitle.value = row ? '编辑明细' : '添加明细'
|
||||
detailOpen.value = true
|
||||
if (detailForm.value.productCode && set.value.setType === 'FIXED') {
|
||||
ensureCountries(detailForm.value.productCode)
|
||||
}
|
||||
}
|
||||
|
||||
function submitDetail() {
|
||||
proxy.$refs['detailFormRef'].validate(valid => {
|
||||
if (!valid) return
|
||||
const payload = { ...detailForm.value, priceSetId: set.value.priceSetId }
|
||||
const payload = {
|
||||
...detailForm.value,
|
||||
priceSetId: set.value.priceSetId
|
||||
}
|
||||
delete payload._countryKey
|
||||
const req = payload.psdId ? updateSetDetail(payload) : addSetDetail(payload)
|
||||
req.then(() => {
|
||||
proxy.$modal.msgSuccess('保存成功')
|
||||
@@ -369,6 +513,7 @@ function removeCustomer(row) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadProducts()
|
||||
load()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user