Files
BMS/bms-front/src/views/price/set/detail.vue
T
2026-09-08 10:51:20 +08:00

587 lines
22 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="app-container" v-loading="loading">
<div class="detail-header">
<h2>{{ set.priceSetCode || '-' }} · {{ set.priceSetName || '套餐详情' }}</h2>
<div class="header-actions">
<el-tag :type="statusTag" size="large">{{ statusLabel }}</el-tag>
<el-tag :type="set.setType === 'FIXED' ? 'warning' : 'primary'" size="large" effect="plain">
{{ set.setType === 'FIXED' ? 'FIXED 固定价' : 'DISCOUNT 折扣' }}
</el-tag>
<el-button @click="goList">返回列表</el-button>
<el-button v-if="set.status === 'D' || set.status === 'R'" type="primary" @click="goEdit" v-hasPermi="['price:set:edit']">继续配置</el-button>
<el-button v-if="set.status === 'D' || set.status === 'R'" type="primary" @click="onSubmit" v-hasPermi="['price:set:audit']">提交审核</el-button>
<el-button v-if="set.status === 'A'" type="success" @click="onApprove" v-hasPermi="['price:set:audit']">审批生效</el-button>
<el-button v-if="set.status === 'A'" type="warning" @click="onReject" v-hasPermi="['price:set:audit']">驳回</el-button>
<el-button v-if="set.status === 'E' && !set.expired" type="danger" @click="onDisable" v-hasPermi="['price:set:audit']">停用</el-button>
<el-button v-if="set.status === 'S'" @click="onCopy" v-hasPermi="['price:set:add']">复用新建</el-button>
</div>
</div>
<el-row :gutter="16">
<el-col :span="24">
<el-card shadow="never">
<template #header>基本信息</template>
<el-descriptions :column="2" border>
<el-descriptions-item label="套餐ID">{{ set.priceSetCode }}</el-descriptions-item>
<el-descriptions-item label="套餐名称">{{ set.priceSetName }}</el-descriptions-item>
<el-descriptions-item label="计价类型">
{{ set.setType === 'FIXED' ? 'FIXED 固定价' : 'DISCOUNT 折扣' }}
</el-descriptions-item>
<el-descriptions-item label="默认折扣">
<span v-if="set.setType === 'DISCOUNT'">{{ set.defaultDiscount }}%</span>
<el-tag v-else type="info" size="small">不适用(FIXED)</el-tag>
</el-descriptions-item>
<el-descriptions-item label="状态">{{ statusLabel }}</el-descriptions-item>
<el-descriptions-item label="生效日期">
{{ formatDate(set.effectiveDate) }} ~ {{ set.expireDate ? formatDate(set.expireDate) : '长期' }}
</el-descriptions-item>
<el-descriptions-item label="创建人">{{ set.createBy || '-' }}</el-descriptions-item>
<el-descriptions-item label="创建时间">{{ set.createTime || '-' }}</el-descriptions-item>
<el-descriptions-item label="最后更新" :span="2">{{ set.updateTime || '-' }} {{ set.updateBy ? '(' + set.updateBy + ')' : '' }}</el-descriptions-item>
<el-descriptions-item label="说明" :span="2">{{ set.priceSetNote || '-' }}</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
</el-row>
<el-card shadow="never" class="mt16">
<template #header>
<div class="card-head">
<span>套餐明细</span>
<el-button
v-if="childEditable"
type="primary"
size="small"
icon="Plus"
@click="openDetailDialog()"
v-hasPermi="['price:set:edit']"
>添加明细</el-button>
</div>
</template>
<el-table :data="set.details || []" border empty-text="暂无明细">
<el-table-column label="明细ID" prop="psdId" width="90" />
<el-table-column label="产品" min-width="130">
<template #default="{ row }">{{ row.productCode }} {{ row.productName || '' }}</template>
</el-table-column>
<el-table-column v-if="set.setType === 'FIXED'" label="国家" min-width="110">
<template #default="{ row }">{{ row.countryName || row.countryCode || '-' }}</template>
</el-table-column>
<el-table-column v-if="set.setType === 'FIXED'" label="重量段" prop="weightLabel" min-width="120" />
<el-table-column v-if="set.setType === 'FIXED'" label="运费单价" min-width="120">
<template #default="{ row }"><span class="hl">{{ row.fvValue }} RMB/KG</span></template>
</el-table-column>
<el-table-column v-if="set.setType === 'FIXED'" label="挂号费" min-width="120">
<template #default="{ row }"><span class="reg">{{ row.fvRegistrationFee }} RMB/票</span></template>
</el-table-column>
<el-table-column v-if="set.setType === 'DISCOUNT'" label="产品折扣" min-width="110">
<template #default="{ row }">{{ row.discountValue != null ? row.discountValue + '%' : '默认折扣' }}</template>
</el-table-column>
<el-table-column label="取值方式" min-width="110" align="center">
<template #default="{ row }">{{ roundModeLabel(row.roundMode) }}</template>
</el-table-column>
<!-- <el-table-column label="关联 pr_id" prop="prId" width="110">
<template #default="{ row }">{{ row.prId || '-' }}</template>
</el-table-column> -->
<el-table-column v-if="childEditable" label="操作" width="140" align="center">
<template #default="{ row }">
<el-button link type="primary" @click="openDetailDialog(row)" v-hasPermi="['price:set:edit']">编辑</el-button>
<el-button link type="danger" @click="removeDetail(row)" v-hasPermi="['price:set:edit']">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<el-card shadow="never" class="mt16">
<template #header>
<div class="card-head">
<span>绑定客户</span>
<el-button
v-if="childEditable"
type="primary"
size="small"
icon="Plus"
@click="openCustomerDialog()"
v-hasPermi="['price:set:edit']"
>添加客户</el-button>
</div>
</template>
<el-table :data="set.customers || []" border empty-text="暂未绑定客户">
<el-table-column label="绑定ID" prop="customerPricesetId" width="100" />
<el-table-column label="客户ID" prop="customerId" width="110" />
<el-table-column label="客户名称" prop="customerName" min-width="140" />
<el-table-column label="优先级" width="110">
<template #default="{ row }">{{ row.bindPriority }}{{ row.bindPriority === 1 ? '(最高)' : '' }}</template>
</el-table-column>
<el-table-column label="生效日期" min-width="200">
<template #default="{ row }">
{{ formatDate(row.prBegindate) }} ~ {{ row.prEnddate ? formatDate(row.prEnddate) : '长期' }}
</template>
</el-table-column>
<el-table-column v-if="childEditable" label="操作" width="140" align="center">
<template #default="{ row }">
<el-button link type="primary" @click="openCustomerDialog(row)" v-hasPermi="['price:set:edit']">编辑</el-button>
<el-button link type="danger" @click="removeCustomer(row)" v-hasPermi="['price:set:edit']">解绑</el-button>
</template>
</el-table-column>
</el-table>
<div class="rel-hint">优先级数字越小越优先;同一客户绑定多个套餐时,按优先级 → 生效日期依次命中。</div>
</el-card>
<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-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-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-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%" />
</el-form-item>
<el-form-item label="挂号费" prop="fvRegistrationFee">
<el-input-number v-model="detailForm.fvRegistrationFee" :min="0" :precision="2" controls-position="right" style="width: 100%" />
</el-form-item>
</template>
<el-form-item v-else label="产品折扣%" prop="discountValue">
<el-input-number v-model="detailForm.discountValue" :min="1" :max="99" controls-position="right" style="width: 100%" />
</el-form-item>
<el-form-item label="取值方式" prop="roundMode">
<el-select v-model="detailForm.roundMode" placeholder="请选择" style="width: 100%">
<el-option v-for="d in bms_round_mode" :key="d.value" :label="d.label" :value="d.value" />
</el-select>
</el-form-item>
<!-- <el-form-item label="关联 pr_id" prop="prId">
<el-input v-model="detailForm.prId" placeholder="可选" />
</el-form-item> -->
</el-form>
<template #footer>
<el-button type="primary" @click="submitDetail">确 定</el-button>
<el-button @click="detailOpen = false">取 消</el-button>
</template>
</el-dialog>
<el-dialog :title="customerTitle" v-model="customerOpen" width="520px" append-to-body>
<el-form ref="customerFormRef" :model="customerForm" :rules="customerRules" label-width="110px">
<el-form-item label="客户ID" prop="customerId">
<el-input v-model="customerForm.customerId" />
</el-form-item>
<el-form-item label="客户名称" prop="customerName">
<el-input v-model="customerForm.customerName" maxlength="100" />
</el-form-item>
<el-form-item label="优先级" prop="bindPriority">
<el-input-number v-model="customerForm.bindPriority" :min="1" controls-position="right" />
</el-form-item>
<el-form-item label="生效日期" prop="prBegindate">
<el-date-picker v-model="customerForm.prBegindate" type="date" value-format="YYYY-MM-DD" style="width: 100%" />
</el-form-item>
<el-form-item label="失效日期" prop="prEnddate">
<el-date-picker v-model="customerForm.prEnddate" type="date" value-format="YYYY-MM-DD" style="width: 100%" />
</el-form-item>
</el-form>
<template #footer>
<el-button type="primary" @click="submitCustomer">确 定</el-button>
<el-button @click="customerOpen = false">取 消</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup name="PriceSetDetail">
import {
getPriceSet, submitPriceSet, approvePriceSet, rejectPriceSet, disablePriceSet, copyPriceSet,
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 { bms_round_mode } = useDict('bms_round_mode')
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: 'change' }],
roundMode: [{ required: true, message: '请选择取值方式', trigger: 'change' }]
}
const customerOpen = ref(false)
const customerTitle = ref('')
const customerFormRef = ref()
const customerForm = ref({})
const customerRules = {
customerId: [{ required: true, message: '客户ID不能为空', trigger: 'blur' }],
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 || []).filter(item => !item.expireDate)
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,
detailId: item.detailId,
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.productCountryId = 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.productCountryId = undefined
detailForm.value.fvValue = undefined
detailForm.value.fvRegistrationFee = undefined
}
function onDetailWeightChange() {
const opt = detailWeightOptions.value.find(w => w.value === detailForm.value.weightLabel)
if (!opt) {
detailForm.value.productCountryId = undefined
return
}
detailForm.value.productCountryId = opt.detailId
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))
function roundModeLabel(mode) {
const hit = (bms_round_mode.value || []).find(d => d.value === mode)
return hit ? hit.label : (mode || '四舍五入')
}
const statusLabel = computed(() => {
if (set.value.expired) return '已过期'
const map = { D: '草稿', A: '审核中', E: '生效中', R: '驳回', S: '已停用' }
return map[set.value.status] || set.value.status || '-'
})
const statusTag = computed(() => {
if (set.value.expired) return 'danger'
const map = { D: 'warning', A: 'primary', E: 'success', R: 'danger', S: 'info' }
return map[set.value.status] || 'info'
})
function formatDate(val) {
return val ? parseTime(val, '{y}-{m}-{d}') : ''
}
function load() {
const id = route.query.priceSetId
if (!id) return
loading.value = true
getPriceSet(id).then(res => {
set.value = res.data || {}
}).finally(() => {
loading.value = false
})
}
function goList() {
const obj = { path: '/customer/set' }
if (proxy.$tab) {
proxy.$tab.closeOpenPage(obj)
} else {
proxy.$router.push(obj)
}
}
function goEdit() {
proxy.$router.push({ path: '/customer/setCreate', query: { priceSetId: set.value.priceSetId } })
}
function onSubmit() {
proxy.$modal.confirm('确认提交审核?').then(() => submitPriceSet(set.value.priceSetId)).then(() => {
proxy.$modal.msgSuccess('已提交审核')
load()
}).catch(() => {})
}
function onApprove() {
proxy.$modal.confirm('确认审批生效?').then(() => approvePriceSet(set.value.priceSetId)).then(() => {
proxy.$modal.msgSuccess('套餐已生效')
load()
}).catch(() => {})
}
function onReject() {
proxy.$modal.confirm('确认驳回该套餐?').then(() => rejectPriceSet(set.value.priceSetId)).then(() => {
proxy.$modal.msgSuccess('已驳回')
load()
}).catch(() => {})
}
function onDisable() {
proxy.$modal.confirm('停用后不再参与计费命中,确认停用?').then(() => disablePriceSet(set.value.priceSetId)).then(() => {
proxy.$modal.msgSuccess('已停用')
load()
}).catch(() => {})
}
function onCopy() {
copyPriceSet(set.value.priceSetId).then(res => {
proxy.$modal.msgSuccess('已复制为草稿')
proxy.$router.push({ path: '/customer/setCreate', query: { priceSetId: res.data } })
})
}
function openDetailDialog(row) {
detailForm.value = row ? {
...row,
roundMode: row.roundMode || 'HALF_UP',
_countryKey: countryKeyOf(row)
} : {
priceSetId: set.value.priceSetId,
productCode: undefined,
productName: undefined,
countryCode: undefined,
countryName: undefined,
_countryKey: undefined,
weightLabel: undefined,
productCountryId: undefined,
fvValue: undefined,
fvRegistrationFee: undefined,
discountValue: undefined,
roundMode: 'HALF_UP'
}
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
}
delete payload._countryKey
const req = payload.psdId ? updateSetDetail(payload) : addSetDetail(payload)
req.then(() => {
proxy.$modal.msgSuccess('保存成功')
detailOpen.value = false
load()
})
})
}
function removeDetail(row) {
proxy.$modal.confirm('确认删除该明细?').then(() => delSetDetail(row.psdId)).then(() => {
proxy.$modal.msgSuccess('已删除')
load()
}).catch(() => {})
}
function openCustomerDialog(row) {
customerForm.value = row ? { ...row } : {
priceSetId: set.value.priceSetId,
customerId: undefined,
customerName: '',
bindPriority: 1,
prBegindate: set.value.effectiveDate,
prEnddate: set.value.expireDate
}
customerTitle.value = row ? '编辑客户绑定' : '添加客户'
customerOpen.value = true
}
function submitCustomer() {
proxy.$refs['customerFormRef'].validate(valid => {
if (!valid) return
const payload = {
...customerForm.value,
priceSetId: set.value.priceSetId,
customerId: Number(customerForm.value.customerId)
}
const req = payload.customerPricesetId ? updateSetCustomer(payload) : addSetCustomer(payload)
req.then(() => {
proxy.$modal.msgSuccess('保存成功')
customerOpen.value = false
load()
})
})
}
function removeCustomer(row) {
proxy.$modal.confirm('确认解绑该客户?').then(() => delSetCustomer(row.customerPricesetId)).then(() => {
proxy.$modal.msgSuccess('已解绑')
load()
}).catch(() => {})
}
onMounted(() => {
loadProducts()
load()
})
</script>
<style scoped>
.detail-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
gap: 12px;
flex-wrap: wrap;
}
.detail-header h2 {
margin: 0;
font-size: 18px;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.mt16 {
margin-top: 16px;
}
.card-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.rel-hint {
margin-top: 10px;
font-size: 12px;
color: #909399;
}
.hl {
color: #1890ff;
font-weight: 600;
}
.reg {
color: #d48806;
font-weight: 600;
}
</style>