4 Commits

Author SHA1 Message Date
wuweihua c860d1666d 修改附加费 2026-09-22 10:40:13 +08:00
wuweihua 465b3e6b6b Merge branch 'master' of http://git.lionquexpress.com/wuweihua/BMS 2026-09-22 10:40:09 +08:00
wuweihua 1240ff28fc Merge branch 'master' of http://git.lionquexpress.com/wuweihua/BMS 2026-09-22 10:15:22 +08:00
wuweihua ba81700463 修改附加费操作 2026-09-22 10:15:17 +08:00
21 changed files with 589 additions and 144 deletions
@@ -211,15 +211,29 @@ public class PriceSetController extends BaseController
}
@PreAuthorize("@ss.hasPermi('price:set:edit') or @ss.hasPermi('price:set:forceEdit')")
@Log(title = "套餐明细", businessType = BusinessType.UPDATE)
@Log(title = "\u5957\u9910\u660e\u7ec6", businessType = BusinessType.UPDATE)
@PutMapping("/detail")
public AjaxResult editDetail(@RequestBody PrcPriceSetDetail detail)
{
return toAjax(priceSetService.updateDetail(detail));
}
/**
* Async batch write of detail surcharge snapshots. Returns taskId; poll /save/task/{taskId}.
*/
@PreAuthorize("@ss.hasPermi('price:set:edit') or @ss.hasPermi('price:set:forceEdit')")
@Log(title = "套餐明细", businessType = BusinessType.DELETE)
@Log(title = "\u5957\u9910\u9644\u52a0\u8d39", businessType = BusinessType.UPDATE)
@PostMapping("/detail/surcharge/async")
public AjaxResult batchSurchargeAsync(@RequestBody List<PrcPriceSetDetail> details)
{
String taskId = priceSetService.submitDetailSurchargeAsync(details);
Map<String, Object> payload = new HashMap<String, Object>();
payload.put("taskId", taskId);
return success(payload);
}
@PreAuthorize("@ss.hasPermi('price:set:edit') or @ss.hasPermi('price:set:forceEdit')")
@Log(title = "\u5957\u9910\u660e\u7ec6", businessType = BusinessType.DELETE)
@DeleteMapping("/detail/{psdIds}")
public AjaxResult removeDetail(@PathVariable Long[] psdIds)
{
@@ -108,20 +108,42 @@ public class SurchargeController extends BaseController
return toAjax(surchargeService.insertPrcSurcharge(surcharge));
}
/**
* 修改(版本化):内容无变化时返回 warn 提示,否则原记录作废 + 插入新记录,产品关联自动重指向新记录。
*/
@PreAuthorize("@ss.hasPermi('price:surcharge:edit')")
@Log(title = "附加费配置", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody PrcSurcharge surcharge)
{
surcharge.setUpdateBy(getUsername());
return toAjax(surchargeService.updatePrcSurcharge(surcharge));
int rows = surchargeService.updatePrcSurcharge(surcharge);
if (rows == -1)
{
return AjaxResult.warn("未做任何修改");
}
return toAjax(rows);
}
/**
* 停用(原地修改 ss_code=of,不新增数据,不物理删除)。
*/
@PreAuthorize("@ss.hasPermi('price:surcharge:remove')")
@Log(title = "附加费配置", businessType = BusinessType.DELETE)
@DeleteMapping("/{scIds}")
public AjaxResult remove(@PathVariable Long[] scIds)
@Log(title = "附加费停用", businessType = BusinessType.UPDATE)
@PutMapping("/disable/{scIds}")
public AjaxResult disable(@PathVariable Long[] scIds)
{
return toAjax(surchargeService.deletePrcSurchargeByIds(scIds));
return toAjax(surchargeService.disablePrcSurchargeByIds(scIds, getUsername()));
}
/**
* 启用(原地修改 ss_code=on,不新增数据)。
*/
@PreAuthorize("@ss.hasPermi('price:surcharge:remove')")
@Log(title = "附加费启用", businessType = BusinessType.UPDATE)
@PutMapping("/enable/{scIds}")
public AjaxResult enable(@PathVariable Long[] scIds)
{
return toAjax(surchargeService.enablePrcSurchargeByIds(scIds, getUsername()));
}
}
@@ -1,11 +1,14 @@
package com.ruoyi.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.price.domain.PrcSurcharge;
/**
* 附加费配置 数据层
*
* 附加费为计费主数据:不做物理修改/删除,编辑=作废旧记录插入新记录,删除=仅作废。
*
* @author ruoyi
*/
public interface PrcSurchargeMapper
@@ -16,7 +19,6 @@ public interface PrcSurchargeMapper
public int insertPrcSurcharge(PrcSurcharge surcharge);
public int updatePrcSurcharge(PrcSurcharge surcharge);
public int deletePrcSurchargeByIds(Long[] scIds);
/** 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd */
public int updateSsCodeByIds(@Param("scIds") Long[] scIds, @Param("ssCode") String ssCode, @Param("operator") String operator);
}
@@ -1,6 +1,7 @@
package com.ruoyi.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.price.domain.PrcSurchargeRel;
/**
@@ -21,4 +22,7 @@ public interface PrcSurchargeRelMapper
/** 删除产品时清理其关联 */
public int deleteRelByProductCodes(String[] productCodes);
/** 附加费版本化编辑后,把产品关联从旧记录重指向新记录 */
public int rebindRelScId(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId, @Param("operator") String operator);
}
@@ -85,6 +85,15 @@ public interface IPrcPriceSetService
/** submit async save, return taskId immediately */
public String submitSaveAsync(PrcPriceSet set);
/**
* Submit async batch write of detail surcharge snapshots (product-level pick can hit many rows).
* @return taskId for polling getSaveTask
*/
public String submitDetailSurchargeAsync(List<PrcPriceSetDetail> details);
/** Sync batch update of detail surcharge snapshots */
public int batchUpdateDetailSurcharges(List<PrcPriceSetDetail> details);
/** poll async save progress */
public PrcPriceSetSaveTask getSaveTask(String taskId);
}
@@ -6,6 +6,8 @@ import com.ruoyi.price.domain.PrcSurcharge;
/**
* 附加费配置 服务层
*
* 附加费为计费主数据:编辑=原记录作废+插入新记录(版本化),删除=仅作废不物理删除。
*
* @author ruoyi
*/
public interface IPrcSurchargeService
@@ -16,7 +18,12 @@ public interface IPrcSurchargeService
public int insertPrcSurcharge(PrcSurcharge surcharge);
/** 版本化更新:原记录作废(ss_code=vd),插入新记录,产品关联重指向新记录;状态继承原记录 */
public int updatePrcSurcharge(PrcSurcharge surcharge);
public int deletePrcSurchargeByIds(Long[] scIds);
/** 停用(原地修改 ss_code=of,不新增数据) */
public int disablePrcSurchargeByIds(Long[] scIds, String operator);
/** 启用(原地修改 ss_code=on,不新增数据) */
public int enablePrcSurchargeByIds(Long[] scIds, String operator);
}
@@ -125,6 +125,39 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
return taskId;
}
@Override
public String submitDetailSurchargeAsync(List<PrcPriceSetDetail> details)
{
String taskId = IdUtils.fastSimpleUUID();
saveAsyncRunner.put(taskId, PrcPriceSetSaveTask.STATUS_PENDING, 0, "queued", null, null);
saveAsyncRunner.runSurchargeBatch(taskId, details);
return taskId;
}
@Override
public int batchUpdateDetailSurcharges(List<PrcPriceSetDetail> details)
{
if (details == null || details.isEmpty())
{
return 0;
}
int rows = 0;
for (PrcPriceSetDetail detail : details)
{
if (detail == null || detail.getPsdId() == null)
{
continue;
}
// Always replace snapshot for this batch API (null would skip in updateDetail)
if (detail.getSurcharges() == null)
{
detail.setSurcharges(new ArrayList<PrcPriceSetVersionSurcharge>());
}
rows += updateDetail(detail);
}
return rows;
}
@Override
public PrcPriceSetSaveTask getSaveTask(String taskId)
{
@@ -3,24 +3,36 @@ package com.ruoyi.price.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcSurcharge;
import com.ruoyi.price.mapper.PrcSurchargeMapper;
import com.ruoyi.price.mapper.PrcSurchargeRelMapper;
import com.ruoyi.price.service.IPrcSurchargeService;
/**
* 附加费配置 服务层实现
*
* 附加费为计费主数据,不做物理修改/删除:
* - 编辑 = 原记录作废(ss_code=vd)+ 插入新记录(状态继承),产品关联重指向新记录(保留变更历史)
* - 停用 = 原地修改 ss_code=of,不新增数据
*
* @author ruoyi
*/
@Service
public class PrcSurchargeServiceImpl implements IPrcSurchargeService
{
/** 作废状态:区别于启用(on)/停用(of),列表默认不显示 */
public static final String SS_CODE_VOID = "vd";
@Autowired
private PrcSurchargeMapper surchargeMapper;
@Autowired
private PrcSurchargeRelMapper surchargeRelMapper;
@Override
public PrcSurcharge selectPrcSurchargeById(Long scId)
{
@@ -37,6 +49,106 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
public int insertPrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
applyInsertDefaults(surcharge);
return surchargeMapper.insertPrcSurcharge(surcharge);
}
/**
* 版本化更新:内容无变化时返回 -1(不产生新版本),否则原记录作废 + 插入新记录 + 产品关联重指向。
*/
@Override
@Transactional
public int updatePrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
PrcSurcharge old = surchargeMapper.selectPrcSurchargeById(surcharge.getScId());
if (old == null)
{
throw new ServiceException("附加费不存在或已被作废,无法修改");
}
// 无实际变化:不置作废、不插新记录,返回 -1 由 Controller 提示"未修改"
if (isUnchanged(old, surcharge))
{
return -1;
}
String operator = StringUtils.isNotEmpty(surcharge.getUpdateBy()) ? surcharge.getUpdateBy() : surcharge.getCreateBy();
// 1. 原记录作废(保留历史)
surchargeMapper.updateSsCodeByIds(new Long[] { surcharge.getScId() }, SS_CODE_VOID, operator);
// 2. 按表单内容插入新记录(状态继承原记录,状态变更只能走列表停用操作)
PrcSurcharge fresh = new PrcSurcharge();
fresh.setScName(surcharge.getScName());
fresh.setFeeType(StringUtils.isNotEmpty(surcharge.getFeeType()) ? surcharge.getFeeType() : old.getFeeType());
fresh.setChargeType(surcharge.getChargeType());
fresh.setChargeValue(surcharge.getChargeValue());
fresh.setCurrency(surcharge.getCurrency());
fresh.setRoundMode(surcharge.getRoundMode());
fresh.setSsCode(old.getSsCode());
fresh.setCountryCode(surcharge.getCountryCode());
fresh.setScNote(surcharge.getScNote());
applyInsertDefaults(fresh);
fresh.setCreateBy(operator);
int rows = surchargeMapper.insertPrcSurcharge(fresh);
// 3. 产品关联重指向新记录,保持产品附加费配置不失效
surchargeRelMapper.rebindRelScId(surcharge.getScId(), fresh.getScId(), operator);
return rows;
}
/** 逐字段比对编辑内容与原记录是否一致(字符串 trim 后比较,数值统一 BigDecimal 比较) */
private boolean isUnchanged(PrcSurcharge old, PrcSurcharge updated)
{
return eq(old.getScName(), updated.getScName())
&& eq(old.getFeeType(), updated.getFeeType())
&& eq(old.getChargeType(), updated.getChargeType())
&& eqDecimal(old.getChargeValue(), updated.getChargeValue())
&& eq(old.getCurrency(), updated.getCurrency())
&& eq(old.getRoundMode(), updated.getRoundMode())
&& eq(old.getCountryCode(), updated.getCountryCode())
&& eq(old.getScNote(), updated.getScNote());
}
private boolean eq(String a, String b)
{
String sa = a == null ? "" : a.trim();
String sb = b == null ? "" : b.trim();
return sa.equals(sb);
}
private boolean eqDecimal(java.math.BigDecimal a, java.math.BigDecimal b)
{
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return a.compareTo(b) == 0;
}
/**
* 停用(原地修改 ss_code=of,不新增数据、不动产品关联)。
*/
@Override
public int disablePrcSurchargeByIds(Long[] scIds, String operator)
{
return updateStatusByIds(scIds, "of", operator);
}
/**
* 启用(原地修改 ss_code=on,不新增数据)。
*/
@Override
public int enablePrcSurchargeByIds(Long[] scIds, String operator)
{
return updateStatusByIds(scIds, "on", operator);
}
private int updateStatusByIds(Long[] scIds, String ssCode, String operator)
{
if (scIds == null || scIds.length == 0)
{
return 0;
}
return surchargeMapper.updateSsCodeByIds(scIds, ssCode, operator);
}
private void applyInsertDefaults(PrcSurcharge surcharge)
{
if (StringUtils.isEmpty(surcharge.getSsCode()))
{
surcharge.setSsCode("on");
@@ -49,20 +161,6 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
{
surcharge.setRoundMode("HALF_UP");
}
return surchargeMapper.insertPrcSurcharge(surcharge);
}
@Override
public int updatePrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
return surchargeMapper.updatePrcSurcharge(surcharge);
}
@Override
public int deletePrcSurchargeByIds(Long[] scIds)
{
return surchargeMapper.deletePrcSurchargeByIds(scIds);
}
private void validate(PrcSurcharge surcharge)
@@ -1,5 +1,6 @@
package com.ruoyi.price.task;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -9,6 +10,7 @@ import org.springframework.stereotype.Component;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcPriceSet;
import com.ruoyi.price.domain.PrcPriceSetDetail;
import com.ruoyi.price.domain.PrcPriceSetSaveTask;
import com.ruoyi.price.service.IPrcPriceSetService;
@@ -51,6 +53,29 @@ public class PrcPriceSetSaveAsyncRunner
}
}
/** Background write of detail surcharge snapshots for many rows. */
@Async("threadPoolTaskExecutor")
public void runSurchargeBatch(String taskId, List<PrcPriceSetDetail> details)
{
try
{
put(taskId, PrcPriceSetSaveTask.STATUS_RUNNING, 10, "saving surcharges", null, null);
int rows = priceSetService.batchUpdateDetailSurcharges(details);
put(taskId, PrcPriceSetSaveTask.STATUS_SUCCESS, 100, "done", null, null);
log.info("async surcharge batch done, taskId={}, rows={}", taskId, rows);
}
catch (Exception e)
{
log.error("async surcharge batch failed, taskId={}", taskId, e);
String msg = e.getMessage();
if (StringUtils.isEmpty(msg))
{
msg = e.getClass().getSimpleName();
}
put(taskId, PrcPriceSetSaveTask.STATUS_FAIL, 100, "failed", null, msg);
}
}
public void put(String taskId, String status, int percent, String message, Long priceSetId, String error)
{
PrcPriceSetSaveTask task = new PrcPriceSetSaveTask();
@@ -161,7 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where d.psv_id = #{psvId}
and ifnull(s.sc_name, '') &lt;&gt; ''
and s.charge_value is not null
and lower(ifnull(s.ss_code, '')) &lt;&gt; 'of'
and lower(ifnull(s.ss_code, '')) not in ('of', 'vd')
and (r.detail_id is null or r.detail_id = d.product_country_id)
and (
s.country_code is null or s.country_code = ''
@@ -48,9 +48,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="roundMode != null and roundMode != ''">
AND round_mode = #{roundMode}
</if>
<if test="ssCode != null and ssCode != ''">
AND ss_code = #{ssCode}
</if>
<choose>
<when test="ssCode != null and ssCode != ''">
AND lower(ss_code) = lower(#{ssCode})
</when>
<otherwise>
<!-- 默认排除已作废记录,可在状态筛选中选择作废查看历史 -->
AND lower(ifnull(ss_code, '')) &lt;&gt; 'vd'
</otherwise>
</choose>
<if test="countryCode != null and countryCode != ''">
AND country_code = #{countryCode}
</if>
@@ -91,30 +97,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</insert>
<update id="updatePrcSurcharge" parameterType="PrcSurcharge">
<!-- 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd -->
<update id="updateSsCodeByIds">
update prc_surcharge
<set>
<if test="scName != null and scName != ''">sc_name = #{scName},</if>
<if test="feeType != null and feeType != ''">fee_type = #{feeType},</if>
<if test="chargeType != null and chargeType != ''">charge_type = #{chargeType},</if>
<if test="chargeValue != null">charge_value = #{chargeValue},</if>
<if test="currency != null and currency != ''">currency = #{currency},</if>
<if test="roundMode != null and roundMode != ''">round_mode = #{roundMode},</if>
<if test="ssCode != null and ssCode != ''">ss_code = #{ssCode},</if>
country_code = #{countryCode},
<if test="scNote != null">sc_note = #{scNote},</if>
<if test="tmsId != null">tms_id = #{tmsId},</if>
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
update_time = sysdate()
</set>
where sc_id = #{scId}
</update>
<delete id="deletePrcSurchargeByIds" parameterType="Long">
delete from prc_surcharge where sc_id in
<foreach item="scId" collection="array" open="(" separator="," close=")">
set ss_code = #{ssCode}, updated_by = #{operator}, update_time = sysdate()
where sc_id in
<foreach item="scId" collection="scIds" open="(" separator="," close=")">
#{scId}
</foreach>
</delete>
</update>
</mapper>
@@ -81,4 +81,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<!-- 附加费版本化编辑后,产品关联重指向新记录 -->
<update id="rebindRelScId">
update prc_surcharge_rel
set sc_id = #{newScId}, updated_by = #{operator}, update_time = sysdate()
where sc_id = #{oldScId}
</update>
</mapper>
+35
View File
@@ -197,6 +197,41 @@ export function updateSetDetail(data) {
})
}
/**
* Submit async batch write of detail surcharge snapshots and poll until done.
* @returns {Promise<{ task: object }>}
*/
export async function updateSetDetailSurchargeAsync(details, onProgress) {
const submitRes = await request({
url: '/price/set/detail/surcharge/async',
method: 'post',
data: details || []
})
const taskId = pickSaveTaskId(submitRes)
if (!taskId) {
throw new Error('missing surcharge taskId')
}
const started = Date.now()
const maxMs = 30 * 60 * 1000
while (Date.now() - started < maxMs) {
const res = await getPriceSetSaveTask(taskId)
const task = res.data || {}
if (typeof onProgress === 'function') {
onProgress(task)
}
if (task.status === 'SUCCESS') {
return { task }
}
if (task.status === 'FAIL') {
const err = new Error(task.error || task.message || 'surcharge save failed')
err.task = task
throw err
}
await new Promise(resolve => setTimeout(resolve, 800))
}
throw new Error('surcharge save timeout')
}
export function delSetDetail(psdIds) {
return request({
url: '/price/set/detail/' + psdIds,
+12 -4
View File
@@ -71,10 +71,18 @@ export function updateSurcharge(data) {
})
}
/** 删除附加费配置 */
export function delSurcharge(scIds) {
/** 停用附加费配置(原地修改 ss_code=of,不新增数据、不物理删除) */
export function disableSurcharge(scIds) {
return request({
url: '/price/surcharge/' + scIds,
method: 'delete'
url: '/price/surcharge/disable/' + scIds,
method: 'put'
})
}
/** 启用附加费配置(原地修改 ss_code=on,不新增数据) */
export function enableSurcharge(scIds) {
return request({
url: '/price/surcharge/enable/' + scIds,
method: 'put'
})
}
@@ -19,9 +19,6 @@
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['price:product:add']">新建产品</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" :disabled="selection.length !== 1 || (selection[0] && isProductActive(selection[0]))" @click="handleUpdate(selection[0])" v-hasPermi="['price:product:edit']">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="info" plain icon="Upload" @click="handleImport" v-hasPermi="['price:product:import']">导入 Excel</el-button>
</el-col>
@@ -100,16 +100,6 @@ const schemas = computed(() => [
width: '100%',
props: { filterable: true, clearable: true }
},
{
label: "状态",
prop: 'ssCode',
component: 'radio',
span: 12,
options: [
{ label: "有效", value: 'on' },
{ label: "停用", value: 'of' }
]
},
{
label: "备注",
prop: 'scNote',
@@ -130,7 +120,6 @@ function emptyForm() {
chargeValue: undefined,
currency: 'CNY',
roundMode: 'HALF_UP',
ssCode: 'on',
countryCode: undefined,
scNote: undefined
}
@@ -163,7 +152,6 @@ function open(row) {
}
getSurcharge(row.scId).then(res => {
const data = res.data || {}
if (data.ssCode) data.ssCode = String(data.ssCode).toLowerCase()
form.value = { ...emptyForm(), ...data }
title.value = "修改附加费"
visible.value = true
@@ -182,6 +170,8 @@ function submitForm() {
proxy.$modal.msgSuccess(payload.scId != null ? "修改成功" : "新增成功")
visible.value = false
emit('success')
}).catch(() => {
// 后端返回 warn(601「未做任何修改」) 时由全局拦截器弹提示,此处吞掉 reject
})
})
}
@@ -0,0 +1,149 @@
<template>
<el-drawer v-model="visible" size="960px" title="作废附加费记录" append-to-body>
<el-form :inline="true" @submit.prevent>
<el-form-item label="附加费名称">
<el-input
v-model="queryParams.scName"
placeholder="请输入名称"
clearable
style="width: 200px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="list" border max-height="calc(100vh - 300px)" empty-text="暂无作废记录">
<el-table-column label="附加费名称" prop="scName" min-width="140" show-overflow-tooltip />
<el-table-column label="费用类型" width="90" align="center">
<template #default="{ row }">{{ feeTypeLabel(row.feeType) }}</template>
</el-table-column>
<el-table-column label="计费方式" width="110" align="center">
<template #default="{ row }">{{ chargeTypeLabel(row.chargeType) }}</template>
</el-table-column>
<el-table-column label="计费数值" width="130" align="right">
<template #default="{ row }">
<span class="charge-value">{{ formatChargeValue(row) }}</span>
</template>
</el-table-column>
<el-table-column label="取值方式" width="100" align="center">
<template #default="{ row }">{{ roundModeLabel(row.roundMode) }}</template>
</el-table-column>
<el-table-column label="适用国家" width="110" align="center">
<template #default="{ row }">{{ countryLabel(row.countryCode) }}</template>
</el-table-column>
<el-table-column label="状态" width="80" align="center">
<template #default>
<el-tag type="danger" size="small">作废</el-tag>
</template>
</el-table-column>
<el-table-column label="备注" prop="scNote" min-width="120" show-overflow-tooltip />
<el-table-column label="创建时间" width="160" align="center">
<template #default="{ row }">{{ timeStr(row.createTime) }}</template>
</el-table-column>
<el-table-column label="作废时间" width="160" align="center">
<template #default="{ row }">{{ timeStr(row.updateTime) }}</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="loadList"
/>
</el-drawer>
</template>
<script setup>
import { onMounted } from 'vue'
import { listSurcharge } from '@/api/price/surcharge'
import { listRegionOptions } from '@/api/data/region'
// 只读抽屉:查看已被版本化编辑淘汰的作废记录(ss_code = vd)
const { proxy } = getCurrentInstance()
const { bms_charge_type, bms_round_mode, bms_fee_type } = useDict('bms_charge_type', 'bms_round_mode', 'bms_fee_type')
const visible = ref(false)
const loading = ref(false)
const list = ref([])
const total = ref(0)
const regionOptions = ref([])
const queryParams = ref({ pageNum: 1, pageSize: 10, scName: undefined })
function open() {
visible.value = true
resetQuery()
}
function loadList() {
loading.value = true
listSurcharge({ ...queryParams.value, ssCode: 'vd' }).then(res => {
list.value = res.rows || []
total.value = res.total || 0
}).finally(() => {
loading.value = false
})
}
function handleQuery() {
queryParams.value.pageNum = 1
loadList()
}
function resetQuery() {
queryParams.value = { pageNum: 1, pageSize: 10, scName: undefined }
loadList()
}
function feeTypeLabel(val) {
const found = bms_fee_type.value.find(d => d.value === val)
return found ? found.label : (val || '-')
}
function chargeTypeLabel(val) {
const found = bms_charge_type.value.find(d => d.value === val)
return found ? found.label : (val || '-')
}
function roundModeLabel(val) {
const found = bms_round_mode.value.find(d => d.value === val)
return found ? found.label : (val || '-')
}
function formatChargeValue(row) {
if (row.chargeValue == null) return '-'
const v = Number(row.chargeValue)
if (row.chargeType === 'RATE') return (v * 100).toFixed(2) + '%'
return v + ' ' + (row.currency || 'CNY')
}
function countryLabel(code) {
if (!code) return '全部'
const found = regionOptions.value.find(r => r.countryCode2 === code)
return found ? (found.countryNameCn || found.countryNameEn || code) : code
}
function timeStr(val) {
return val ? proxy.parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}') : '-'
}
onMounted(() => {
listRegionOptions().then(res => {
regionOptions.value = res.data || []
})
})
defineExpose({ open })
</script>
<style scoped>
.charge-value {
font-weight: 600;
color: #d63031;
}
</style>
@@ -7,7 +7,7 @@
:query="queryList"
row-key="scId"
>
<template #toolbar="{ selection, ids }">
<template #toolbar>
<el-col :span="1.5">
<el-button
type="primary"
@@ -19,30 +19,16 @@
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="selection.length !== 1"
@click="handleUpdate(selection[0])"
v-hasPermi="['price:surcharge:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="!selection.length"
@click="handleDelete(ids)"
v-hasPermi="['price:surcharge:remove']"
>删除</el-button>
icon="View"
@click="voidDrawerRef.open()"
v-hasPermi="['price:surcharge:list']"
>作废记录</el-button>
</el-col>
</template>
<template #col-ssCode="{ row }">
<el-tag :type="(row.ssCode || '').toLowerCase() === 'on' ? 'success' : 'warning'" size="small">
{{ (row.ssCode || '').toLowerCase() === 'on' ? '有效' : '停用' }}
</el-tag>
<el-tag :type="ssInfo(row.ssCode).type" size="small">{{ ssInfo(row.ssCode).label }}</el-tag>
</template>
<template #col-chargeType="{ row }">
@@ -59,17 +45,34 @@
<template #col-action="{ row }">
<el-button link type="primary" icon="Edit" @click="handleUpdate(row)" v-hasPermi="['price:surcharge:edit']">编辑</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(row.scId)" v-hasPermi="['price:surcharge:remove']">删除</el-button>
<el-button
v-if="String(row.ssCode || '').toLowerCase() === 'on'"
link
type="danger"
icon="CircleClose"
@click="handleDisable(row.scId)"
v-hasPermi="['price:surcharge:remove']"
>停用</el-button>
<el-button
v-if="String(row.ssCode || '').toLowerCase() === 'of'"
link
type="success"
icon="CircleCheck"
@click="handleEnable(row.scId)"
v-hasPermi="['price:surcharge:remove']"
>启用</el-button>
</template>
</basic-table>
<surcharge-form-dialog ref="formDialogRef" @success="() => tableRef.refresh()" />
<surcharge-void-drawer ref="voidDrawerRef" />
</div>
</template>
<script setup name="PriceSurcharge">
import { listSurcharge, delSurcharge } from '@/api/price/surcharge'
import { listSurcharge, disableSurcharge, enableSurcharge } from '@/api/price/surcharge'
import SurchargeFormDialog from './components/SurchargeFormDialog.vue'
import SurchargeVoidDrawer from './components/SurchargeVoidDrawer.vue'
import { listRegionOptions } from '@/api/data/region'
import { onMounted } from 'vue'
@@ -78,6 +81,7 @@ const { bms_charge_type } = useDict('bms_charge_type')
const tableRef = ref()
const formDialogRef = ref()
const voidDrawerRef = ref()
const regionOptions = ref([])
const columns = [
@@ -110,7 +114,8 @@ const searchColumns = [
component: 'select',
options: [
{ label: '有效', value: 'on' },
{ label: '停用', value: 'of' }
{ label: '停用', value: 'of' },
{ label: '作废', value: 'vd' }
],
placeholder: '状态',
width: '120px'
@@ -159,15 +164,35 @@ function handleUpdate(row) {
formDialogRef.value.open(row)
}
function handleDelete(ids) {
function handleDisable(ids) {
const idText = Array.isArray(ids) ? ids.join(',') : ids
proxy.$modal.confirm('是否确认删除所选附加费配置?').then(() => {
return delSurcharge(idText)
proxy.$modal.confirm('是否确认停用所选附加费?停用后不再参与计费,可再启用恢复').then(() => {
return disableSurcharge(idText)
}).then(() => {
proxy.$modal.msgSuccess('删除成功')
proxy.$modal.msgSuccess('停用成功')
tableRef.value.refresh()
}).catch(() => {})
}
function handleEnable(ids) {
const idText = Array.isArray(ids) ? ids.join(',') : ids
proxy.$modal.confirm('是否确认启用所选附加费?启用后重新参与计费').then(() => {
return enableSurcharge(idText)
}).then(() => {
proxy.$modal.msgSuccess('启用成功')
tableRef.value.refresh()
}).catch(() => {})
}
// 状态三态:on 有效 / of 停用 / vd 作废
function ssInfo(code) {
const map = {
on: { label: '有效', type: 'success' },
of: { label: '停用', type: 'warning' },
vd: { label: '作废', type: 'danger' }
}
return map[String(code || '').toLowerCase()] || { label: code || '-', type: 'info' }
}
</script>
<style scoped>
@@ -73,7 +73,7 @@
</el-table-column>
<el-table-column :label="colSurcharge" width="110" align="center">
<template #default="{ row }">
<surcharge-count-cell :list="row.surcharges || []" @click="pickSurcharge(row)" />
<surcharge-count-cell :list="row.surcharges || []" @remove="s => removeSurcharge(row, s)" />
</template>
</el-table-column>
<el-table-column :label="colAction" width="90" align="center">
@@ -97,7 +97,7 @@ const props = defineProps({
productName: { type: String, default: '' },
rows: { type: Array, default: () => [] }
})
const emit = defineEmits(['update:modelValue', 'pick-surcharge', 'row-change'])
const emit = defineEmits(['update:modelValue', 'pick-surcharge', 'row-change', 'surcharge-change'])
const { proxy } = getCurrentInstance()
@@ -187,6 +187,14 @@ function pickSurcharge(row) {
emit('pick-surcharge', row || null)
}
function removeSurcharge(row, sc) {
if (!row || !sc || sc.scId == null) return
const scId = String(sc.scId)
const next = (row.surcharges || []).filter(s => s && String(s.scId) !== scId)
row.surcharges = next
emit('surcharge-change', row)
}
function countryKey(row) {
return String(row.countryCode || row.countryName || '').toUpperCase()
}
@@ -30,16 +30,11 @@
</template>
</el-table-column>
<el-table-column :label="colRegion" prop="destRegion" width="90" align="center" />
<el-table-column :label="colTax" width="90" align="center">
<!-- <el-table-column :label="colTax" width="90" align="center">
<template #default="{ row }">
<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> -->
<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 },
@@ -119,8 +114,7 @@ const colName = '产品名称'
const colLevel = '时效等级'
const colCargo = '走货属性'
const colRegion = '目的区域'
const colTax = '税模式'
const colSurcharge = '附加费'
// const colTax = '税模式'
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 : '附加费后台写入失败')
})
}
@@ -5,38 +5,49 @@
placement="top"
:width="380"
trigger="hover"
:hide-after="120"
>
<template #default>
<div class="sc-count__pop-title">已纳入 {{ list.length }} 项附加费</div>
<surcharge-tags :list="list" :popover="false" empty-text="-" />
<div class="sc-count__tags">
<el-tag
v-for="s in list"
:key="s.relId || s.scId || s.scName"
size="small"
type="danger"
effect="plain"
closable
@click.stop
@close="onRemove(s)"
>{{ surchargeTagLabel(s) }}</el-tag>
</div>
</template>
<template #reference>
<el-link type="primary" :underline="false" @click="emit('click')">
{{ list.length }} 项
</el-link>
<span class="sc-count__text">{{ list.length }} 项</span>
</template>
</el-popover>
<el-link v-else type="info" :underline="false" @click="emit('click')">0</el-link>
<span v-else class="sc-count__text is-empty">0</span>
</div>
</template>
<script setup name="SurchargeCountCell">
/**
* 套餐 · 附加费数量单元格(新建第 3 步产品列表 / 价格编辑抽屉共用)
*
* 显示当前数量(默认 0);hover 气泡看具体是哪几项,点击进入勾选弹窗调整。
* Hover shows included surcharges; closable tag removes one item from the row.
*/
import SurchargeTags from '../SurchargeTags.vue'
import { surchargeTagLabel } from '../../utils/priceSet'
defineProps({
/** 该行 / 该产品当前纳入的附加费列表 */
list: {
type: Array,
default: () => []
}
})
const emit = defineEmits(['click'])
const emit = defineEmits(['remove'])
function onRemove(s) {
emit('remove', s)
}
</script>
<style scoped>
@@ -45,10 +56,23 @@ const emit = defineEmits(['click'])
align-items: center;
gap: 4px;
}
.sc-count__text {
color: var(--el-color-primary);
cursor: default;
font-size: 13px;
}
.sc-count__text.is-empty {
color: var(--el-text-color-secondary);
}
.sc-count__pop-title {
margin-bottom: 6px;
font-size: 12px;
font-weight: 600;
color: #606266;
}
.sc-count__tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
</style>