客户编辑添加绑定套餐

This commit is contained in:
luojiaquan
2026-09-16 17:06:50 +08:00
parent b1ceae4776
commit 6fbb9049bf
9 changed files with 761 additions and 0 deletions
@@ -0,0 +1,36 @@
import request from '@/utils/request.js'
// 查询客户已绑定的套餐列表
export function listCustomerPriceSet(customerId) {
return request({
url: '/customersupplier/customerinfo/priceset/bind/list',
method: 'get',
params: { customerId }
})
}
// 查询可绑定的生效套餐选项
export function listPriceSetOption(query) {
return request({
url: '/customersupplier/customerinfo/priceset/option/list',
method: 'get',
params: query
})
}
// 保存客户套餐绑定(已绑定则更新/更换,未绑定则新增)
export function saveCustomerPriceSet(data) {
return request({
url: '/customersupplier/customerinfo/priceset/bind',
method: 'post',
data
})
}
// 解绑客户套餐
export function delCustomerPriceSet(customerPricesetIds) {
return request({
url: '/customersupplier/customerinfo/priceset/bind/' + customerPricesetIds,
method: 'delete'
})
}
@@ -186,6 +186,50 @@
</el-table>
</el-tab-pane>
<!-- ============ 绑定套餐 ============ -->
<el-tab-pane label="绑定套餐" name="priceSet">
<div class="pane-toolbar">
<el-button type="primary" plain icon="Plus" size="small" :disabled="isAdd" @click="openPriceSetDialog()">
{{ boundPriceSets.length ? '更换套餐' : '绑定套餐' }}
</el-button>
<span class="pane-tip">绑定后写入客户套餐关系表 prc_customer_price_set,一个客户仅可绑定一个价格套餐,仅「生效中」的套餐可绑定</span>
</div>
<el-table :data="boundPriceSets" border size="small" class="bound-table">
<el-table-column label="序号" type="index" width="55" align="center" />
<el-table-column label="套餐编码" prop="priceSetCode" width="120" show-overflow-tooltip />
<el-table-column label="套餐名称" prop="priceSetName" min-width="180" show-overflow-tooltip />
<el-table-column label="计价类型" width="90" align="center">
<template #default="{ row }">
<el-tag :type="row.setType === 'DISCOUNT' ? 'warning' : 'primary'" size="small">
{{ setTypeMap[row.setType] || row.setType || '-' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="套餐状态" width="90" align="center">
<template #default="{ row }">
<el-tag :type="priceSetStatusTagType[row.priceSetStatus] || 'info'" size="small">
{{ priceSetStatusMap[row.priceSetStatus] || '未知' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="优先级" prop="bindPriority" width="70" align="center" />
<el-table-column label="绑定生效" prop="prBegindate" width="110" align="center" />
<el-table-column label="绑定失效" width="100" align="center">
<template #default="{ row }">{{ row.prEnddate || '长期' }}</template>
</el-table-column>
<el-table-column label="备注" prop="priceSetNote" min-width="140" show-overflow-tooltip />
<el-table-column label="操作" width="120" align="center">
<template #default="{ row }">
<el-button link type="primary" size="small" @click="openPriceSetDialog(row)">更换</el-button>
<el-button link type="danger" size="small" @click="handleUnbindPriceSet(row)">解绑</el-button>
</template>
</el-table-column>
<template #empty>
<el-empty :description="isAdd ? '请先保存客户后再绑定套餐' : '暂未绑定套餐,点击上方「绑定套餐」'" :image-size="80" />
</template>
</el-table>
</el-tab-pane>
<!-- ============ 公司主体 ============ -->
<el-tab-pane label="公司主体" name="company">
<div class="pane-toolbar">
@@ -582,6 +626,75 @@
</div>
</template>
</el-dialog>
<!-- ====== 绑定套餐对话框 ====== -->
<el-dialog :title="priceSetDialogTitle" v-model="priceSetDialogVisible" width="560px" append-to-body>
<el-form ref="priceSetRef" :model="priceSetForm" :rules="priceSetRules" label-width="96px">
<el-form-item label="价格套餐" prop="priceSetId">
<el-select
v-model="priceSetForm.priceSetId"
filterable
placeholder="请选择生效中的套餐"
style="width: 100%;"
@change="onPriceSetChange"
>
<el-option
v-for="opt in priceSetOptions"
:key="opt.priceSetId"
:label="((opt.priceSetCode || '') + ' ' + opt.priceSetName).trim()"
:value="opt.priceSetId"
/>
</el-select>
</el-form-item>
<el-form-item v-if="selectedPriceSet" label="套餐信息">
<div class="ps-readonly">
<el-tag size="small" :type="selectedPriceSet.setType === 'DISCOUNT' ? 'warning' : 'primary'">
{{ setTypeMap[selectedPriceSet.setType] || selectedPriceSet.setType }}
</el-tag>
<span class="ps-readonly__range">
套餐有效期:{{ selectedPriceSet.effectiveDate || '-' }} 至 {{ selectedPriceSet.expireDate || '长期' }}
</span>
</div>
</el-form-item>
<el-form-item label="优先级" prop="bindPriority">
<el-input-number v-model="priceSetForm.bindPriority" :min="1" controls-position="right" style="width: 100%;" />
<div class="pane-tip">数字越小优先级越高,1 为最高</div>
</el-form-item>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item label="生效日期" prop="prBegindate">
<el-date-picker
v-model="priceSetForm.prBegindate"
type="date"
value-format="YYYY-MM-DD"
placeholder="选择日期"
style="width: 100%;"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="失效日期" prop="prEnddate">
<el-date-picker
v-model="priceSetForm.prEnddate"
type="date"
value-format="YYYY-MM-DD"
placeholder="长期有效"
style="width: 100%;"
/>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注" prop="priceSetNote">
<el-input v-model="priceSetForm.priceSetNote" type="textarea" :rows="2" maxlength="100" show-word-limit placeholder="绑定备注(选填)" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" :loading="priceSetSaving" @click="submitPriceSetForm">确 定</el-button>
<el-button @click="priceSetDialogVisible = false">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
@@ -590,6 +703,10 @@ import {
listCustomer, getCustomer, addCustomer, updateCustomer,
delCustomerCompany, delCustomerContact
} from '@/api/customersuppliermanagement/customerinfo/customer.js'
import {
listCustomerPriceSet, listPriceSetOption,
saveCustomerPriceSet, delCustomerPriceSet
} from '@/api/customersuppliermanagement/customerinfo/customerPriceSet.js'
import { getToken } from '@/utils/auth'
import axios from 'axios'
import { saveAs } from 'file-saver'
@@ -664,6 +781,99 @@ function removeProduct(productId) {
form.value.productIds = ids.join(',')
}
/* ---------------- 套餐绑定(prc_customer_price_set,一客户一套餐) ---------------- */
const setTypeMap = { FIXED: '固定价', DISCOUNT: '折扣' }
const priceSetStatusMap = { D: '草稿', A: '审核中', E: '生效', R: '驳回', S: '停用' }
const priceSetStatusTagType = { D: 'info', A: 'warning', E: 'success', R: 'danger', S: 'info' }
const boundPriceSets = ref([])
const priceSetOptions = ref([])
const priceSetDialogVisible = ref(false)
const priceSetDialogTitle = ref('')
const priceSetSaving = ref(false)
const priceSetRef = ref()
const priceSetForm = ref({})
const priceSetRules = {
priceSetId: [{ required: true, message: '请选择价格套餐', trigger: 'change' }],
bindPriority: [{ required: true, message: '优先级不能为空', trigger: 'blur' }],
prBegindate: [{ required: true, message: '绑定生效日期不能为空', trigger: 'change' }]
}
const selectedPriceSet = computed(() =>
priceSetOptions.value.find(o => o.priceSetId === priceSetForm.value.priceSetId)
)
/** 加载当前客户已绑定套餐 */
function loadBoundPriceSets() {
if (!form.value.customerId) {
boundPriceSets.value = []
return
}
listCustomerPriceSet(form.value.customerId).then(res => {
boundPriceSets.value = res.data || []
})
}
/** 加载可绑定的生效套餐(仅加载一次) */
function ensurePriceSetOptions() {
if (priceSetOptions.value.length) return
listPriceSetOption().then(res => {
priceSetOptions.value = res.data || []
})
}
/** 打开绑定/更换套餐弹窗:row 为空=新增绑定,有值=更换 */
function openPriceSetDialog(row) {
if (!form.value.customerId) {
proxy.$modal.msgWarning('请先保存客户后再绑定套餐')
return
}
ensurePriceSetOptions()
priceSetForm.value = row
? { ...row }
: { priceSetId: null, bindPriority: 1, prBegindate: null, prEnddate: null, priceSetNote: null }
priceSetDialogTitle.value = row || boundPriceSets.value.length ? '更换套餐' : '绑定套餐'
priceSetDialogVisible.value = true
nextTick(() => proxy.$refs['priceSetRef'] && proxy.$refs['priceSetRef'].clearValidate())
}
/** 选择套餐后,生效日期未填时默认带出套餐生效日期 */
function onPriceSetChange(priceSetId) {
const opt = priceSetOptions.value.find(o => o.priceSetId === priceSetId)
if (opt && !priceSetForm.value.prBegindate) {
priceSetForm.value.prBegindate = opt.effectiveDate || null
}
}
function submitPriceSetForm() {
proxy.$refs['priceSetRef'].validate(valid => {
if (!valid) return
if (priceSetForm.value.prEnddate && priceSetForm.value.prBegindate > priceSetForm.value.prEnddate) {
proxy.$modal.msgWarning('失效日期不能早于生效日期')
return
}
const payload = { ...priceSetForm.value, customerId: form.value.customerId }
priceSetSaving.value = true
saveCustomerPriceSet(payload).then(() => {
proxy.$modal.msgSuccess('保存成功')
priceSetDialogVisible.value = false
loadBoundPriceSets()
}).finally(() => {
priceSetSaving.value = false
})
})
}
function handleUnbindPriceSet(row) {
proxy.$modal.confirm(`确认解绑套餐「${row.priceSetName || row.priceSetCode || ''}」?解绑后该客户询价将不再命中此套餐。`)
.then(() => delCustomerPriceSet(row.customerPricesetId))
.then(() => {
proxy.$modal.msgSuccess('解绑成功')
loadBoundPriceSets()
}).catch(() => {})
}
/* ---------------- 用户冗余姓名 ---------------- */
function handleUserChange(uid, user, nameField) {
form.value[nameField] = user ? (user.nickName || user.userName || null) : null
@@ -976,6 +1186,7 @@ function loadDetail(id) {
form.value.attachmentList = form.value.attachmentList || []
form.value.companyList = form.value.companyList || []
form.value.contactList = form.value.contactList || []
loadBoundPriceSets()
})
}
@@ -1031,6 +1242,7 @@ function initByRoute() {
loadDetail(customerId.value).finally(() => { pageLoading.value = false })
} else {
form.value = buildEmptyForm()
boundPriceSets.value = []
}
}
@@ -1085,4 +1297,14 @@ onMounted(() => {
.bound-table {
margin-top: 4px;
}
.ps-readonly {
display: flex;
align-items: center;
gap: 10px;
color: #606266;
font-size: 13px;
&__range {
color: #909399;
}
}
</style>