新增产品和附加费删除标记,优化版本编辑逻辑

This commit is contained in:
wuweihua
2026-11-16 14:54:19 +08:00
parent 4503424cf0
commit 215effe036
10 changed files with 418 additions and 166 deletions
@@ -107,4 +107,7 @@ public class LblProduct extends BaseEntity
/** 邮编→分区(保存时同步到 prc_zone,不落产品子表) */ /** 邮编→分区(保存时同步到 prc_zone,不落产品子表) */
private Map<String, List<String>> zonePostcodes; private Map<String, List<String>> zonePostcodes;
/** 编辑保存删除标记(不落库) */
private Boolean deleted;
} }
@@ -59,4 +59,7 @@ public class LblSurcharge
private BigDecimal weightMax; private BigDecimal weightMax;
private Integer sortNo; private Integer sortNo;
/** 编辑保存删除标记(不落库) */
private Boolean deleted;
} }
@@ -57,4 +57,7 @@ public class LblWeightBand
private String extraPriceUnit; private String extraPriceUnit;
private Integer sortNo; private Integer sortNo;
/** 编辑保存删除标记(不落库) */
private Boolean deleted;
} }
@@ -310,6 +310,8 @@ public final class LblBandNormalizer
private static LblWeightBand copyBand(LblWeightBand src) private static LblWeightBand copyBand(LblWeightBand src)
{ {
LblWeightBand b = new LblWeightBand(); LblWeightBand b = new LblWeightBand();
b.setBandId(src.getBandId());
b.setDeleted(src.getDeleted());
b.setProductId(src.getProductId()); b.setProductId(src.getProductId());
b.setVersionId(src.getVersionId()); b.setVersionId(src.getVersionId());
b.setSectionName(src.getSectionName()); b.setSectionName(src.getSectionName());
@@ -36,6 +36,8 @@ public interface LblProductMapper
int deleteAllVersionsBySetAndNo(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo); int deleteAllVersionsBySetAndNo(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo);
int deleteVersionById(@Param("versionId") Long versionId);
List<LblProductVersion> selectVersionsBySet(@Param("priceSetId") Long priceSetId); List<LblProductVersion> selectVersionsBySet(@Param("priceSetId") Long priceSetId);
List<LblProductVersion> selectVersionsBySetAndNo(@Param("priceSetId") Long priceSetId, List<LblProductVersion> selectVersionsBySetAndNo(@Param("priceSetId") Long priceSetId,
@@ -56,6 +58,8 @@ public interface LblProductMapper
int deleteWeightBandsByVersion(@Param("versionId") Long versionId); int deleteWeightBandsByVersion(@Param("versionId") Long versionId);
int deleteWeightBandById(@Param("bandId") Long bandId);
List<LblWeightBand> selectWeightBandsByVersion(@Param("versionId") Long versionId); List<LblWeightBand> selectWeightBandsByVersion(@Param("versionId") Long versionId);
int insertSurcharge(LblSurcharge surcharge); int insertSurcharge(LblSurcharge surcharge);
@@ -66,6 +70,8 @@ public interface LblProductMapper
int deleteSurchargesByVersion(@Param("versionId") Long versionId); int deleteSurchargesByVersion(@Param("versionId") Long versionId);
int deleteSurchargeById(@Param("surchargeId") Long surchargeId);
List<LblSurcharge> selectSurchargesByVersion(@Param("versionId") Long versionId); List<LblSurcharge> selectSurchargesByVersion(@Param("versionId") Long versionId);
List<Long> selectVersionIdsBySetAndProducts(@Param("priceSetId") Long priceSetId, @Param("productIds") Long[] productIds); List<Long> selectVersionIdsBySetAndProducts(@Param("priceSetId") Long priceSetId, @Param("productIds") Long[] productIds);
@@ -215,15 +215,11 @@ public class LblProductServiceImpl implements ILblProductService
Long priceSetId = ensureLabelPriceSet(command); Long priceSetId = ensureLabelPriceSet(command);
report(listener, 8, "套餐 " + priceSetId + " 就绪,开始落库产品"); report(listener, 8, "套餐 " + priceSetId + " 就绪,开始落库产品");
String operator = SecurityUtils.getUsername(); String operator = SecurityUtils.getUsername();
Date keepStart = null;
String keepStatus = TERM_PENDING;
int nextVersionNo; int nextVersionNo;
boolean editPendingVersion = command.getVersionNo() != null; boolean editVersion = command.getVersionNo() != null;
if (editPendingVersion) if (editVersion)
{ {
VersionKeep keep = clearEditableVersion(priceSetId, command.getVersionNo(), operator); assertEditableVersionExists(priceSetId, command.getVersionNo());
keepStart = keep.effectiveStart;
keepStatus = keep.status == null ? TERM_PENDING : keep.status;
nextVersionNo = command.getVersionNo(); nextVersionNo = command.getVersionNo();
} }
else else
@@ -234,13 +230,24 @@ public class LblProductServiceImpl implements ILblProductService
int saved = 0; int saved = 0;
int replaced = 0; int replaced = 0;
int skipped = 0; int skipped = 0;
int removed = 0;
List<LblProduct> products = command.getProducts(); List<LblProduct> products = command.getProducts();
int total = products.size(); int total = products.size();
Map<String, Map<String, List<String>>> zoneSyncByCountry = new LinkedHashMap<String, Map<String, List<String>>>(); Map<String, Map<String, List<String>>> zoneSyncByCountry = new LinkedHashMap<String, Map<String, List<String>>>();
for (int i = 0; i < products.size(); i++) for (int i = 0; i < products.size(); i++)
{ {
LblProduct product = products.get(i); LblProduct product = products.get(i);
if (product == null || isBlank(product.getProductName()) || isBlank(product.getSheetName()) if (product == null)
{
throw PaymentMesEnum.BMS_PAY_PROD_FIELD.exception();
}
if (editVersion && Boolean.TRUE.equals(product.getDeleted()))
{
removeEditVersionProduct(priceSetId, nextVersionNo, product);
removed++;
continue;
}
if (isBlank(product.getProductName()) || isBlank(product.getSheetName())
|| isBlank(product.getFileMd5())) || isBlank(product.getFileMd5()))
{ {
throw PaymentMesEnum.BMS_PAY_PROD_FIELD.exception(); throw PaymentMesEnum.BMS_PAY_PROD_FIELD.exception();
@@ -248,7 +255,15 @@ public class LblProductServiceImpl implements ILblProductService
String displayName = blankTo(product.getProductName(), product.getSheetName()); String displayName = blankTo(product.getProductName(), product.getSheetName());
int pct = 10 + (int) Math.floor((i * 75.0) / Math.max(total, 1)); int pct = 10 + (int) Math.floor((i * 75.0) / Math.max(total, 1));
report(listener, pct, "正在保存「" + displayName + "」(" + (i + 1) + "/" + total + ")"); report(listener, pct, "正在保存「" + displayName + "」(" + (i + 1) + "/" + total + ")");
LblBandNormalizer.normalizeProduct(product); if (editVersion && product.getVersionId() != null)
{
// 编辑已有版本:不做拆合归一,保留 bandId/surchargeId
fillBandDefaults(product);
}
else
{
LblBandNormalizer.normalizeProduct(product);
}
String dict = blankTo(product.getDictValue(), product.getProductName()); String dict = blankTo(product.getDictValue(), product.getProductName());
product.setDictValue(dict); product.setDictValue(dict);
Long existsId = lblProductMapper.selectProductIdBySetAndDict(priceSetId, dict); Long existsId = lblProductMapper.selectProductIdBySetAndDict(priceSetId, dict);
@@ -257,7 +272,7 @@ public class LblProductServiceImpl implements ILblProductService
LblProduct byDict = lblProductMapper.selectProductByDict(dict); LblProduct byDict = lblProductMapper.selectProductByDict(dict);
existsId = byDict == null ? null : byDict.getProductId(); existsId = byDict == null ? null : byDict.getProductId();
} }
boolean hasPending = !editPendingVersion && existsId != null && hasPending(priceSetId, existsId); boolean hasPending = !editVersion && existsId != null && hasPending(priceSetId, existsId);
if (hasPending && !command.isOverwrite()) if (hasPending && !command.isOverwrite())
{ {
skipped++; skipped++;
@@ -270,20 +285,36 @@ public class LblProductServiceImpl implements ILblProductService
product.setCreateTime(new Date()); product.setCreateTime(new Date());
if (existsId != null) if (existsId != null)
{ {
if (editPendingVersion || command.isOverwrite())
{
lblProductMapper.closePendingBySetProduct(priceSetId, existsId, yesterday(), operator);
}
product.setProductId(existsId); product.setProductId(existsId);
lblProductMapper.updateProduct(product); lblProductMapper.updateProduct(product);
openVersion(product, priceSetId, nextVersionNo, operator); if (editVersion && product.getVersionId() != null)
replaced++; {
assertVersionBelongs(product.getVersionId(), priceSetId, nextVersionNo, existsId);
upsertDetails(product, product.getVersionId());
}
else
{
if (!editVersion && command.isOverwrite())
{
lblProductMapper.closePendingBySetProduct(priceSetId, existsId, yesterday(), operator);
}
openVersion(product, priceSetId, nextVersionNo, operator);
if (editVersion)
{
alignNewVersionMeta(priceSetId, nextVersionNo, product.getVersionId(), operator);
}
replaced++;
}
} }
else else
{ {
product.setProductId(null); product.setProductId(null);
lblProductMapper.insertProduct(product); lblProductMapper.insertProduct(product);
openVersion(product, priceSetId, nextVersionNo, operator); openVersion(product, priceSetId, nextVersionNo, operator);
if (editVersion)
{
alignNewVersionMeta(priceSetId, nextVersionNo, product.getVersionId(), operator);
}
} }
saved++; saved++;
collectZoneSync(zoneSyncByCountry, product); collectZoneSync(zoneSyncByCountry, product);
@@ -293,20 +324,9 @@ public class LblProductServiceImpl implements ILblProductService
{ {
prcZoneService.syncCountryZones(e.getKey(), e.getValue()); prcZoneService.syncCountryZones(e.getKey(), e.getValue());
} }
if (editPendingVersion && keepStart != null)
{
List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, nextVersionNo);
for (LblProductVersion row : rows)
{
row.setEffectiveStart(keepStart);
row.setStatus(keepStatus);
row.setUpdateBy(operator);
lblProductMapper.updateVersion(row);
}
}
report(listener, 98, "保存完成,正在收尾"); report(listener, 98, "保存完成,正在收尾");
return editPendingVersion return editVersion
? ("套餐" + priceSetId + "版本V" + nextVersionNo + "已更新" + saved + "个产品") ? ("套餐" + priceSetId + "版本V" + nextVersionNo + "已更新" + saved + "个产品,删除" + removed + "个")
: ("套餐" + priceSetId + "已保存" + saved + "个产品,新版本" + replaced + "个,跳过" + skipped + "个"); : ("套餐" + priceSetId + "已保存" + saved + "个产品,新版本" + replaced + "个,跳过" + skipped + "个");
} }
@@ -675,6 +695,230 @@ public class LblProductServiceImpl implements ILblProductService
} }
} }
private void assertEditableVersionExists(Long priceSetId, Integer versionNo)
{
List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, versionNo);
if (rows == null || rows.isEmpty())
{
throw new ServiceException("版本不存在");
}
for (LblProductVersion row : rows)
{
if (!TERM_PENDING.equals(row.getStatus()) && !TERM_EFFECT.equals(row.getStatus()))
{
throw new ServiceException("只能编辑待生效或已生效版本");
}
}
}
private void assertVersionBelongs(Long versionId, Long priceSetId, int versionNo, Long productId)
{
LblProductVersion ver = lblProductMapper.selectVersionById(versionId);
if (ver == null)
{
throw new ServiceException("价卡版本不存在");
}
if (!priceSetId.equals(ver.getPriceSetId()) || ver.getVersionNo() == null || ver.getVersionNo().intValue() != versionNo)
{
throw new ServiceException("版本与当前编辑版不匹配");
}
if (productId != null && ver.getProductId() != null && !productId.equals(ver.getProductId()))
{
throw new ServiceException("版本产品不匹配");
}
}
private void removeEditVersionProduct(Long priceSetId, int versionNo, LblProduct product)
{
Long versionId = product.getVersionId();
if (versionId == null && product.getProductId() != null)
{
List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, versionNo);
if (rows != null)
{
for (LblProductVersion row : rows)
{
if (product.getProductId().equals(row.getProductId()))
{
versionId = row.getVersionId();
break;
}
}
}
}
if (versionId == null)
{
return;
}
LblProductVersion exists = lblProductMapper.selectVersionById(versionId);
if (exists == null)
{
return;
}
assertVersionBelongs(versionId, priceSetId, versionNo, product.getProductId());
lblProductMapper.deleteWeightBandsByVersion(versionId);
lblProductMapper.deleteSurchargesByVersion(versionId);
lblProductMapper.deleteVersionById(versionId);
}
private void alignNewVersionMeta(Long priceSetId, int versionNo, Long newVersionId, String operator)
{
if (newVersionId == null)
{
return;
}
List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, versionNo);
if (rows == null || rows.isEmpty())
{
return;
}
LblProductVersion sample = null;
for (LblProductVersion row : rows)
{
if (row != null && row.getVersionId() != null && !newVersionId.equals(row.getVersionId()))
{
sample = row;
break;
}
}
if (sample == null)
{
return;
}
LblProductVersion neu = lblProductMapper.selectVersionById(newVersionId);
if (neu == null)
{
return;
}
neu.setEffectiveStart(sample.getEffectiveStart());
neu.setEffectiveEnd(sample.getEffectiveEnd());
neu.setStatus(sample.getStatus() == null ? TERM_PENDING : sample.getStatus());
neu.setUpdateBy(operator);
lblProductMapper.updateVersion(neu);
}
private void fillBandDefaults(LblProduct product)
{
if (product == null || product.getWeightBands() == null)
{
return;
}
int sort = 0;
for (LblWeightBand band : product.getWeightBands())
{
if (band == null || Boolean.TRUE.equals(band.getDeleted()))
{
continue;
}
if (band.getFeeType() == null || band.getFeeType().isEmpty())
{
band.setFeeType("FREIGHT");
}
if (band.getChargeMode() == null || band.getChargeMode().isEmpty())
{
band.setChargeMode("ITEM");
}
if (band.getCountryCode() == null)
{
band.setCountryCode("");
}
if (band.getZoneCode() == null)
{
band.setZoneCode("");
}
if (band.getPostcodeParam() == null)
{
band.setPostcodeParam("");
}
if (band.getCalcParam() == null)
{
band.setCalcParam("");
}
band.setSortNo(sort++);
}
}
private void upsertDetails(LblProduct product, Long versionId)
{
if (product.getWeightBands() != null)
{
int i = 0;
for (LblWeightBand band : product.getWeightBands())
{
if (band == null)
{
continue;
}
if (Boolean.TRUE.equals(band.getDeleted()))
{
if (band.getBandId() != null)
{
lblProductMapper.deleteWeightBandById(band.getBandId());
}
continue;
}
band.setProductId(product.getProductId());
band.setVersionId(versionId);
if (band.getCountryCode() == null)
{
band.setCountryCode("");
}
if (band.getZoneCode() == null)
{
band.setZoneCode("");
}
if (band.getPostcodeParam() == null)
{
band.setPostcodeParam("");
}
band.setSortNo(i++);
if (band.getBandId() != null)
{
lblProductMapper.updateWeightBand(band);
}
else
{
lblProductMapper.insertWeightBand(band);
}
}
}
if (product.getSurcharges() != null)
{
int i = 0;
for (LblSurcharge fee : product.getSurcharges())
{
if (fee == null)
{
continue;
}
if (Boolean.TRUE.equals(fee.getDeleted()))
{
if (fee.getSurchargeId() != null)
{
lblProductMapper.deleteSurchargeById(fee.getSurchargeId());
}
continue;
}
if (isBlank(fee.getFeeName()))
{
continue;
}
fee.setProductId(product.getProductId());
fee.setVersionId(versionId);
fee.setSortNo(i++);
if (fee.getSurchargeId() != null)
{
lblProductMapper.updateSurcharge(fee);
}
else
{
lblProductMapper.insertSurcharge(fee);
}
}
}
}
private VersionKeep clearEditableVersion(Long priceSetId, Integer versionNo, String operator) private VersionKeep clearEditableVersion(Long priceSetId, Integer versionNo, String operator)
{ {
List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, versionNo); List<LblProductVersion> rows = lblProductMapper.selectVersionsBySetAndNo(priceSetId, versionNo);
@@ -786,8 +1030,28 @@ public class LblProductServiceImpl implements ILblProductService
private void prepareCounts(LblProduct product) private void prepareCounts(LblProduct product)
{ {
int bands = product.getWeightBands() == null ? 0 : product.getWeightBands().size(); int bands = 0;
int fees = product.getSurcharges() == null ? 0 : product.getSurcharges().size(); if (product.getWeightBands() != null)
{
for (LblWeightBand band : product.getWeightBands())
{
if (band != null && !Boolean.TRUE.equals(band.getDeleted()))
{
bands++;
}
}
}
int fees = 0;
if (product.getSurcharges() != null)
{
for (LblSurcharge fee : product.getSurcharges())
{
if (fee != null && !Boolean.TRUE.equals(fee.getDeleted()) && !isBlank(fee.getFeeName()))
{
fees++;
}
}
}
product.setWeightCount(bands); product.setWeightCount(bands);
product.setSurchargeCount(fees); product.setSurchargeCount(fees);
} }
@@ -117,6 +117,10 @@
where price_set_id = #{priceSetId} and version_no = #{versionNo} where price_set_id = #{priceSetId} and version_no = #{versionNo}
</delete> </delete>
<delete id="deleteVersionById">
delete from prc_label_product_version where version_id = #{versionId}
</delete>
<select id="selectVersionsBySet" resultType="com.bms.price.domain.LblProductVersion"> <select id="selectVersionsBySet" resultType="com.bms.price.domain.LblProductVersion">
select v.version_id as versionId, v.price_set_id as priceSetId, v.product_id as productId, v.dict_value as dictValue, select v.version_id as versionId, v.price_set_id as priceSetId, v.product_id as productId, v.dict_value as dictValue,
v.version_no as versionNo, v.effective_start as effectiveStart, v.effective_end as effectiveEnd, v.file_path as filePath, v.version_no as versionNo, v.effective_start as effectiveStart, v.effective_end as effectiveEnd, v.file_path as filePath,
@@ -200,6 +204,10 @@
delete from prc_label_weight_band where version_id = #{versionId} delete from prc_label_weight_band where version_id = #{versionId}
</delete> </delete>
<delete id="deleteWeightBandById">
delete from prc_label_weight_band where band_id = #{bandId}
</delete>
<select id="selectWeightBandsByVersion" resultType="com.bms.price.domain.LblWeightBand"> <select id="selectWeightBandsByVersion" resultType="com.bms.price.domain.LblWeightBand">
select band_id as bandId, product_id as productId, version_id as versionId, fee_type as feeType, select band_id as bandId, product_id as productId, version_id as versionId, fee_type as feeType,
country_name as countryName, country_code as countryCode, zone_code as zoneCode, zone_name as zoneName, country_name as countryName, country_code as countryCode, zone_code as zoneCode, zone_name as zoneName,
@@ -251,6 +259,10 @@
delete from prc_label_surcharge where version_id = #{versionId} delete from prc_label_surcharge where version_id = #{versionId}
</delete> </delete>
<delete id="deleteSurchargeById">
delete from prc_label_surcharge where surcharge_id = #{surchargeId}
</delete>
<select id="selectSurchargesByVersion" resultType="com.bms.price.domain.LblSurcharge"> <select id="selectSurchargesByVersion" resultType="com.bms.price.domain.LblSurcharge">
select surcharge_id as surchargeId, product_id as productId, version_id as versionId, fee_name as feeName, sc_id as scId, select surcharge_id as surchargeId, product_id as productId, version_id as versionId, fee_name as feeName, sc_id as scId,
zone_code as zoneCode, zone_name as zoneName, charge_text as chargeText, amount, currency, price_unit as priceUnit, zone_code as zoneCode, zone_name as zoneName, charge_text as chargeText, amount, currency, price_unit as priceUnit,
@@ -2,7 +2,7 @@
<div v-if="panes.length" class="label-detail"> <div v-if="panes.length" class="label-detail">
<section v-for="pane in panes" :key="pane.key" class="label-product"> <section v-for="pane in panes" :key="pane.key" class="label-product">
<el-tabs v-model="pane.tab"> <el-tabs v-model="pane.tab">
<el-tab-pane :label="`重量段(${(pane.item.weightBands || []).length})`" name="band"> <el-tab-pane :label="bandTabLabel(pane)" name="band">
<el-input v-model="pane.bandKeyword" clearable placeholder="筛选国家、分区、重量段、计费条件、邮编、费用项" class="label-filter" /> <el-input v-model="pane.bandKeyword" clearable placeholder="筛选国家、分区、重量段、计费条件、邮编、费用项" class="label-filter" />
<el-table <el-table
:data="displayBands(pane)" :data="displayBands(pane)"
@@ -503,8 +503,16 @@ watch(source, (list) => {
})) }))
}, { immediate: true }) }, { immediate: true })
function aliveRows(list) {
return (list || []).filter(row => row && row.deleted !== true)
}
function bandTabLabel(pane) {
return '重量段(' + aliveRows(pane?.item?.weightBands).length + ')'
}
function filteredBands(pane) { function filteredBands(pane) {
return filterRows(pane.item.weightBands || [], pane.bandKeyword, ['countryName', 'countryCode', 'zoneCode', 'zoneName', 'postcodeParam', 'weightLabel', 'feeType', 'chargeMode', 'chargeName', 'calcParam', 'priceUnit', 'extraPriceUnit']) return filterRows(aliveRows(pane.item.weightBands), pane.bandKeyword, ['countryName', 'countryCode', 'zoneCode', 'zoneName', 'postcodeParam', 'weightLabel', 'feeType', 'chargeMode', 'chargeName', 'calcParam', 'priceUnit', 'extraPriceUnit'])
} }
const FEE_TYPE_ORDER = { FREIGHT: 1, REGISTRATION: 2, REMOTE: 3 } const FEE_TYPE_ORDER = { FREIGHT: 1, REGISTRATION: 2, REMOTE: 3 }
@@ -527,7 +535,7 @@ function feeTypeOrder(row) {
} }
function bandViewSignature(pane) { function bandViewSignature(pane) {
const bands = pane?.item?.weightBands || [] const bands = aliveRows(pane?.item?.weightBands)
const keyword = pane?.bandKeyword || '' const keyword = pane?.bandKeyword || ''
let hash = bands.length + ':' + keyword let hash = bands.length + ':' + keyword
for (let i = 0; i < bands.length; i++) { for (let i = 0; i < bands.length; i++) {
@@ -611,16 +619,15 @@ function invalidateBandView(pane) {
} }
function filteredFees(pane) { function filteredFees(pane) {
return filterRows(pane.item.surcharges || [], pane.feeKeyword, ['feeName', 'amount', 'currency', 'priceUnit', 'feeDesc', 'calcRule', 'calcParam']) return filterRows(aliveRows(pane.item.surcharges), pane.feeKeyword, ['feeName', 'amount', 'currency', 'priceUnit', 'feeDesc', 'calcRule', 'calcParam'])
} }
function feeTabLabel(pane) { function feeTabLabel(pane) {
const fees = pane.item.surcharges || [] return '附加费(' + aliveRows(pane?.item?.surcharges).length + ')'
return '附加费(' + fees.length + ')'
} }
function feeCheckedCount(pane) { function feeCheckedCount(pane) {
return (pane?.item?.surcharges || []).filter(fee => fee && fee._checked === true).length return aliveRows(pane?.item?.surcharges).filter(fee => fee && fee._checked === true).length
} }
function isAllFilteredFeesChecked(pane) { function isAllFilteredFeesChecked(pane) {
@@ -644,7 +651,7 @@ function setFilteredFeesChecked(pane, value) {
async function removeCheckedFees(pane) { async function removeCheckedFees(pane) {
const list = pane?.item?.surcharges const list = pane?.item?.surcharges
if (!list?.length) return if (!list?.length) return
const checked = list.filter(fee => fee && fee._checked === true) const checked = aliveRows(list).filter(fee => fee && fee._checked === true)
if (!checked.length) { if (!checked.length) {
proxy.$modal.msgWarning('请先勾选要删除的附加费') proxy.$modal.msgWarning('请先勾选要删除的附加费')
return return
@@ -654,10 +661,18 @@ async function removeCheckedFees(pane) {
} catch { } catch {
return return
} }
const remain = list.filter(fee => !(fee && fee._checked === true)) for (const fee of checked) {
pane.item.surcharges = remain if (fee.surchargeId != null) {
const maxPage = Math.max(1, Math.ceil(remain.length / pageSize) || 1) fee.deleted = true
fee._checked = false
} else {
const index = list.indexOf(fee)
if (index >= 0) list.splice(index, 1)
}
}
const maxPage = Math.max(1, Math.ceil(aliveRows(list).length / pageSize) || 1)
if (pane.feePageNo > maxPage) pane.feePageNo = maxPage if (pane.feePageNo > maxPage) pane.feePageNo = maxPage
invalidateBandView(pane)
proxy.$modal.msgSuccess(`已删除 ${checked.length} 项`) proxy.$modal.msgSuccess(`已删除 ${checked.length} 项`)
} }
@@ -666,7 +681,7 @@ const feePickerVisible = ref(false)
const feePickerPane = ref(null) const feePickerPane = ref(null)
const feePickerExcludeIds = computed(() => { const feePickerExcludeIds = computed(() => {
const fees = feePickerPane.value?.item?.surcharges || [] const fees = aliveRows(feePickerPane.value?.item?.surcharges)
return fees.map(fee => fee?.scId).filter(id => id != null) return fees.map(fee => fee?.scId).filter(id => id != null)
}) })
@@ -736,8 +751,13 @@ function onFeePickerConfirm(list) {
} }
function removeRow(list, row) { function removeRow(list, row) {
const index = list.indexOf(row) if (!list || !row) return
if (index >= 0) list.splice(index, 1) if (row.bandId != null || row.surchargeId != null) {
row.deleted = true
} else {
const index = list.indexOf(row)
if (index >= 0) list.splice(index, 1)
}
for (const pane of panes.value) { for (const pane of panes.value) {
if (pane?.item?.weightBands === list || pane?.item?.surcharges === list) invalidateBandView(pane) if (pane?.item?.weightBands === list || pane?.item?.surcharges === list) invalidateBandView(pane)
} }
@@ -33,23 +33,13 @@
<el-table-column :label="colBoundChannels" min-width="180" show-overflow-tooltip> <el-table-column :label="colBoundChannels" min-width="180" show-overflow-tooltip>
<template #default="{ row }">{{ boundChannelText(row) }}</template> <template #default="{ row }">{{ boundChannelText(row) }}</template>
</el-table-column> </el-table-column>
<el-table-column :label="colAction" width="160" align="center" fixed="right"> <el-table-column :label="colAction" width="90" align="center" fixed="right">
<template #default="{ row }"> <template #default="{ row }">
<el-button link type="primary" @click="openProduct(row)" v-hasPermi="['price:label:query', 'price:label:edit']">编辑</el-button>
<el-button link type="primary" @click="openBindList(row)" v-hasPermi="['price:label:edit']">绑定</el-button> <el-button link type="primary" @click="openBindList(row)" v-hasPermi="['price:label:edit']">绑定</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-drawer v-model="detailVisible" :title="detailTitle" size="78%" destroy-on-close append-to-body>
<label-config-detail
v-loading="detailLoading"
:product="detail"
:editable="canEditDetail"
:saving-row-key="savingRowKey"
@save-row="saveDetailRow"
/>
</el-drawer>
<el-drawer <el-drawer
v-model="bindListVisible" v-model="bindListVisible"
@@ -128,16 +118,10 @@
<script setup> <script setup>
import { import {
listLabelProducts, listLabelProducts,
getLabelProduct,
updateLabelProduct,
updateLabelWeightBand,
updateLabelSurcharge,
listLabelProductChannels, listLabelProductChannels,
replaceLabelProductChannels replaceLabelProductChannels
} from '@/api/price/label' } from '@/api/price/label'
import { checkPermi } from '@/utils/permission'
import { listChannelOptions } from '@/api/masterdata/serviceChannel' import { listChannelOptions } from '@/api/masterdata/serviceChannel'
import LabelConfigDetail from './LabelConfigDetail.vue'
const props = defineProps({ const props = defineProps({
visible: { type: Boolean, default: false }, visible: { type: Boolean, default: false },
@@ -150,13 +134,6 @@ const { proxy } = getCurrentInstance()
const loading = ref(false) const loading = ref(false)
const rows = ref([]) const rows = ref([])
const keyword = ref('') const keyword = ref('')
const detailVisible = ref(false)
const detailLoading = ref(false)
const detailSaving = ref(false)
const savingRowKey = ref('')
const detail = ref(null)
const canEditDetail = computed(() => checkPermi(['price:label:edit']))
const bindListVisible = ref(false) const bindListVisible = ref(false)
const bindListLoading = ref(false) const bindListLoading = ref(false)
const bindProductId = ref(null) const bindProductId = ref(null)
@@ -194,12 +171,6 @@ const title = computed(() => {
return label ? `版本明细 · ${label}` : '版本明细' return label ? `版本明细 · ${label}` : '版本明细'
}) })
const detailTitle = computed(() => {
if (!detail.value) return '产品明细'
const no = detail.value.versionNo ? `第 ${detail.value.versionNo} 版` : ''
return `${detail.value.productName || '产品'} ${no}`.trim()
})
const bindListTitle = computed(() => { const bindListTitle = computed(() => {
return bindProductName.value ? `绑定渠道 · ${bindProductName.value}` : '绑定渠道' return bindProductName.value ? `绑定渠道 · ${bindProductName.value}` : '绑定渠道'
}) })
@@ -270,86 +241,6 @@ async function load() {
} }
} }
function cleanMoney(product) {
if (!product) return
;(product.weightBands || []).forEach(row => {
if (!row) return
if (row.price === '') row.price = null
if (row.extraPrice === '') row.extraPrice = null
if (row.weightMin === '') row.weightMin = null
if (row.weightMax === '') row.weightMax = null
})
;(product.surcharges || []).forEach(row => {
if (row && row.amount === '') row.amount = null
})
}
async function persistDetail() {
if (!detail.value?.productId) {
throw new Error('NO_PRODUCT')
}
cleanMoney(detail.value)
await updateLabelProduct(detail.value)
const versionId = detail.value.versionId || detail.value.termId
const res = await getLabelProduct(detail.value.productId, versionId)
detail.value = res.data || detail.value
await load()
emit('changed')
}
async function saveDetailRow(payload) {
if (!detail.value || savingRowKey.value || detailSaving.value) {
payload?.done?.(false)
return
}
savingRowKey.value = payload?.rowKey || 'row'
let ok = false
try {
const row = payload?.row
if (payload?.kind === 'band') {
if (!row?.bandId) throw new Error('NO_BAND')
if (row.price === '') row.price = null
if (row.extraPrice === '') row.extraPrice = null
await updateLabelWeightBand({
bandId: row.bandId,
feeType: row.feeType,
chargeMode: row.chargeMode,
calcParam: row.calcParam,
postcodeParam: row.postcodeParam,
price: row.price,
extraPrice: row.extraPrice
})
} else if (payload?.kind === 'fee') {
if (!row?.surchargeId) throw new Error('NO_FEE')
if (row.amount === '') row.amount = null
await updateLabelSurcharge(row)
} else {
await persistDetail()
}
ok = true
proxy.$modal.msgSuccess('该行已保存')
} catch (e) {
ok = false
} finally {
savingRowKey.value = ''
payload?.done?.(ok)
}
}
async function openProduct(row) {
detailVisible.value = true
detailLoading.value = true
detailSaving.value = false
savingRowKey.value = ''
detail.value = null
try {
const res = await getLabelProduct(row.productId, row.versionId || row.termId)
detail.value = res.data || null
} finally {
detailLoading.value = false
}
}
async function ensureChannelOptions() { async function ensureChannelOptions() {
if (channelOptions.value.length) return if (channelOptions.value.length) return
const res = await listChannelOptions({ blOpen: '1' }) const res = await listChannelOptions({ blOpen: '1' })
+59 -11
View File
@@ -128,6 +128,7 @@ const form = reactive({
basic: createEmptyBasicInfo() basic: createEmptyBasicInfo()
}) })
const productRows = ref([]) const productRows = ref([])
const removedProducts = ref([])
const productTableRef = ref() const productTableRef = ref()
const selectedProducts = ref([]) const selectedProducts = ref([])
const importMeta = reactive({ const importMeta = reactive({
@@ -165,7 +166,7 @@ const pageBanner = computed(() => {
return `新建版本:${name}(${code})` return `新建版本:${name}(${code})`
}) })
const headerTip = computed(() => { const headerTip = computed(() => {
if (editVersionMode.value) return '可重新导入或修改明细;完成后覆盖本版本,不新增版本号' if (editVersionMode.value) return '可重新导入或修改明细;完成后按ID更新/新增/删除,不新增版本号'
if (newVersionMode.value) return '导入后生成待生效新版本;生效时间请回详情页设置' if (newVersionMode.value) return '导入后生成待生效新版本;生效时间请回详情页设置'
return '打单价卡与应付独立;解析后回填到此表,可删除不需要的产品,编辑明细后点完成保存' return '打单价卡与应付独立;解析后回填到此表,可删除不需要的产品,编辑明细后点完成保存'
}) })
@@ -190,6 +191,7 @@ async function loadPackageHeader() {
async function loadEditProducts() { async function loadEditProducts() {
if (!editVersionMode.value || !priceSetId.value || !versionNo.value) return if (!editVersionMode.value || !priceSetId.value || !versionNo.value) return
loadingProducts.value = true loadingProducts.value = true
removedProducts.value = []
try { try {
const res = await listLabelProducts(priceSetId.value, versionNo.value) const res = await listLabelProducts(priceSetId.value, versionNo.value)
const list = res.data || [] const list = res.data || []
@@ -244,6 +246,34 @@ function productKey(row) {
return row?.rowKey || `${row?.sheetName || ''}-${row?.productName || ''}` return row?.rowKey || `${row?.sheetName || ''}-${row?.productName || ''}`
} }
function aliveDetailRows(list) {
return (list || []).filter(row => row && row.deleted !== true)
}
function markProductRemoved(row) {
if (!row) return
const vid = row.versionId || row.termId
const pid = row.productId
const dup = (removedProducts.value || []).some(item => {
if (vid != null && (item.versionId || item.termId) != null) {
return String(item.versionId || item.termId) === String(vid)
}
return pid != null && item.productId != null && String(item.productId) === String(pid)
})
if (dup) return
removedProducts.value.push({
...row,
deleted: true,
weightBands: aliveDetailRows(row.weightBands).filter(b => b.bandId != null).map(b => ({ ...b, deleted: true })),
surcharges: aliveDetailRows(row.surcharges).filter(s => s.surchargeId != null).map(s => ({ ...s, deleted: true }))
})
}
function buildSaveProducts() {
const active = (productRows.value || []).filter(row => row && row.deleted !== true)
return [...(removedProducts.value || []), ...active]
}
async function removeProduct(row) { async function removeProduct(row) {
if (!row) return if (!row) return
try { try {
@@ -252,6 +282,9 @@ async function removeProduct(row) {
return return
} }
const key = productKey(row) const key = productKey(row)
if (editVersionMode.value && (row.versionId || row.productId)) {
markProductRemoved(row)
}
productRows.value = productRows.value.filter(item => productKey(item) !== key) productRows.value = productRows.value.filter(item => productKey(item) !== key)
selectedProducts.value = selectedProducts.value.filter(item => productKey(item) !== key) selectedProducts.value = selectedProducts.value.filter(item => productKey(item) !== key)
if (detailRowKey.value === key) { if (detailRowKey.value === key) {
@@ -272,6 +305,11 @@ async function removeSelectedProducts() {
return return
} }
const keys = new Set(rows.map(productKey)) const keys = new Set(rows.map(productKey))
if (editVersionMode.value) {
for (const row of rows) {
if (row.versionId || row.productId) markProductRemoved(row)
}
}
productRows.value = productRows.value.filter(item => !keys.has(productKey(item))) productRows.value = productRows.value.filter(item => !keys.has(productKey(item)))
selectedProducts.value = [] selectedProducts.value = []
if (keys.has(detailRowKey.value)) { if (keys.has(detailRowKey.value)) {
@@ -281,6 +319,13 @@ async function removeSelectedProducts() {
} }
function onImportConfirm(payload) { function onImportConfirm(payload) {
if (editVersionMode.value) {
for (const row of productRows.value || []) {
if (row?.versionId || row?.productId) markProductRemoved(row)
}
} else {
removedProducts.value = []
}
productRows.value = payload?.products || [] productRows.value = payload?.products || []
selectedProducts.value = [] selectedProducts.value = []
importMeta.sourceFile = payload?.sourceFile || '' importMeta.sourceFile = payload?.sourceFile || ''
@@ -319,8 +364,8 @@ function applyEditedProduct() {
proxy.$modal.msgError('未找到对应产品行') proxy.$modal.msgError('未找到对应产品行')
return false return false
} }
const bands = edited.weightBands || [] const bands = aliveDetailRows(edited.weightBands)
const fees = edited.surcharges || [] const fees = aliveDetailRows(edited.surcharges)
const extras = edited.extraLines || [] const extras = edited.extraLines || []
productRows.value.splice(idx, 1, { productRows.value.splice(idx, 1, {
...edited, ...edited,
@@ -375,19 +420,22 @@ async function finish() {
proxy.$modal.msgWarning(editVersionMode.value ? '缺少套餐编号,无法编辑版本' : '缺少套餐编号,无法新建版本') proxy.$modal.msgWarning(editVersionMode.value ? '缺少套餐编号,无法编辑版本' : '缺少套餐编号,无法新建版本')
return return
} }
if (!productRows.value.length) {
proxy.$modal.msgWarning('请先导入并确认价卡产品')
return
}
// 抽屉未关闭时先回写勾选,避免丢失 // 抽屉未关闭时先回写勾选,避免丢失
if (detailVisible.value && detailProduct.value && detailRowKey.value) { if (detailVisible.value && detailProduct.value && detailRowKey.value) {
applyEditedProduct() applyEditedProduct()
} }
const saveProducts = buildSaveProducts()
if (!saveProducts.length) {
proxy.$modal.msgWarning('请先导入并确认价卡产品')
return
}
const activeCount = saveProducts.filter(p => !p.deleted).length
const removedCount = saveProducts.filter(p => p.deleted).length
const tip = editVersionMode.value const tip = editVersionMode.value
? `将覆盖版本 V${versionNo.value} 的 ${productRows.value.length} 个产品,确认继续?` ? `将按ID更新版本 V${versionNo.value}(保留 ${activeCount} 个产品,删除 ${removedCount} 个),确认继续?`
: newVersionMode.value : newVersionMode.value
? `将为套餐「${form.basic.priceSetName || ''}」新建待生效版本并保存 ${productRows.value.length} 个产品,确认继续?` ? `将为套餐「${form.basic.priceSetName || ''}」新建待生效版本并保存 ${activeCount} 个产品,确认继续?`
: `将创建打单套餐并保存 ${productRows.value.length} 个产品,确认继续?` : `将创建打单套餐并保存 ${activeCount} 个产品,确认继续?`
try { try {
await proxy.$modal.confirm(tip) await proxy.$modal.confirm(tip)
} catch { } catch {
@@ -400,7 +448,7 @@ async function finish() {
try { try {
const payload = { const payload = {
overwrite: editVersionMode.value ? true : importMeta.overwrite, overwrite: editVersionMode.value ? true : importMeta.overwrite,
products: productRows.value products: saveProducts
} }
if (editVersionMode.value) { if (editVersionMode.value) {
payload.priceSetId = priceSetId.value payload.priceSetId = priceSetId.value