mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
Compare commits
4
Commits
e47f76c22a
...
abe75f87aa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abe75f87aa | ||
|
|
7781f53d8a | ||
|
|
5427b3830c | ||
|
|
f382ba9bd7 |
+4
-2
@@ -74,8 +74,10 @@ public class ExpressQuoteController {
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "报价详情", allowSuper = true)
|
||||
public ApiResponse<ExpressQuoteVO> detail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", expressQuoteService.detail(id));
|
||||
public ApiResponse<ExpressQuoteVO> detail(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(value = "withHistory", defaultValue = "false") boolean withHistory) {
|
||||
return ApiResponse.success("获取成功", expressQuoteService.detail(id, withHistory));
|
||||
}
|
||||
|
||||
@PostMapping("/{quoteId}/version")
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class ExpressQuoteImportService {
|
||||
}
|
||||
expressQuoteService.requireCompanyQuote(params.getQuoteId());
|
||||
expressQuoteService.upsertVersion(params.getQuoteId(), toVersionDto(draft));
|
||||
return expressQuoteService.detail(params.getQuoteId());
|
||||
return expressQuoteService.detail(params.getQuoteId(), false);
|
||||
}
|
||||
throw new BusinessException("不支持的导入模式: " + params.getMode());
|
||||
}
|
||||
|
||||
+6
-1
@@ -21,7 +21,12 @@ public interface ExpressQuoteService {
|
||||
|
||||
List<ExpressQuoteVO> listEnabled();
|
||||
|
||||
ExpressQuoteVO detail(Long id);
|
||||
/**
|
||||
* 报价详情。
|
||||
*
|
||||
* @param withHistory true=加载全部版本的分区/重量带(详情抽屉);false=仅当前版本明细(编辑页)
|
||||
*/
|
||||
ExpressQuoteVO detail(Long id, boolean withHistory);
|
||||
|
||||
ExpressQuotePO requireCompanyQuote(Long id);
|
||||
|
||||
|
||||
+76
-18
@@ -35,7 +35,9 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -91,7 +93,7 @@ public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, Exp
|
||||
if (dto.getInitialVersion() != null) {
|
||||
upsertVersionInternal(po, dto.getInitialVersion());
|
||||
}
|
||||
return detail(po.getId());
|
||||
return detail(po.getId(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +109,7 @@ public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, Exp
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
updateById(po);
|
||||
markDirtyForQuote(po.getId(), null);
|
||||
return detail(id);
|
||||
return detail(id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,20 +168,58 @@ public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, Exp
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressQuoteVO detail(Long id) {
|
||||
public ExpressQuoteVO detail(Long id, boolean withHistory) {
|
||||
ExpressQuotePO po = requireCompanyQuote(id);
|
||||
ExpressQuoteVO vo = toBriefVo(po);
|
||||
ExpressQuoteVO vo = new ExpressQuoteVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
|
||||
List<ExpressQuoteVersionPO> versions = versionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, id)
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom));
|
||||
List<ExpressQuoteVO.VersionVO> versionVos = new ArrayList<>();
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||
.orderByDesc(ExpressQuoteVersionPO::getId));
|
||||
if (versions.isEmpty()) {
|
||||
return vo;
|
||||
}
|
||||
|
||||
// 编辑页只要当前版本明细;详情抽屉再拉全历史分区(避免 N 版 × 2 次查询)
|
||||
List<ExpressQuoteVersionPO> versionsToExpand = withHistory
|
||||
? versions
|
||||
: List.of(versions.get(0));
|
||||
List<Long> expandIds = versionsToExpand.stream().map(ExpressQuoteVersionPO::getId).toList();
|
||||
|
||||
Map<Long, List<ExpressQuoteRegionPO>> regionsByVersion = Map.of();
|
||||
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion = Map.of();
|
||||
if (!expandIds.isEmpty()) {
|
||||
List<ExpressQuoteRegionPO> allRegions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.in(ExpressQuoteRegionPO::getVersionId, expandIds)
|
||||
.orderByAsc(ExpressQuoteRegionPO::getSortOrder)
|
||||
.orderByAsc(ExpressQuoteRegionPO::getId));
|
||||
regionsByVersion = allRegions.stream()
|
||||
.collect(Collectors.groupingBy(ExpressQuoteRegionPO::getVersionId, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
List<Long> regionIds = allRegions.stream().map(ExpressQuoteRegionPO::getId).toList();
|
||||
if (!regionIds.isEmpty()) {
|
||||
List<ExpressQuoteBandPO> allBands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||
.in(ExpressQuoteBandPO::getRegionId, regionIds)
|
||||
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||
.orderByAsc(ExpressQuoteBandPO::getWeightFromG)
|
||||
.orderByAsc(ExpressQuoteBandPO::getId));
|
||||
bandsByRegion = allBands.stream()
|
||||
.collect(Collectors.groupingBy(ExpressQuoteBandPO::getRegionId, LinkedHashMap::new, Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
List<ExpressQuoteVO.VersionVO> versionVos = new ArrayList<>(versions.size());
|
||||
for (ExpressQuoteVersionPO v : versions) {
|
||||
versionVos.add(toVersionVo(v, true));
|
||||
boolean expand = expandIds.contains(v.getId());
|
||||
versionVos.add(toVersionVo(
|
||||
v,
|
||||
expand,
|
||||
expand ? regionsByVersion.getOrDefault(v.getId(), List.of()) : List.of(),
|
||||
expand ? bandsByRegion : Map.of()));
|
||||
}
|
||||
vo.setVersions(versionVos);
|
||||
if (!versionVos.isEmpty()) {
|
||||
vo.setCurrentVersion(versionVos.get(0));
|
||||
}
|
||||
vo.setCurrentVersion(versionVos.get(0));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -459,20 +499,38 @@ public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, Exp
|
||||
}
|
||||
|
||||
private ExpressQuoteVO.VersionVO toVersionVo(ExpressQuoteVersionPO v, boolean withRegions) {
|
||||
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||
BeanCopyUtils.copyProperties(v, vo);
|
||||
if (!withRegions) {
|
||||
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||
BeanCopyUtils.copyProperties(v, vo);
|
||||
return vo;
|
||||
}
|
||||
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, v.getId())
|
||||
.orderByAsc(ExpressQuoteRegionPO::getSortOrder));
|
||||
List<ExpressQuoteBandPO> bands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||
.eq(ExpressQuoteBandPO::getVersionId, v.getId())
|
||||
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||
.orderByAsc(ExpressQuoteBandPO::getWeightFromG));
|
||||
var bandsByRegion = bands.stream().collect(Collectors.groupingBy(ExpressQuoteBandPO::getRegionId));
|
||||
List<ExpressQuoteVO.RegionVO> regionVos = new ArrayList<>();
|
||||
List<Long> regionIds = regions.stream().map(ExpressQuoteRegionPO::getId).toList();
|
||||
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion = Map.of();
|
||||
if (!regionIds.isEmpty()) {
|
||||
List<ExpressQuoteBandPO> bands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||
.in(ExpressQuoteBandPO::getRegionId, regionIds)
|
||||
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||
.orderByAsc(ExpressQuoteBandPO::getWeightFromG));
|
||||
bandsByRegion = bands.stream().collect(Collectors.groupingBy(ExpressQuoteBandPO::getRegionId));
|
||||
}
|
||||
return toVersionVo(v, true, regions, bandsByRegion);
|
||||
}
|
||||
|
||||
/** 用预取的分区/重量带组装,避免详情 N+1 */
|
||||
private ExpressQuoteVO.VersionVO toVersionVo(
|
||||
ExpressQuoteVersionPO v,
|
||||
boolean withRegions,
|
||||
List<ExpressQuoteRegionPO> regions,
|
||||
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion) {
|
||||
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||
BeanCopyUtils.copyProperties(v, vo);
|
||||
if (!withRegions) {
|
||||
return vo;
|
||||
}
|
||||
List<ExpressQuoteVO.RegionVO> regionVos = new ArrayList<>(regions.size());
|
||||
for (ExpressQuoteRegionPO r : regions) {
|
||||
ExpressQuoteVO.RegionVO rv = new ExpressQuoteVO.RegionVO();
|
||||
rv.setId(r.getId());
|
||||
|
||||
@@ -23,9 +23,14 @@ export async function getEnabledExpressQuotesApi() {
|
||||
return requestClient.get<ExpressQuoteVO.Info[]>('/ec/express-quote/enabled');
|
||||
}
|
||||
|
||||
export async function getExpressQuoteDetailApi(id: number) {
|
||||
/** withHistory:详情抽屉拉全版本分区;编辑页默认 false 仅当前版本明细 */
|
||||
export async function getExpressQuoteDetailApi(
|
||||
id: number,
|
||||
withHistory = false,
|
||||
) {
|
||||
return requestClient.get<ExpressQuoteVO.Info>(
|
||||
`/ec/express-quote/detail/${id}`,
|
||||
{ params: { withHistory } },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ async function open(id: number) {
|
||||
loading.value = true;
|
||||
detail.value = null;
|
||||
try {
|
||||
detail.value = await getExpressQuoteDetailApi(id);
|
||||
detail.value = await getExpressQuoteDetailApi(id, true);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('加载报价详情失败');
|
||||
|
||||
+180
-57
@@ -1,11 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 分区×重量带编辑:动态嵌套用 antd Card/Table;左侧 Anchor 快速跳转分区。
|
||||
* 分区×重量带编辑:左侧分区导航(可选进入拖拽排序)+ 右侧分区卡片。
|
||||
* 排序落库用数组下标 → sortOrder(表字段已有)。
|
||||
*/
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
import type { Sortable } from '@vben/hooks';
|
||||
|
||||
import { computed, nextTick, onBeforeUnmount, ref } from 'vue';
|
||||
|
||||
import { useSortable } from '@vben/hooks';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Anchor,
|
||||
Button,
|
||||
Card,
|
||||
Input,
|
||||
@@ -17,23 +22,10 @@ import {
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
export interface BandRow {
|
||||
weightFromG: number;
|
||||
weightToG: number | null;
|
||||
priceMode: string;
|
||||
flatAmount: number;
|
||||
firstWeightG: number;
|
||||
firstAmount: number;
|
||||
continuePerKg: number;
|
||||
}
|
||||
import { createRegionUid, type BandRow, type RegionRow } from './region-band';
|
||||
|
||||
export interface RegionRow {
|
||||
regionName: string;
|
||||
zoneLabel: string;
|
||||
provinces: string[];
|
||||
isDefault: boolean;
|
||||
bands: BandRow[];
|
||||
}
|
||||
/** 分区导航拖拽手柄 */
|
||||
const GripVerticalIcon = createIconifyIcon('lucide:grip-vertical');
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: RegionRow[];
|
||||
@@ -47,24 +39,24 @@ const emit = defineEmits<{
|
||||
defineOptions({ name: 'RegionBandEditor' });
|
||||
|
||||
const scrollRef = ref<HTMLElement | null>(null);
|
||||
const navListRef = ref<HTMLElement | null>(null);
|
||||
let navSortable: Sortable | null = null;
|
||||
|
||||
/** 是否处于拖拽排序模式 */
|
||||
const sorting = ref(false);
|
||||
/** 排序草稿,确定后写回 model;取消则丢弃 */
|
||||
const draftRegions = ref<RegionRow[]>([]);
|
||||
|
||||
const regions = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v),
|
||||
});
|
||||
|
||||
const anchorItems = computed(() =>
|
||||
regions.value.map((r, i) => ({
|
||||
key: `region-${i}`,
|
||||
href: `#quote-region-${i}`,
|
||||
title: r.zoneLabel || r.regionName || `分区${i + 1}`,
|
||||
})),
|
||||
/** 导航列表数据源:排序中用草稿,否则用正式数据 */
|
||||
const navRegions = computed(() =>
|
||||
sorting.value ? draftRegions.value : regions.value,
|
||||
);
|
||||
|
||||
function getScrollContainer() {
|
||||
return scrollRef.value || window;
|
||||
}
|
||||
|
||||
const bandColumnDefs = [
|
||||
{ title: '从(克)', key: 'from', width: 110 },
|
||||
{ title: '到(克)', key: 'to', width: 110 },
|
||||
@@ -85,11 +77,87 @@ function emptyBand(fromG = 0): BandRow {
|
||||
};
|
||||
}
|
||||
|
||||
function scrollToRegion(uid: string) {
|
||||
if (sorting.value) return;
|
||||
document
|
||||
.getElementById(`quote-region-${uid}`)
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
function destroyNavSortable() {
|
||||
navSortable?.destroy();
|
||||
navSortable = null;
|
||||
}
|
||||
|
||||
/** 进入排序后再绑 Sortable,避免默认态误拖、也避免 ref 未挂载 */
|
||||
async function initNavSortable() {
|
||||
destroyNavSortable();
|
||||
await nextTick();
|
||||
const el = navListRef.value;
|
||||
if (!el || draftRegions.value.length < 2) return;
|
||||
const { initializeSortable } = useSortable(el, {
|
||||
animation: 200,
|
||||
delay: 0,
|
||||
handle: '.region-nav-drag-handle',
|
||||
draggable: '.region-nav-item',
|
||||
onEnd(evt) {
|
||||
const { oldIndex, newIndex } = evt;
|
||||
if (
|
||||
oldIndex == null ||
|
||||
newIndex == null ||
|
||||
oldIndex === newIndex ||
|
||||
Number.isNaN(oldIndex) ||
|
||||
Number.isNaN(newIndex)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const list = [...draftRegions.value];
|
||||
const [moved] = list.splice(oldIndex, 1);
|
||||
if (!moved) return;
|
||||
list.splice(newIndex, 0, moved);
|
||||
draftRegions.value = list;
|
||||
// Vue 按 uid 重排 DOM 后需重绑,否则下次拖拽失效
|
||||
void initNavSortable();
|
||||
},
|
||||
});
|
||||
navSortable = await initializeSortable();
|
||||
}
|
||||
|
||||
async function enterSortMode() {
|
||||
if (regions.value.length < 2) {
|
||||
message.warning('至少两个分区才能排序');
|
||||
return;
|
||||
}
|
||||
draftRegions.value = regions.value.map((r) => ({ ...r }));
|
||||
sorting.value = true;
|
||||
await initNavSortable();
|
||||
}
|
||||
|
||||
function confirmSort() {
|
||||
regions.value = draftRegions.value.map((r) => ({ ...r }));
|
||||
destroyNavSortable();
|
||||
sorting.value = false;
|
||||
draftRegions.value = [];
|
||||
}
|
||||
|
||||
function cancelSort() {
|
||||
destroyNavSortable();
|
||||
sorting.value = false;
|
||||
draftRegions.value = [];
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
destroyNavSortable();
|
||||
});
|
||||
|
||||
function addRegion() {
|
||||
if (sorting.value) return;
|
||||
const uid = createRegionUid();
|
||||
const nextIndex = regions.value.length;
|
||||
regions.value = [
|
||||
...regions.value,
|
||||
{
|
||||
uid,
|
||||
regionName: `分区${nextIndex + 1}`,
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
@@ -97,14 +165,11 @@ function addRegion() {
|
||||
bands: [emptyBand(0)],
|
||||
},
|
||||
];
|
||||
void nextTick(() => {
|
||||
document
|
||||
.getElementById(`quote-region-${nextIndex}`)
|
||||
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
});
|
||||
void nextTick(() => scrollToRegion(uid));
|
||||
}
|
||||
|
||||
function removeRegion(idx: number) {
|
||||
if (sorting.value) return;
|
||||
if (regions.value.length <= 1) {
|
||||
message.warning('至少保留一个分区');
|
||||
return;
|
||||
@@ -149,17 +214,13 @@ function patchBand(ri: number, bi: number, patch: Partial<BandRow>) {
|
||||
const bands = region.bands.map((b, i) => (i === bi ? { ...b, ...patch } : b));
|
||||
patchRegion(ri, { bands });
|
||||
}
|
||||
|
||||
function onAnchorClick(e: Event) {
|
||||
e.preventDefault();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
size="small"
|
||||
title="目的分区 × 重量带"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
class="eq-panel-card flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="{
|
||||
flex: '1 1 0%',
|
||||
minHeight: 0,
|
||||
@@ -170,31 +231,93 @@ function onAnchorClick(e: Event) {
|
||||
}"
|
||||
>
|
||||
<template #extra>
|
||||
<Button size="small" type="dashed" @click="addRegion">添加分区</Button>
|
||||
</template>
|
||||
<div class="flex min-h-0 flex-1 gap-3">
|
||||
<aside
|
||||
class="w-36 shrink-0 overflow-y-auto border-r border-border pr-2 pt-1"
|
||||
<Button
|
||||
size="small"
|
||||
type="dashed"
|
||||
:disabled="sorting"
|
||||
@click="addRegion"
|
||||
>
|
||||
<div class="mb-2 text-xs text-muted-foreground">分区导航</div>
|
||||
<Anchor
|
||||
:affix="false"
|
||||
:items="anchorItems"
|
||||
:get-container="getScrollContainer"
|
||||
@click="onAnchorClick"
|
||||
/>
|
||||
添加分区
|
||||
</Button>
|
||||
</template>
|
||||
<div class="flex min-h-0 flex-1 gap-3 overflow-hidden">
|
||||
<aside
|
||||
class="w-44 shrink-0 overflow-y-auto border-r border-border pr-2 pt-1"
|
||||
>
|
||||
<div class="mb-2 flex items-center justify-between gap-1">
|
||||
<span class="text-xs text-muted-foreground">分区导航</span>
|
||||
<template v-if="sorting">
|
||||
<Space :size="4">
|
||||
<Button size="small" type="link" @click="cancelSort">取消</Button>
|
||||
<Button size="small" type="link" @click="confirmSort">
|
||||
确定
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
<Button
|
||||
v-else
|
||||
size="small"
|
||||
type="link"
|
||||
class="!px-0"
|
||||
:disabled="regions.length < 2"
|
||||
@click="enterSortMode"
|
||||
>
|
||||
调整顺序
|
||||
</Button>
|
||||
</div>
|
||||
<div
|
||||
v-if="sorting"
|
||||
class="mb-1 text-xs text-muted-foreground"
|
||||
>
|
||||
拖动手柄调整,完成后点确定
|
||||
</div>
|
||||
<div ref="navListRef" class="flex flex-col gap-0.5">
|
||||
<div
|
||||
v-for="(region, ri) in navRegions"
|
||||
:key="region.uid"
|
||||
class="region-nav-item flex items-center gap-1 rounded px-1 py-1 text-sm hover:bg-muted/50"
|
||||
:class="sorting ? 'bg-muted/30' : undefined"
|
||||
>
|
||||
<span
|
||||
v-if="sorting"
|
||||
class="region-nav-drag-handle shrink-0 cursor-grab text-muted-foreground active:cursor-grabbing"
|
||||
title="拖动调整顺序"
|
||||
@click.stop
|
||||
>
|
||||
<GripVerticalIcon class="size-3.5" />
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="min-w-0 flex-1 truncate text-left text-foreground"
|
||||
:class="sorting ? 'cursor-default' : undefined"
|
||||
:title="region.zoneLabel || region.regionName || `分区${ri + 1}`"
|
||||
@click="scrollToRegion(region.uid)"
|
||||
>
|
||||
{{ region.zoneLabel || region.regionName || `分区${ri + 1}` }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<div ref="scrollRef" class="min-h-0 min-w-0 flex-1 overflow-y-auto">
|
||||
<div
|
||||
ref="scrollRef"
|
||||
class="flex min-h-0 min-w-0 flex-1 flex-col gap-3 overflow-x-hidden overflow-y-auto pb-1"
|
||||
>
|
||||
<Card
|
||||
v-for="(region, ri) in regions"
|
||||
:id="`quote-region-${ri}`"
|
||||
:key="ri"
|
||||
:id="`quote-region-${region.uid}`"
|
||||
:key="region.uid"
|
||||
size="small"
|
||||
class="mb-3 shrink-0 scroll-mt-2"
|
||||
class="shrink-0 scroll-mt-2"
|
||||
:title="region.regionName || `分区${ri + 1}`"
|
||||
>
|
||||
<template #extra>
|
||||
<Button type="link" danger size="small" @click="removeRegion(ri)">
|
||||
<Button
|
||||
type="link"
|
||||
danger
|
||||
size="small"
|
||||
:disabled="sorting"
|
||||
@click="removeRegion(ri)"
|
||||
>
|
||||
删除分区
|
||||
</Button>
|
||||
</template>
|
||||
@@ -250,7 +373,7 @@ function onAnchorClick(e: Event) {
|
||||
:pagination="false"
|
||||
:columns="bandColumnDefs"
|
||||
:data-source="region.bands"
|
||||
:row-key="(_r: BandRow, i: number) => `${ri}-${i}`"
|
||||
:row-key="(_r: BandRow, i?: number) => `${region.uid}-${i ?? 0}`"
|
||||
>
|
||||
<template #bodyCell="{ column, index }">
|
||||
<template v-if="column.key === 'from'">
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/** 分区×重量带编辑用的行模型与前端 uid */
|
||||
|
||||
export interface BandRow {
|
||||
weightFromG: number;
|
||||
weightToG: number | null;
|
||||
priceMode: string;
|
||||
flatAmount: number;
|
||||
firstWeightG: number;
|
||||
firstAmount: number;
|
||||
continuePerKg: number;
|
||||
}
|
||||
|
||||
export interface RegionRow {
|
||||
/** 前端稳定键,拖拽重排后避免卡片错位 */
|
||||
uid: string;
|
||||
regionName: string;
|
||||
zoneLabel: string;
|
||||
provinces: string[];
|
||||
isDefault: boolean;
|
||||
bands: BandRow[];
|
||||
}
|
||||
|
||||
/** 生成分区前端 uid */
|
||||
export function createRegionUid() {
|
||||
return `r-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ExpressQuoteDTO, ExpressQuoteVO } from '#/api/ec/express-quote';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { ColPage } from '@vben/common-ui';
|
||||
@@ -20,9 +20,8 @@ import {
|
||||
} from '#/api/ec/express-quote';
|
||||
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
|
||||
|
||||
import RegionBandEditor, {
|
||||
type RegionRow,
|
||||
} from './components/RegionBandEditor.vue';
|
||||
import RegionBandEditor from './components/RegionBandEditor.vue';
|
||||
import { createRegionUid, type RegionRow } from './components/region-band';
|
||||
|
||||
defineOptions({ name: 'ExpressQuoteEdit' });
|
||||
|
||||
@@ -43,6 +42,7 @@ const pageTitle = ref('快递报价单编辑「新建」');
|
||||
const provinces = ref<ExpressQuoteVO.ProvinceOption[]>([]);
|
||||
const regions = ref<RegionRow[]>([
|
||||
{
|
||||
uid: createRegionUid(),
|
||||
regionName: '默认区',
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
@@ -246,6 +246,8 @@ const [BaseForm, formApi] = useVbenForm({
|
||||
fieldName: 'useVolumetric',
|
||||
label: '启用体积重',
|
||||
defaultValue: false,
|
||||
// 覆盖 commonConfig 的 w-full,避免开关被拉成整栏宽
|
||||
componentProps: { class: 'w-auto' },
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
@@ -278,6 +280,7 @@ function fillRegionsFromVersion(v?: ExpressQuoteVO.Version) {
|
||||
if (!v?.regions?.length) {
|
||||
regions.value = [
|
||||
{
|
||||
uid: createRegionUid(),
|
||||
regionName: '默认区',
|
||||
zoneLabel: '',
|
||||
provinces: [],
|
||||
@@ -297,7 +300,11 @@ function fillRegionsFromVersion(v?: ExpressQuoteVO.Version) {
|
||||
];
|
||||
return;
|
||||
}
|
||||
regions.value = v.regions.map((r) => ({
|
||||
const sorted = [...v.regions].sort(
|
||||
(a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0),
|
||||
);
|
||||
regions.value = sorted.map((r) => ({
|
||||
uid: createRegionUid(),
|
||||
regionName: r.regionName,
|
||||
zoneLabel: r.zoneLabel || '',
|
||||
provinces: r.provinces ? [...r.provinces] : [],
|
||||
@@ -329,11 +336,21 @@ function fillRegionsFromVersion(v?: ExpressQuoteVO.Version) {
|
||||
|
||||
async function loadDetail() {
|
||||
loading.value = true;
|
||||
let tabTitle: string | undefined;
|
||||
try {
|
||||
if (!provinces.value.length) {
|
||||
provinces.value = await getExpressProvincesApi();
|
||||
// 省份与详情并行,避免串行拉长转圈
|
||||
const needProvinces = !provinces.value.length;
|
||||
const [provinceList, detail] = await Promise.all([
|
||||
needProvinces ? getExpressProvincesApi() : Promise.resolve(null),
|
||||
quoteId.value
|
||||
? getExpressQuoteDetailApi(quoteId.value)
|
||||
: Promise.resolve(null),
|
||||
]);
|
||||
if (provinceList) {
|
||||
provinces.value = provinceList;
|
||||
}
|
||||
if (!quoteId.value) {
|
||||
|
||||
if (!detail) {
|
||||
await formApi.resetForm();
|
||||
await formApi.setValues({
|
||||
carrierCode: 'ZTO',
|
||||
@@ -347,13 +364,16 @@ async function loadDetail() {
|
||||
weightRound: 'NONE',
|
||||
});
|
||||
billingMode.value = 'FLAT';
|
||||
syncLeftWidthByMode();
|
||||
fillRegionsFromVersion();
|
||||
await syncTabTitle('新建');
|
||||
tabTitle = '新建';
|
||||
return;
|
||||
}
|
||||
const detail = await getExpressQuoteDetailApi(quoteId.value);
|
||||
billingMode.value = detail.billingMode;
|
||||
|
||||
const v = detail.currentVersion;
|
||||
billingMode.value = detail.billingMode;
|
||||
syncLeftWidthByMode();
|
||||
// 先回填表单并结束 loading,再挂大块分区(避免接口已返回仍长时间转圈)
|
||||
await formApi.setValues({
|
||||
code: detail.code,
|
||||
name: detail.name,
|
||||
@@ -370,15 +390,19 @@ async function loadDetail() {
|
||||
useVolumetric: v?.useVolumetric === 1,
|
||||
weightRound: v?.weightRound || 'NONE',
|
||||
});
|
||||
loading.value = false;
|
||||
await nextTick();
|
||||
fillRegionsFromVersion(v);
|
||||
await syncTabTitle(detail.name);
|
||||
tabTitle = detail.name;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('加载报价单失败');
|
||||
} finally {
|
||||
syncLeftWidthByMode();
|
||||
loading.value = false;
|
||||
}
|
||||
if (tabTitle != null) {
|
||||
void syncTabTitle(tabTitle);
|
||||
}
|
||||
}
|
||||
|
||||
function buildVersion(
|
||||
@@ -501,13 +525,13 @@ watch(
|
||||
<Card
|
||||
size="small"
|
||||
title="基本信息"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
class="eq-panel-card flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="cardBodyScrollStyle"
|
||||
>
|
||||
<BaseForm />
|
||||
</Card>
|
||||
</template>
|
||||
<div class="h-full min-h-0 min-w-0">
|
||||
<div class="h-full min-h-0 min-w-0 overflow-hidden">
|
||||
<RegionBandEditor
|
||||
v-if="isRegion"
|
||||
v-model="regions"
|
||||
@@ -517,7 +541,7 @@ watch(
|
||||
v-else
|
||||
size="small"
|
||||
title="分区报价"
|
||||
class="flex h-full min-h-0 flex-col overflow-hidden"
|
||||
class="eq-panel-card flex h-full min-h-0 flex-col overflow-hidden"
|
||||
:body-style="cardBodyScrollStyle"
|
||||
>
|
||||
<Empty
|
||||
@@ -548,10 +572,11 @@ watch(
|
||||
min-height: 0;
|
||||
flex: 1 1 0%;
|
||||
}
|
||||
.express-quote-edit-page :deep(.ant-card) {
|
||||
/* 只约束列级面板卡;勿套到右栏内部分区卡,否则 max-height:100% 会裁切并透出半截内容 */
|
||||
.express-quote-edit-page :deep(.eq-panel-card.ant-card) {
|
||||
max-height: 100%;
|
||||
}
|
||||
.express-quote-edit-page :deep(.ant-card-head) {
|
||||
.express-quote-edit-page :deep(.eq-panel-card > .ant-card-head) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user