fix:商品套餐添加固定价格
This commit is contained in:
@@ -195,6 +195,24 @@ export const enableProductPlan = (data) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**禁用套餐固定价格 */
|
||||||
|
export const disablePlanFixedPrice = (data) => {
|
||||||
|
return http2.post('/api/v1/admin/good/plan/disable_fixed_price', data,{
|
||||||
|
headers:{
|
||||||
|
'Content-Type':'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**启用套餐固定价格 */
|
||||||
|
export const enablePlanFixedPrice = (data) => {
|
||||||
|
return http2.post('/api/v1/admin/good/plan/enable_fixed_price', data,{
|
||||||
|
headers:{
|
||||||
|
'Content-Type':'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**---------------------------------- */
|
/**---------------------------------- */
|
||||||
/**商品分组标签管理 */
|
/**商品分组标签管理 */
|
||||||
|
|||||||
@@ -520,13 +520,15 @@
|
|||||||
:title="planFormType === 'add' ? '新增套餐' : '编辑套餐'"
|
:title="planFormType === 'add' ? '新增套餐' : '编辑套餐'"
|
||||||
width="700px"
|
width="700px"
|
||||||
append-to-body
|
append-to-body
|
||||||
|
class="plan-form-dialog"
|
||||||
>
|
>
|
||||||
<el-form
|
<div class="plan-form-content">
|
||||||
ref="planFormRef"
|
<el-form
|
||||||
:model="planForm"
|
ref="planFormRef"
|
||||||
:rules="planFormRules"
|
:model="planForm"
|
||||||
label-width="100px"
|
:rules="planFormRules"
|
||||||
>
|
label-width="100px"
|
||||||
|
>
|
||||||
<el-form-item label="套餐名称" prop="name">
|
<el-form-item label="套餐名称" prop="name">
|
||||||
<el-input v-model="planForm.name" placeholder="请输入套餐名称" />
|
<el-input v-model="planForm.name" placeholder="请输入套餐名称" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -665,6 +667,22 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="库存数量" prop="inventory">
|
<el-form-item label="库存数量" prop="inventory">
|
||||||
<el-input-number v-model="planForm.inventory" :min="0" style="width: 100%" placeholder="库存数量" />
|
<el-input-number v-model="planForm.inventory" :min="0" style="width: 100%" placeholder="库存数量" />
|
||||||
|
<div class="form-tip">0 表示没有库存</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="启用固定价格" prop="enable_fixed_price">
|
||||||
|
<el-switch
|
||||||
|
v-model="planForm.enable_fixed_price"
|
||||||
|
:active-value="true"
|
||||||
|
:inactive-value="false"
|
||||||
|
active-text="启用"
|
||||||
|
inactive-text="禁用"
|
||||||
|
:loading="fixedPriceLoading"
|
||||||
|
@change="handleFixedPriceChange"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">启用后套餐价格将使用固定价格,不再根据参数计算</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="固定价格(元)" prop="fixed_price" v-if="planForm.enable_fixed_price === true">
|
||||||
|
<el-input-number v-model="planForm.fixed_price" :min="0" :precision="2" :step="0.01" style="width: 100%" placeholder="请输入固定价格(元)" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="排序索引" prop="index">
|
<el-form-item label="排序索引" prop="index">
|
||||||
<el-input-number v-model="planForm.index" :min="0" style="width: 100%" />
|
<el-input-number v-model="planForm.index" :min="0" style="width: 100%" />
|
||||||
@@ -675,7 +693,8 @@
|
|||||||
<el-radio :value="true">禁用</el-radio>
|
<el-radio :value="true">禁用</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer">
|
<div class="dialog-footer">
|
||||||
<el-button @click="planFormDialogVisible = false">取消</el-button>
|
<el-button @click="planFormDialogVisible = false">取消</el-button>
|
||||||
@@ -793,7 +812,9 @@ import { getProductList, createProduct, updateProduct, deleteProduct, getProduct
|
|||||||
updateProductPlan,
|
updateProductPlan,
|
||||||
deleteProductPlan,
|
deleteProductPlan,
|
||||||
disableProductPlan,
|
disableProductPlan,
|
||||||
enableProductPlan
|
enableProductPlan,
|
||||||
|
disablePlanFixedPrice,
|
||||||
|
enablePlanFixedPrice
|
||||||
} from '@/api/admin/product'
|
} from '@/api/admin/product'
|
||||||
|
|
||||||
// 查询参数
|
// 查询参数
|
||||||
@@ -1603,6 +1624,7 @@ const currentPlanProductName = ref('')
|
|||||||
const planFormDialogVisible = ref(false)
|
const planFormDialogVisible = ref(false)
|
||||||
const planFormType = ref('add')
|
const planFormType = ref('add')
|
||||||
const planFormRef = ref(null)
|
const planFormRef = ref(null)
|
||||||
|
const fixedPriceLoading = ref(false) // 固定价格开关加载状态
|
||||||
const planForm = reactive({
|
const planForm = reactive({
|
||||||
plan_id: undefined,
|
plan_id: undefined,
|
||||||
name: '',
|
name: '',
|
||||||
@@ -1611,6 +1633,8 @@ const planForm = reactive({
|
|||||||
extra_arg_ids: '',
|
extra_arg_ids: '',
|
||||||
extra_arg_ids_array: [],
|
extra_arg_ids_array: [],
|
||||||
inventory: 0,
|
inventory: 0,
|
||||||
|
fixed_price: 0,
|
||||||
|
enable_fixed_price: false,
|
||||||
index: 0,
|
index: 0,
|
||||||
disable: false
|
disable: false
|
||||||
})
|
})
|
||||||
@@ -1876,10 +1900,15 @@ const initSelectedArgsFromJson = (argsJson, extraArgIds = []) => {
|
|||||||
// 处理额外参数(排除已在args中的参数)
|
// 处理额外参数(排除已在args中的参数)
|
||||||
if (extraArgIds && extraArgIds.length > 0) {
|
if (extraArgIds && extraArgIds.length > 0) {
|
||||||
selectedExtraArgIds.value = extraArgIds.filter(id => !argsParamIds.includes(id))
|
selectedExtraArgIds.value = extraArgIds.filter(id => !argsParamIds.includes(id))
|
||||||
|
console.log('initSelectedArgsFromJson - 额外参数已设置:', selectedExtraArgIds.value)
|
||||||
|
} else {
|
||||||
|
console.log('initSelectedArgsFromJson - 无额外参数或为空, extraArgIds:', extraArgIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据选择状态重新生成 JSON(确保初始状态就有 JSON 展示)
|
// 根据选择状态重新生成 JSON(确保初始状态就有 JSON 展示)
|
||||||
updateArgsJson()
|
updateArgsJson()
|
||||||
|
// 同步更新 planForm.extra_arg_ids
|
||||||
|
updateExtraArgIds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开套餐管理
|
// 打开套餐管理
|
||||||
@@ -1967,6 +1996,8 @@ const handleAddPlan = async () => {
|
|||||||
extra_arg_ids: '',
|
extra_arg_ids: '',
|
||||||
extra_arg_ids_array: [],
|
extra_arg_ids_array: [],
|
||||||
inventory: 0,
|
inventory: 0,
|
||||||
|
fixed_price: 0,
|
||||||
|
enable_fixed_price: false,
|
||||||
index: 0,
|
index: 0,
|
||||||
disable: false
|
disable: false
|
||||||
})
|
})
|
||||||
@@ -1990,16 +2021,28 @@ const handleEditPlan = async (row) => {
|
|||||||
if (res.data.code === 200) {
|
if (res.data.code === 200) {
|
||||||
const data = res.data.data
|
const data = res.data.data
|
||||||
|
|
||||||
// 处理 extra_arg_ids
|
// 处理 extra_arg_ids(兼容驼峰和下划线命名,以及 extraArgs 对象数组)
|
||||||
let extraArgIdsArray = []
|
let extraArgIdsArray = []
|
||||||
if (data.extraArgIds) {
|
const extraArgIdsRaw = data.extraArgIds || data.extra_arg_ids
|
||||||
if (Array.isArray(data.extraArgIds)) {
|
const extraArgsRaw = data.extraArgs || data.extra_args
|
||||||
extraArgIdsArray = data.extraArgIds
|
|
||||||
} else if (typeof data.extraArgIds === 'string') {
|
if (extraArgIdsRaw) {
|
||||||
extraArgIdsArray = data.extraArgIds.split(',').filter(Boolean).map(Number)
|
// 优先使用 extra_arg_ids 字段
|
||||||
|
if (Array.isArray(extraArgIdsRaw)) {
|
||||||
|
extraArgIdsArray = extraArgIdsRaw.map(Number)
|
||||||
|
} else if (typeof extraArgIdsRaw === 'string' && extraArgIdsRaw.trim()) {
|
||||||
|
extraArgIdsArray = extraArgIdsRaw.split(',').filter(Boolean).map(Number)
|
||||||
}
|
}
|
||||||
|
} else if (extraArgsRaw && Array.isArray(extraArgsRaw)) {
|
||||||
|
// 如果有 extraArgs 对象数组,从中提取参数ID
|
||||||
|
extraArgIdsArray = extraArgsRaw.map(arg => arg.id || arg.arg_id || arg.argId).filter(Boolean).map(Number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('编辑套餐 - 原始数据:', data)
|
||||||
|
console.log('编辑套餐 - extraArgIdsRaw:', extraArgIdsRaw)
|
||||||
|
console.log('编辑套餐 - extraArgsRaw:', extraArgsRaw)
|
||||||
|
console.log('编辑套餐 - extraArgIdsArray:', extraArgIdsArray)
|
||||||
|
|
||||||
Object.assign(planForm, {
|
Object.assign(planForm, {
|
||||||
plan_id: data.id,
|
plan_id: data.id,
|
||||||
name: data.name || '',
|
name: data.name || '',
|
||||||
@@ -2008,6 +2051,8 @@ const handleEditPlan = async (row) => {
|
|||||||
extra_arg_ids: extraArgIdsArray.join(','),
|
extra_arg_ids: extraArgIdsArray.join(','),
|
||||||
extra_arg_ids_array: extraArgIdsArray,
|
extra_arg_ids_array: extraArgIdsArray,
|
||||||
inventory: data.inventory || 0,
|
inventory: data.inventory || 0,
|
||||||
|
fixed_price: ((data.fixedPrice || data.fixed_price || 0) / 100).toFixed(2) * 1, // 分转元
|
||||||
|
enable_fixed_price: !!(data.enableFixedPrice || data.enable_fixed_price), // 转为布尔值
|
||||||
index: data.index || 0,
|
index: data.index || 0,
|
||||||
disable: data.disable || false
|
disable: data.disable || false
|
||||||
})
|
})
|
||||||
@@ -2054,21 +2099,71 @@ const handleTogglePlanStatus = async (row) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理固定价格开关变化(编辑模式下调用API)
|
||||||
|
const handleFixedPriceChange = async (value) => {
|
||||||
|
// 只有编辑模式下才调用API
|
||||||
|
if (planFormType.value !== 'edit' || !planForm.plan_id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fixedPriceLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
good_id: String(currentPlanProductId.value),
|
||||||
|
plan_id: String(planForm.plan_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
let res
|
||||||
|
if (value === true) {
|
||||||
|
res = await enablePlanFixedPrice(data)
|
||||||
|
} else {
|
||||||
|
res = await disablePlanFixedPrice(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.data.code === 200) {
|
||||||
|
ElMessage.success(value ? '已启用固定价格' : '已禁用固定价格')
|
||||||
|
} else {
|
||||||
|
// 恢复原值
|
||||||
|
planForm.enable_fixed_price = !value
|
||||||
|
ElMessage.error(res.data.message || '操作失败')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 恢复原值
|
||||||
|
planForm.enable_fixed_price = !value
|
||||||
|
console.error('切换固定价格状态失败:', error)
|
||||||
|
ElMessage.error('操作失败')
|
||||||
|
} finally {
|
||||||
|
fixedPriceLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 提交套餐表单
|
// 提交套餐表单
|
||||||
const submitPlanForm = () => {
|
const submitPlanForm = () => {
|
||||||
planFormRef.value?.validate(async (valid) => {
|
planFormRef.value?.validate(async (valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
try {
|
try {
|
||||||
|
// 确保 extra_arg_ids 是最新的
|
||||||
|
const extraArgIdsStr = selectedExtraArgIds.value.join(',')
|
||||||
|
|
||||||
const submitData = {
|
const submitData = {
|
||||||
good_id: String(currentPlanProductId.value),
|
good_id: String(currentPlanProductId.value),
|
||||||
name: planForm.name,
|
name: planForm.name,
|
||||||
note: planForm.note || '',
|
note: planForm.note || '',
|
||||||
args: planForm.args || '',
|
args: planForm.args || '',
|
||||||
extra_arg_ids: planForm.extra_arg_ids || '',
|
extra_arg_ids: extraArgIdsStr || planForm.extra_arg_ids || '',
|
||||||
inventory: Number(planForm.inventory) || 0,
|
inventory: Number(planForm.inventory) || 0,
|
||||||
|
fixed_price: Math.round(Number(planForm.fixed_price) * 100) || 0, // 元转分
|
||||||
index: Number(planForm.index) || 0
|
index: Number(planForm.index) || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 只有创建时才传递 enable_fixed_price
|
||||||
|
if (planFormType.value === 'add') {
|
||||||
|
submitData.enable_fixed_price = planForm.enable_fixed_price === true
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('提交套餐数据:', submitData)
|
||||||
|
console.log('selectedExtraArgIds:', selectedExtraArgIds.value)
|
||||||
|
|
||||||
let res
|
let res
|
||||||
if (planFormType.value === 'add') {
|
if (planFormType.value === 'add') {
|
||||||
res = await createProductPlan(submitData)
|
res = await createProductPlan(submitData)
|
||||||
@@ -2356,6 +2451,37 @@ const submitPlanForm = () => {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 套餐表单弹窗样式 */
|
||||||
|
.plan-form-content {
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 8px;
|
||||||
|
margin-right: -8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 隐形滚动条样式 */
|
||||||
|
.plan-form-content::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plan-form-content::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plan-form-content::-webkit-scrollbar-thumb {
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 3px;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plan-form-content:hover::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgba(144, 147, 153, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.plan-form-content::-webkit-scrollbar-thumb:hover {
|
||||||
|
background-color: rgba(144, 147, 153, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
/* 参数配置选择器样式 */
|
/* 参数配置选择器样式 */
|
||||||
.args-config-container {
|
.args-config-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user