Merge remote-tracking branch 'origin/master' into feature/hcs-api-p0-web

This commit is contained in:
刘泉佳
2026-10-22 09:43:02 +08:00
108 changed files with 7779 additions and 1683 deletions
@@ -3774,7 +3774,7 @@
</el-table-column>
<el-table-column label="剩余数量" min-width="130" align="center">
<template #default="{ row }">
{{ formatDispatchQuantity(dispatchItemRemainingQuantity(row)) }}
{{ formatDispatchQuantity(dispatchItemDisplayRemainingQuantity(row)) }}
</template>
</el-table-column>
<el-table-column min-width="130" align="center">
@@ -4031,7 +4031,7 @@
</el-input>
<div class="business-crud-page__dispatch-quantity-hint">
剩余数量:{{
formatDispatchQuantity(dispatchItemHintRemainingQuantity(dispatchItemForm))
formatDispatchQuantity(dispatchItemDisplayRemainingQuantity(dispatchItemForm))
}}
{{ dispatchItemForm.quantityUnit || '吨' }}
</div>
@@ -5740,6 +5740,8 @@ export default {
dispatchItemIndex: -1,
dispatchItemForm: defaultDispatchRow(),
dispatchItemCargoRows: [],
// 本次数量变更版本号:驱动同表其他行「剩余数量」同步重算
dispatchCargoQuantityVersion: 0,
dispatchItemAttachmentRows: [],
selectedDispatchItemAttachmentRows: [],
attachmentRows: [],
@@ -5897,7 +5899,7 @@ export default {
'固定金额(整单一口价)': ['固定一口价'],
按数量: ['固定单价', '区间单价', '阶梯单价', '区间阶梯一口价'],
},
settlementTypeOptions: ['月结', '日结', '周结', '半月结', '固定天数周期结算'],
settlementTypeOptions: ['月结', '日结', '周结', '固定天数周期结算'],
billCycleTypeOptions: ['固定截单日', '自然月', '自定义多周期'],
reconciliationModeOptions: ['明细逐行核对', '按账单汇总核对', '跳过自动核对'],
packageOptions,
@@ -12776,18 +12778,23 @@ export default {
row.cargoName = '';
row.specification = '';
row.model = '';
this.dispatchCargoQuantityVersion += 1;
},
handleDispatchConfiguredCargoNameChange(row, value) {
const option = this.getDispatchConfiguredCargoNameOptions(row).find(
item => String(item.value) === String(value || '')
);
row.cargoName = option?.value || '';
if (!option) return;
if (!option) {
this.dispatchCargoQuantityVersion += 1;
return;
}
row.cargoType = option.cargoTypeLabel || row.cargoType || '';
row.cargoTypeCode = option.cargoTypeCode || row.cargoTypeCode || '';
row.cargoTypePath = option.cargoTypePath || row.cargoTypePath || [];
row.specification = option.specification || row.specification || '';
row.model = option.model || row.model || '';
this.dispatchCargoQuantityVersion += 1;
},
openDispatchItemDialog(index = -1, row = defaultDispatchRow()) {
const defaultSummaryItem =
@@ -13119,6 +13126,7 @@ export default {
const parts = text.split('.');
row.quantity =
parts.length > 1 ? `${parts[0]}.${parts.slice(1).join('').slice(0, 3)}` : parts[0];
this.dispatchCargoQuantityVersion += 1;
},
handleDispatchCargoNumberInput(row, prop, value) {
this.handleTaskFullFreightNumberInput(row, prop, value);
@@ -13138,12 +13146,14 @@ export default {
const nextRow = this.normalizeTransportCargoRow({ priceUnit: '元/吨' });
if (index > -1) this.dispatchItemCargoRows.splice(index + 1, 0, nextRow);
else this.dispatchItemCargoRows.push(nextRow);
this.dispatchCargoQuantityVersion += 1;
},
removeDispatchCargoRow(index) {
this.dispatchItemCargoRows.splice(index, 1);
if (!this.dispatchItemCargoRows.length) {
this.dispatchItemCargoRows.push(this.normalizeTransportCargoRow());
}
this.dispatchCargoQuantityVersion += 1;
},
dispatchCargoFreightAmount(cargo = {}) {
const quantity = Number(cargo.quantity || 0);
@@ -13217,11 +13227,52 @@ export default {
}, 0)
);
},
/** 精简录入提示:可调度余量扣减当前本次数量后的剩余 */
dispatchItemHintRemainingQuantity(row = {}) {
/**
* 当前编辑表单中,与指定行同货物(有身份)或同单位(无身份)已占用的本次数量合计。
* 用于剩余数量展示联动,不参与提交校验(校验仍按整单合计对比计划余量)。
*/
getDispatchFormOccupiedQuantity(row = {}) {
const goodsRows =
this.dispatchItemForm?.taskEntryMode === 'full'
? this.dispatchItemCargoRows || []
: [this.dispatchItemForm || row];
const hasCargoIdentity = Boolean(
String(row.cargoName || row.goodsName || row.name || '').trim() ||
String(
row.cargoType || row.secondCargoTypeName || row.goodsType || row.type || ''
).trim()
);
const unit = this.getDispatchQuantityUnit(row);
const cargoKey = this.getDispatchCargoIdentity(row);
return goodsRows.reduce((sum, goods) => {
if (!goods) return sum;
if (hasCargoIdentity) {
const goodsHasIdentity = Boolean(
String(goods.cargoName || goods.goodsName || goods.name || '').trim() ||
String(
goods.cargoType || goods.secondCargoTypeName || goods.goodsType || goods.type || ''
).trim()
);
if (!goodsHasIdentity || this.getDispatchCargoIdentity(goods) !== cargoKey) {
return sum;
}
} else if (this.getDispatchQuantityUnit(goods) !== unit) {
return sum;
}
return sum + this.parseDispatchQuantity(goods.quantity);
}, 0);
},
/** 展示用剩余数量:计划可调度余量扣减本单已填本次数量(含当前行) */
dispatchItemDisplayRemainingQuantity(row = {}) {
// 依赖版本号,确保一行本次数量变化后其他行剩余数量一并刷新
void this.dispatchCargoQuantityVersion;
const available = this.dispatchItemRemainingQuantity(row);
const current = this.parseDispatchQuantity(row.quantity);
return Math.max(available - current, 0);
const occupied = this.getDispatchFormOccupiedQuantity(row);
return Math.max(available - occupied, 0);
},
/** 精简录入提示:与完整录入剩余数量展示规则一致 */
dispatchItemHintRemainingQuantity(row = {}) {
return this.dispatchItemDisplayRemainingQuantity(row);
},
pruneDispatchPendingRows(rows = []) {
const planQuantities = new Map();
@@ -388,7 +388,7 @@
:disabled="dialogReadonly"
@visible-change="visible => visible && loadFeeUnitOptions()"
><el-option
v-for="unit in feeUnitOptions"
v-for="unit in feeUnitSelectOptions"
:key="unit.value"
:label="unit.label"
:value="unit.value" /></el-select
@@ -1124,6 +1124,10 @@ import { getDictionary as getSystemDictionary } from '@/api/system/dict';
import { getDictionary } from '@/api/system/dictbiz';
import { packageOptions } from '@/option/business/common';
import { formatContractOptionLabel } from '@/utils/contract';
import {
mapFeeUnitOptions,
resolvePriceUnitByQuantityUnit,
} from '@/utils/currency';
import { loadMeasurementUnitOptions } from '@/utils/measurement-unit';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { downloadFileByUrl, downloadXls } from '@/utils/util';
@@ -1264,6 +1268,10 @@ const PageAvueForm = {
},
};
const shippingTemplateListRoute = '/business/shipping-template';
const shippingTemplateFormRoute = '/business/shipping-template/form';
const shippingTemplateListRefreshKey = 'shipping-template-list-refresh';
export default {
name: 'ShippingTemplatePage',
components: { PageAvueForm, ElImageViewer, OpenFileViewer },
@@ -1280,6 +1288,9 @@ export default {
return {
Location,
OfficeBuilding,
// 实例所属路由快照,避免 keep-alive 列表实例被全局 $route 误判成表单页。
routePathLocked: this.$route.path,
isFormPageInstance: this.$route.path === shippingTemplateFormRoute,
form: {},
query: {},
loading: true,
@@ -1401,13 +1412,18 @@ export default {
isStandaloneBusinessPage() {
return (
this.standaloneFormPage &&
['/business/shipping-template', '/business/shipping-template/form'].includes(
this.$route.path
)
(this.isFormPageInstance ||
[shippingTemplateListRoute, shippingTemplateFormRoute].includes(this.routePathLocked) ||
[shippingTemplateListRoute, shippingTemplateFormRoute].includes(this.$route.path))
);
},
isStandaloneFormPage() {
return this.isStandaloneBusinessPage && ['add', 'edit'].includes(this.$route.query.mode);
// 用实例锁定标志,避免列表 keep-alive 实例被全局路由误判成表单页。
return (
this.standaloneFormPage &&
this.isFormPageInstance &&
['add', 'edit'].includes(this.$route.query.mode)
);
},
formPageTitle() {
return this.isStandaloneFormPage
@@ -1464,6 +1480,12 @@ export default {
);
return this.currencyUnit(option?.label || this.shippingTemplateFreight.currency);
},
feeUnitSelectOptions() {
return mapFeeUnitOptions(
this.feeUnitOptions,
this.shippingTemplateFreight.currency || 'RMB'
);
},
roadFreightTotal() {
const total = this.shippingTemplateFreight.freightItems.reduce(
(sum, item) => sum + Number(this.freightAmount(item) || 0),
@@ -1530,6 +1552,18 @@ export default {
},
watch: {
$route(to, from) {
// 列表实例:从其他页进入列表时刷新(activated 负责标签切回)。
if (!this.isFormPageInstance) {
const enteringList =
(to.path === this.routePathLocked || to.path === shippingTemplateListRoute) &&
from?.path &&
from.path !== to.path;
if (enteringList) {
sessionStorage.removeItem(shippingTemplateListRefreshKey);
this.$nextTick(() => this.onLoad(this.page, this.query));
}
return;
}
if (
this.isStandaloneFormPage &&
(to.query.mode !== from?.query?.mode ||
@@ -1550,6 +1584,10 @@ export default {
this.handleTransportTypeChange(value);
this.syncFreightItems();
},
'form.templateType'() {
// 切换到运单模板时立即按货物数量单位生成公路运费明细。
this.$nextTick(() => this.syncFreightItems());
},
},
created() {
this.loadProjectOptions();
@@ -1559,8 +1597,16 @@ export default {
this.loadCurrencyOptions();
if (this.isStandaloneFormPage) this.$nextTick(() => this.initStandaloneFormPage());
},
activated() {
if (this.isFormPageInstance) return;
sessionStorage.removeItem(shippingTemplateListRefreshKey);
this.$nextTick(() => this.onLoad(this.page, this.query));
},
methods: {
formatContractOptionLabel,
markShippingTemplateListNeedRefresh() {
sessionStorage.setItem(shippingTemplateListRefreshKey, '1');
},
loadQuantityUnitOptions() {
if (this.quantityUnitLoading) return this.quantityUnitLoadPromise;
this.quantityUnitLoading = true;
@@ -1591,12 +1637,8 @@ export default {
});
}
if (this.menuWidth != null) next.menuWidth = this.menuWidth;
if (
this.standaloneFormPage &&
['/business/shipping-template', '/business/shipping-template/form'].includes(
this.$route.path
)
) {
// 仅表单页实例套用全屏表单弹窗样式,避免列表页误用后表格区域异常。
if (this.standaloneFormPage && this.$route.path === shippingTemplateFormRoute) {
next.dialogAppendToBody = false;
next.dialogModal = false;
next.dialogCustomClass = 'shipping-template-form-page-dialog';
@@ -1776,13 +1818,22 @@ export default {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
if (this.isFormPageInstance) return;
this.loading = true;
const currentPage = page?.currentPage || this.page.currentPage || 1;
const pageSize = page?.pageSize || this.page.pageSize || 10;
this.api
.getList(page.currentPage, page.pageSize, { ...this.query, ...params })
.getList(currentPage, pageSize, { ...this.query, ...params })
.then(res => {
const data = res?.data?.data || {};
this.data = extractRecords(res);
this.page.total = data.total || this.data.length;
const data = res?.data?.data || res?.data || {};
const records = extractRecords(res);
this.data = records;
this.page.total = Number(data.total ?? records.length) || 0;
})
.catch(error => {
window.console.error(error);
this.data = [];
this.page.total = 0;
})
.finally(() => {
this.loading = false;
@@ -1821,9 +1872,10 @@ export default {
.submit(submit)
.then(() => {
this.$message.success('操作成功');
this.markShippingTemplateListNeedRefresh();
done?.();
this.closeCrudDialog();
this.onLoad(this.page, this.query);
if (!this.isFormPageInstance) this.onLoad(this.page, this.query);
})
.catch(() => loading?.());
},
@@ -1837,9 +1889,10 @@ export default {
.submit(submit)
.then(() => {
this.$message.success('操作成功');
this.markShippingTemplateListNeedRefresh();
done?.();
this.closeCrudDialog();
this.onLoad(this.page, this.query);
if (!this.isFormPageInstance) this.onLoad(this.page, this.query);
})
.catch(() => loading?.());
},
@@ -1883,6 +1936,8 @@ export default {
this.attachmentRows = [];
this.shippingTemplateFreight = defaultFreight();
this.loadCurrencyOptions();
this.loadFeeUnitOptions();
this.$nextTick(() => this.syncFreightItems());
if (typeof this.api.nextCode === 'function')
this.api
.nextCode()
@@ -2005,20 +2060,47 @@ export default {
return false;
}
if (this.transportMode === 'road') {
const invalid = this.shippingTemplateFreight.freightItems.findIndex(
item =>
Number(item.unitPrice || 0) < 0 ||
!item.priceUnit ||
(!this.isFreightAutoCalculable(item) &&
(item.freightAmount === '' ||
item.freightAmount === null ||
item.freightAmount === undefined)) ||
Number(item.freightAmount || 0) < 0
);
if (invalid > -1) {
this.$message.warning(`第${invalid + 1}条货物的单价、计价单位或运费无效`);
if (!this.shippingTemplateFreight.freightItems.length) {
this.$message.warning('请先完善货物数量单位,以便生成运费明细');
return false;
}
for (const [index, item] of this.shippingTemplateFreight.freightItems.entries()) {
const label = `第${index + 1}条运费明细`;
if (
item.unitPrice === '' ||
item.unitPrice === null ||
item.unitPrice === undefined
) {
this.$message.warning(`请填写${label}的单价`);
return false;
}
if (Number(item.unitPrice) < 0) {
this.$message.warning(`${label}的单价不能小于0`);
return false;
}
if (!String(item.priceUnit || '').trim()) {
this.$message.warning(`请选择${label}的计价单位`);
return false;
}
if (this.isFreightAutoCalculable(item)) {
if (!item.freightAmountManual) {
item.freightAmount = this.freightAmount(item);
}
} else if (
item.freightAmount === '' ||
item.freightAmount === null ||
item.freightAmount === undefined
) {
this.$message.warning(
`${label}的计价单位与货物数量单位不匹配,无法自动计算运费,请手动填写运费`
);
return false;
}
if (Number(item.freightAmount || 0) < 0) {
this.$message.warning(`${label}的运费不能小于0`);
return false;
}
}
} else if (Number(this.shippingTemplateFreight.freightAmount || 0) < 0) {
this.$message.warning('运费不能小于0');
return false;
@@ -2033,8 +2115,11 @@ export default {
return true;
},
closeCrudDialog() {
if (this.isStandaloneBusinessPage) {
this.$router.push({ path: '/business/shipping-template', query: {} });
if (this.isStandaloneBusinessPage || this.isFormPageInstance) {
// 关闭独立表单页时标记列表需刷新(含直接点关闭未保存的场景)
this.markShippingTemplateListNeedRefresh();
this.$router.$avueRouter?.closeTag?.();
this.$router.push({ path: shippingTemplateListRoute, query: {} });
return;
}
this.$refs.crud?.closeDialog?.();
@@ -2294,7 +2379,16 @@ export default {
},
loadFeeUnitOptions() {
getDictionary({ code: 'unit_fee' }).then(res => {
this.feeUnitOptions = this.normalizeDictOptions(res?.data?.data || []);
// 计价单位必须保存可读文案(如 元/吨),才能与货物数量单位匹配并自动计算运费。
this.feeUnitOptions = (res?.data?.data || []).map(item => {
const label = String(item.dictValue || item.label || item.value || '').trim();
const key = String(item.dictKey || item.value || '').trim();
return {
label: label || key,
value: label.includes('/') ? label : key || label,
remark: item.remark || '',
};
});
});
},
loadCurrencyOptions() {
@@ -3098,24 +3192,53 @@ export default {
: [];
const quantityUnits = [];
this.transportCargoRows.forEach(row => {
const quantityUnit = row.quantityUnit || '';
const quantityUnit = String(row.quantityUnit || '').trim();
if (!quantityUnit) return;
if (!quantityUnits.some(unit => unit === quantityUnit)) quantityUnits.push(quantityUnit);
});
const currency = this.shippingTemplateFreight.currency || 'RMB';
this.shippingTemplateFreight.freightItems = quantityUnits.map((quantityUnit, index) => {
const matched =
previousItems.find(item => String(item.quantityUnit || '') === String(quantityUnit)) ||
previousItems[index] ||
{};
const defaultPriceUnit = resolvePriceUnitByQuantityUnit(quantityUnit, currency);
const priceUnit = this.normalizeFreightPriceUnit(
matched.priceUnit || defaultPriceUnit || '',
quantityUnit,
currency
);
return {
quantityUnit,
unitPrice: matched.unitPrice || '',
priceUnit: matched.priceUnit || '',
priceUnit,
freightAmount: matched.freightAmount ?? '',
freightAmountManual:
matched.freightAmountManual === true || matched.manualFreightAmount === true,
};
});
},
normalizeFreightPriceUnit(priceUnit, quantityUnit, currency = 'RMB') {
const text = this.resolvePriceUnitText(priceUnit);
if (text && this.priceUnitMatchesQuantity(text, quantityUnit)) return text;
return (
resolvePriceUnitByQuantityUnit(quantityUnit, currency) ||
text ||
String(priceUnit || '').trim()
);
},
resolvePriceUnitText(priceUnit) {
const raw = String(priceUnit || '').trim();
if (!raw) return '';
if (raw.includes('/')) return raw;
const options = this.feeUnitSelectOptions.length
? this.feeUnitSelectOptions
: this.feeUnitOptions;
const matched = options.find(
item => String(item.value) === raw || String(item.label) === raw
);
return matched?.label || raw;
},
quantityUnits() {
return [
...new Set(
@@ -3131,7 +3254,7 @@ export default {
.replace(/\s+/g, '')
.replace(/立方米|立方公尺|方/g, '立方');
const unit = normalizeUnit(quantityUnit).replace(/[·*.]/g, '');
const value = String(priceUnit || '')
const value = String(this.resolvePriceUnitText(priceUnit) || '')
.trim()
.toLowerCase()
.replace(/\s+/g, '');
@@ -3163,6 +3286,10 @@ export default {
return this.formatFreightNumber(item.freightAmount);
}
if (!this.isFreightAutoCalculable(item)) {
// 无法自动计算且未手工填写时返回空,避免把空值显示成 0 造成“已填写”的错觉。
if (item.freightAmount === '' || item.freightAmount === null || item.freightAmount === undefined) {
return '';
}
return this.formatFreightNumber(item.freightAmount);
}
return this.formatFreightNumber(
@@ -1677,7 +1677,7 @@
{{
isDispatchPlanQuantityUnlimited(row)
? '-'
: formatDispatchQuantity(dispatchItemRemainingQuantity(row))
: formatDispatchQuantity(dispatchItemDisplayRemainingQuantity(row))
}}
</template>
</el-table-column>
@@ -1861,7 +1861,7 @@
/>
</el-select>
</el-form-item>
<el-form-item label="司机" :required="dispatchItemForm.carrierType !== '承运商'">
<el-form-item label="司机" required>
<el-autocomplete
v-model="dispatchItemForm.driverName"
placeholder="请输入"
@@ -1874,7 +1874,7 @@
</el-form-item>
<el-form-item
:label="dispatchItemForm.carrierType === '承运商' ? '手机号' : '司机手机号'"
:required="dispatchItemForm.carrierType !== '承运商'"
required
>
<el-input v-model="dispatchItemForm.driverPhone" placeholder="请输入" />
</el-form-item>
@@ -1955,7 +1955,7 @@
class="transport-plan-page__dispatch-quantity-hint"
>
剩余数量:{{
formatDispatchQuantity(dispatchItemHintRemainingQuantity(dispatchItemForm))
formatDispatchQuantity(dispatchItemDisplayRemainingQuantity(dispatchItemForm))
}}
{{ dispatchItemForm.quantityUnit || '吨' }}
</div>
@@ -2096,11 +2096,7 @@
/>
</el-select>
</el-form-item>
<el-form-item
v-if="dispatchIsRoadTransport"
label="司机"
:required="dispatchItemForm.carrierType === '自运'"
>
<el-form-item v-if="dispatchIsRoadTransport" label="司机" required>
<el-autocomplete
v-model="dispatchItemForm.driverName"
placeholder="请输入"
@@ -2111,11 +2107,7 @@
@select="item => handleTaskDriverSelect('dispatch', item)"
/>
</el-form-item>
<el-form-item
v-if="dispatchIsRoadTransport"
label="手机号"
:required="dispatchItemForm.carrierType === '自运'"
>
<el-form-item v-if="dispatchIsRoadTransport" label="手机号" required>
<el-input v-model="dispatchItemForm.driverPhone" placeholder="请输入" />
</el-form-item>
<el-form-item
@@ -2807,8 +2799,11 @@ import 'nprogress/nprogress.css';
const AMAP_KEY = '653b7cf105ad7fb8ec9b2f5198ade315';
const AMAP_SECURITY_CODE = '5aab65c632e48ebae0d0e28f5b28e21a';
let amapLoader;
const transportPlanListRoute = '/business/transport-plan';
const transportPlanFormRoute = '/business/transport-plan/form';
const transportPlanListRefreshKey = 'transport-plan-list-refresh';
const standaloneTransportPlanFormRoutes = {
'/business/transport-plan': '/business/transport-plan/form',
[transportPlanListRoute]: transportPlanFormRoute,
};
const standaloneTransportPlanFormPaths = [
...Object.keys(standaloneTransportPlanFormRoutes),
@@ -3072,6 +3067,10 @@ export default {
// 必须放 data:Options API 的顺序是 data → computed → watch(immediate) → created,
// 放 created 的话首个 immediate watcher 会读到空值,把首次加载也挡掉。
routePathLocked: this.$route.path,
// 表单页实例在创建时锁定,避免 keep-alive 列表实例随全局 $route 误切到表单态。
isFormPageInstance: Object.values(standaloneTransportPlanFormRoutes).includes(
this.$route.path
),
form: {},
suppressTransportTypeClear: false,
query: {},
@@ -3112,10 +3111,11 @@ export default {
option: (() => {
const opt = this.cloneOption(this.crudOption, estimateMenuButtonCount(this.config));
if (this.menuWidth != null) opt.menuWidth = this.menuWidth;
if (
this.standaloneFormPage &&
standaloneTransportPlanFormPaths.includes(this.$route.path)
) {
// 仅表单页实例套用全屏表单弹窗样式,避免列表页误用后表格区域异常。
const isFormInstance = Object.values(standaloneTransportPlanFormRoutes).includes(
this.$route.path
);
if (this.standaloneFormPage && isFormInstance) {
opt.dialogAppendToBody = false;
opt.dialogModal = false;
opt.dialogCustomClass = 'transport-plan-form-page-dialog';
@@ -3150,6 +3150,8 @@ export default {
dispatchItemIndex: -1,
dispatchItemForm: defaultDispatchRow(),
dispatchItemCargoRows: [],
// 本次数量变更版本号:驱动同表其他行「剩余数量」同步重算
dispatchCargoQuantityVersion: 0,
dispatchItemAttachmentRows: [],
selectedDispatchItemAttachmentRows: [],
attachmentRows: [],
@@ -3289,6 +3291,12 @@ export default {
}
this.loadTaskQuantityUnitOptions();
},
// keep-alive 重新激活列表时强制刷新,避免缓存脏数据;标记位用于兼容旧跳转逻辑。
activated() {
if (this.isFormPageInstance) return;
sessionStorage.removeItem(transportPlanListRefreshKey);
this.$nextTick(() => this.onLoad(this.page, this.query));
},
computed: {
...mapGetters(['permission', 'userInfo']),
permissionList() {
@@ -3300,10 +3308,20 @@ export default {
return this.config.detailSections || [];
},
isStandaloneBusinessPage() {
return this.standaloneFormPage && standaloneTransportPlanFormPaths.includes(this.$route.path);
return (
this.standaloneFormPage &&
(this.isFormPageInstance ||
standaloneTransportPlanFormPaths.includes(this.routePathLocked) ||
standaloneTransportPlanFormPaths.includes(this.$route.path))
);
},
isStandaloneFormPage() {
return this.isStandaloneBusinessPage && ['add', 'edit'].includes(this.$route.query.mode);
// 用实例锁定标志,避免列表 keep-alive 实例被全局路由误判成表单页。
return (
this.standaloneFormPage &&
this.isFormPageInstance &&
['add', 'edit'].includes(this.$route.query.mode)
);
},
formPageTitle() {
if (this.isStandaloneFormPage) {
@@ -3752,6 +3770,18 @@ export default {
},
watch: {
$route(to, from) {
// 列表实例:从其他页进入列表时刷新(activated 负责标签切回)。
if (!this.isFormPageInstance) {
const enteringList =
(to.path === this.routePathLocked || to.path === transportPlanListRoute) &&
from?.path &&
from.path !== to.path;
if (enteringList) {
sessionStorage.removeItem(transportPlanListRefreshKey);
this.$nextTick(() => this.onLoad(this.page, this.query));
}
return;
}
if (!this.isStandaloneFormPage) return;
if (
to.query.mode !== from?.query?.mode ||
@@ -4484,6 +4514,9 @@ export default {
loading();
}
},
markTransportPlanListNeedRefresh() {
sessionStorage.setItem(transportPlanListRefreshKey, '1');
},
rowSave(row, done, loading) {
const submitRow = this.normalizeRow(row);
if (!submitRow) {
@@ -4492,6 +4525,7 @@ export default {
}
this.getSaveRequest()(submitRow).then(
() => {
this.markTransportPlanListNeedRefresh();
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
@@ -4511,6 +4545,7 @@ export default {
}
this.getSaveRequest()(submitRow).then(
() => {
this.markTransportPlanListNeedRefresh();
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
@@ -4540,7 +4575,7 @@ export default {
.submit(submitRow)
.then(() => {
this.$message.success(action === 'draft' ? '暂存成功' : '创建成功');
this.onLoad(this.page, this.query);
this.markTransportPlanListNeedRefresh();
this.closeCrudDialog();
})
.finally(() => {
@@ -4548,12 +4583,14 @@ export default {
});
},
closeCrudDialog() {
if (this.isStandaloneBusinessPage) {
if (this.isStandaloneBusinessPage || this.isFormPageInstance) {
// 关闭独立表单页时标记列表需刷新(含直接点关闭未保存的场景)
this.markTransportPlanListNeedRefresh();
this.$router.$avueRouter?.closeTag?.();
const listPath =
Object.entries(standaloneTransportPlanFormRoutes).find(
([, formPath]) => formPath === this.$route.path
)?.[0] || this.$route.path;
([, formPath]) => formPath === this.$route.path || formPath === this.routePathLocked
)?.[0] || transportPlanListRoute;
this.$router.push({ path: listPath, query: {} });
return;
}
@@ -6634,20 +6671,33 @@ export default {
return query;
},
onLoad(page, params = {}) {
if (this.isFormPageInstance) return;
this.loading = true;
const currentPage = page?.currentPage || this.page.currentPage || 1;
const pageSize = page?.pageSize || this.page.pageSize || 10;
const query = this.normalizeQueryParams({
...params,
...this.query,
allDept: 0,
});
this.api
.getList(page.currentPage, page.pageSize, query)
.getList(currentPage, pageSize, query)
.then(res => {
const result = res.data.data;
this.page.total = result.total;
this.data = result.records;
const result = res?.data?.data || res?.data || {};
const records = Array.isArray(result.records)
? result.records
: Array.isArray(result)
? result
: [];
this.page.total = Number(result.total ?? records.length) || 0;
this.data = records;
this.selectionClear();
})
.catch(error => {
window.console.error(error);
this.data = [];
this.page.total = 0;
})
.finally(() => {
this.loading = false;
});
@@ -7652,6 +7702,7 @@ export default {
row.cargoName = '';
row.specification = '';
row.model = '';
this.dispatchCargoQuantityVersion += 1;
},
handleDispatchConfiguredCargoNameChange(row, value) {
const nextValue = String(value ?? row.cargoName ?? '').trim();
@@ -7660,6 +7711,7 @@ export default {
);
if (!option) {
row.cargoName = nextValue;
this.dispatchCargoQuantityVersion += 1;
return;
}
const previousType = String(row.cargoType || '').trim();
@@ -7674,6 +7726,7 @@ export default {
}
row.specification = option.specification || row.specification || '';
row.model = option.model || row.model || '';
this.dispatchCargoQuantityVersion += 1;
},
openDispatchItemDialog(index = -1, row = defaultDispatchRow()) {
const defaultSummaryItem =
@@ -8002,6 +8055,7 @@ export default {
const parts = text.split('.');
row.quantity =
parts.length > 1 ? `${parts[0]}.${parts.slice(1).join('').slice(0, 3)}` : parts[0];
this.dispatchCargoQuantityVersion += 1;
},
handleDispatchCargoNumberInput(row, prop, value) {
this.handleFreightNumberInput(row, prop, value);
@@ -8021,12 +8075,14 @@ export default {
const nextRow = this.normalizeTransportCargoRow({ priceUnit: this.defaultPriceUnit });
if (index > -1) this.dispatchItemCargoRows.splice(index + 1, 0, nextRow);
else this.dispatchItemCargoRows.push(nextRow);
this.dispatchCargoQuantityVersion += 1;
},
removeDispatchCargoRow(index) {
this.dispatchItemCargoRows.splice(index, 1);
if (!this.dispatchItemCargoRows.length) {
this.dispatchItemCargoRows.push(this.normalizeTransportCargoRow());
}
this.dispatchCargoQuantityVersion += 1;
},
dispatchCargoFreightAmount(cargo = {}) {
if (cargo.freightAmount !== undefined && cargo.freightAmount !== null) {
@@ -8176,11 +8232,50 @@ export default {
}, 0)
);
},
/** 精简录入提示:可调度余量扣减当前本次数量后的剩余 */
dispatchItemHintRemainingQuantity(row = {}) {
/**
* 当前编辑表单中,与指定行同货物(有身份)或同单位(无身份)已占用的本次数量合计。
* 用于剩余数量展示联动,不参与提交校验(校验仍按整单合计对比计划余量)。
*/
getDispatchFormOccupiedQuantity(row = {}) {
const goodsRows =
this.dispatchItemForm?.taskEntryMode === 'full'
? this.dispatchItemCargoRows || []
: [this.dispatchItemForm || row];
const hasCargoIdentity = Boolean(
String(row.cargoName || row.goodsName || row.name || '').trim() ||
String(row.cargoType || row.secondCargoTypeName || row.goodsType || row.type || '').trim()
);
const unit = this.getDispatchQuantityUnit(row);
const cargoKey = this.getDispatchCargoIdentity(row);
return goodsRows.reduce((sum, goods) => {
if (!goods) return sum;
if (hasCargoIdentity) {
const goodsHasIdentity = Boolean(
String(goods.cargoName || goods.goodsName || goods.name || '').trim() ||
String(
goods.cargoType || goods.secondCargoTypeName || goods.goodsType || goods.type || ''
).trim()
);
if (!goodsHasIdentity || this.getDispatchCargoIdentity(goods) !== cargoKey) {
return sum;
}
} else if (this.getDispatchQuantityUnit(goods) !== unit) {
return sum;
}
return sum + this.parseDispatchQuantity(goods.quantity);
}, 0);
},
/** 展示用剩余数量:计划可调度余量扣减本单已填本次数量(含当前行) */
dispatchItemDisplayRemainingQuantity(row = {}) {
// 依赖版本号,确保一行本次数量变化后其他行剩余数量一并刷新
void this.dispatchCargoQuantityVersion;
const available = this.dispatchItemRemainingQuantity(row);
const current = this.parseDispatchQuantity(row.quantity);
return Math.max(available - current, 0);
const occupied = this.getDispatchFormOccupiedQuantity(row);
return Math.max(available - occupied, 0);
},
/** 精简录入提示:与完整录入剩余数量展示规则一致 */
dispatchItemHintRemainingQuantity(row = {}) {
return this.dispatchItemDisplayRemainingQuantity(row);
},
pruneDispatchPendingRows(rows = []) {
const planQuantities = new Map();
@@ -8278,13 +8373,17 @@ export default {
const fullEntry = row.taskEntryMode === 'full';
const roadTransport = this.resolveTransportMode(row.transportType) === 'road';
if (fullEntry) {
if (roadTransport && row.carrierType === '自运') {
// 公路运输时司机/手机号一律必填(含承运类型为承运商)
if (roadTransport && row.carrierType) {
requiredFields.push(['driverName', '司机']);
requiredFields.push(['driverPhone', '手机号']);
}
} else if (row.carrierType && row.carrierType !== '承运商') {
} else if (row.carrierType) {
requiredFields.push(['driverName', '司机']);
requiredFields.push(['driverPhone', '司机手机号']);
requiredFields.push([
'driverPhone',
row.carrierType === '承运商' ? '手机号' : '司机手机号',
]);
}
const emptyField = requiredFields.find(([prop]) => this.isBillingFieldEmpty(row[prop]));
if (emptyField) return requiredMessage(emptyField[1]);
@@ -96,22 +96,12 @@
prop="carrierName"
label="承运商"
min-width="140"
/><el-table-column
v-if="columnVisible.carrierType"
prop="carrierType"
label="承运类型"
min-width="120"
/>
<el-table-column
v-if="columnVisible.waybillCount"
prop="waybillCount"
label="运单数"
width="90"
/> <el-table-column
v-if="columnVisible.importTypeName"
prop="importTypeName"
label="导入方式"
width="100"
/>
<el-table-column
v-if="columnVisible.statusName"
@@ -119,6 +109,12 @@
label="状态"
width="100"
/>
<el-table-column
v-if="columnVisible.settlementStatusName"
prop="settlementStatusName"
label="结算状态"
width="110"
/>
<el-table-column
v-if="columnVisible.createUserName"
prop="createUserName"
@@ -159,7 +155,7 @@
>编辑</el-link
>
<el-link
v-if="row.importStatus === 'draft'"
v-if="canRemoveBatch(row)"
type="danger"
@click="removeBatch(row)"
>删除</el-link
@@ -641,10 +637,9 @@ const columnOptions = [
{ prop: 'batchNo', label: '运单批次号' },
{ prop: 'projectName', label: '项目名称' },
{ prop: 'carrierName', label: '承运商' },
{ prop: 'carrierType', label: '承运类型' },
{ prop: 'waybillCount', label: '运单数' },
{ prop: 'importTypeName', label: '导入方式' },
{ prop: 'statusName', label: '状态' },
{ prop: 'settlementStatusName', label: '结算状态' },
{ prop: 'createUserName', label: '创建人' },
{ prop: 'createTime', label: '创建时间' },
{ prop: 'updateTime', label: '更新时间' },
@@ -1266,9 +1261,47 @@ const fillEditForm = async row => {
if (carrierValue) carrierChange(carrierValue);
await loadBatchRows(snapshot.id);
};
const removeBatches = () =>
api.removeImportBatches(selected.value.map(item => item.id).join(',')).then(loadBatches);
const removeBatch = row => api.removeImportBatches(row.id).then(loadBatches);
/** 与后端一致:仅未结算批次可整批删除 */
const canRemoveBatch = row => String(row?.settlementStatus || 'unsettled') === 'unsettled';
const removeBatches = async () => {
if (!selected.value.length) {
ElMessage.warning('请选择至少一条数据');
return;
}
// 选中含部分结算/已结算时整批拦截,不静默跳过
if (selected.value.some(row => !canRemoveBatch(row))) {
ElMessage.warning('仅未结算的运单批次可以删除');
return;
}
try {
await ElMessageBox.confirm('确认删除选中的运单批次?删除后不可恢复。', '提示', {
type: 'warning',
});
} catch {
return;
}
await api.removeImportBatches(selected.value.map(item => item.id).join(','));
ElMessage.success('删除成功');
return loadBatches();
};
const removeBatch = async row => {
if (!canRemoveBatch(row)) {
ElMessage.warning('仅未结算的运单批次可以删除');
return;
}
try {
await ElMessageBox.confirm(
`确认删除运单批次「${row.batchNo || ''}」?删除后不可恢复。`,
'提示',
{ type: 'warning' }
);
} catch {
return;
}
await api.removeImportBatches(row.id);
ElMessage.success('删除成功');
return loadBatches();
};
const projectChange = async id => {
const requestId = ++projectRequestId;
const item = projects.value.find(row => String(row.id) === String(id));