修改附加费

This commit is contained in:
wuweihua
2026-09-22 10:40:13 +08:00
parent 465b3e6b6b
commit c860d1666d
8 changed files with 192 additions and 46 deletions
@@ -35,11 +35,6 @@
<dict-tag :options="bms_tax_mode" :value="row.taxMode" />
</template>
</el-table-column> -->
<el-table-column :label="colSurcharge" width="110" align="center">
<template #default="{ row }">
<surcharge-count-cell :list="productSurcharges(row)" @click="openSurcharge(row)" />
</template>
</el-table-column>
<el-table-column :label="colAction" width="220" align="center" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openPrice(row)">编辑价格</el-button>
@@ -76,6 +71,7 @@
:product-name="editName"
:rows="editRows"
@row-change="onRowPriceChange"
@surcharge-change="onRowSurchargeChange"
@pick-surcharge="openSurchargeFromDrawer"
/>
</el-card>
@@ -83,7 +79,6 @@
<script setup name="StepDetails">
import PriceEditDrawer from './PriceEditDrawer.vue'
import SurchargeCountCell from './SurchargeCountCell.vue'
import SurchargePickerDialog from './SurchargePickerDialog.vue'
import { useDetailCascade } from '../../composables/usePriceSetRefData'
import {
@@ -95,7 +90,7 @@ import {
surchargeAppliesToRow,
toDetailPayload
} from '../../utils/priceSet'
import { updateSetDetail, delSetDetail } from '@/api/price/set'
import { updateSetDetail, updateSetDetailSurchargeAsync, delSetDetail } from '@/api/price/set'
const props = defineProps({
details: { type: Array, required: true },
@@ -120,7 +115,6 @@ const colLevel = '时效等级'
const colCargo = '走货属性'
const colRegion = '目的区域'
// const colTax = '税模式'
const colSurcharge = '附加费'
const colAction = '操作'
const colDiscount = '产品折扣'
@@ -181,21 +175,6 @@ const pulling = ref(false)
function noop() {}
/** 该产品所有明细行附加费的并集(按 scId 去重),列表列展示用 */
function productSurcharges(row) {
const seen = new Set()
const list = []
;((row && row.rows) || []).forEach(r => {
(r.surcharges || []).forEach(s => {
const key = s && s.scId != null ? String(s.scId) : (s && s.scName)
if (!key || seen.has(key)) return
seen.add(key)
list.push(s)
})
})
return list
}
/** enter step 3: pull all library products + country prices (skip already added) */
async function pullAllFromLibrary(opts = {}) {
const silent = !!opts.silent
@@ -320,6 +299,17 @@ async function persistDetail(row, withSurcharge) {
await updateSetDetail(payload)
}
/** drawer hover remove surcharge -> write snapshot for this row */
async function onRowSurchargeChange(row) {
if (!row || !row.psdId) return
try {
await persistDetail(row, true)
proxy.$modal.msgSuccess('附加费已移除')
} catch (e) {
proxy.$modal.msgError((e && e.message) ? e.message : '附加费移除失败')
}
}
/** drawer field change -> immediate DB update */
async function onRowPriceChange(row) {
if (!row || !row.psdId) return
@@ -470,17 +460,25 @@ function onSurchargeConfirm(picked) {
proxy.$modal.msgWarning('已勾选但未生效:这些附加费配置了适用国家/重量段,与当前明细行不匹配')
return
}
if (skipped > 0) {
Promise.all(targets.filter(r => r.psdId).map(r => persistDetail(r, true))).finally(() => {
proxy.$modal.msgWarning(`已纳入 ${applied} 项附加费${scopeText};${skipped} 项因适用国家不匹配被跳过(已写库)`)
})
const okText = ids.size
? (skipped > 0
? `已纳入 ${applied} 项附加费${scopeText};${skipped} 项因适用国家不匹配被跳过`
: `已纳入 ${ids.size} 项附加费${scopeText}`)
: `已清空附加费${scopeText}`
const payload = targets.filter(r => r.psdId).map(r => toDetailPayload(r)).map(p => {
p.priceSetId = props.priceSetId
return p
})
scVisible.value = false
if (!payload.length) {
proxy.$modal.msgSuccess(okText)
return
}
const okText = ids.size ? `已纳入 ${ids.size} 项附加费${scopeText}` : `已清空附加费${scopeText}`
Promise.all(targets.filter(r => r.psdId).map(r => persistDetail(r, true))).then(() => {
proxy.$modal.msgSuccess(okText + ',正在后台写入…')
updateSetDetailSurchargeAsync(payload).then(() => {
proxy.$modal.msgSuccess(okText + ',已写入数据库')
}).catch(() => {
proxy.$modal.msgSuccess(okText)
}).catch(e => {
proxy.$modal.msgError((e && e.message) ? e.message : '附加费后台写入失败')
})
}