diff --git a/src/option/business/contract-manage.js b/src/option/business/contract-manage.js index 685ceb2..0992ceb 100644 --- a/src/option/business/contract-manage.js +++ b/src/option/business/contract-manage.js @@ -267,7 +267,7 @@ export const option = createCrudOption([ searchType: 'select', searchPlaceholder: '请选择', formslot: true, - order: 140, + order: 165, dicUrl: '/blade-transport/project-apply/list?current=1&size=9999&approvalStatuses=approved,change_approved', dicFormatter: listDicFormatter, @@ -345,14 +345,9 @@ export const option = createCrudOption([ label: '甲方', prop: 'partyA', type: 'select', + formslot: true, + disabled: true, order: 160, - dicUrl: - '/blade-transport/customer-archive/list?current=1&size=9999&customerType=客户&approvalStatus=approved&status=1', - dicFormatter: listDicFormatter, - props: { - label: 'fullName', - value: 'fullName', - }, filterable: true, minWidth: 160, rules: selectRule('甲方'), @@ -361,14 +356,9 @@ export const option = createCrudOption([ label: '乙方', prop: 'partyB', type: 'select', + formslot: true, + disabled: true, order: 150, - dicUrl: - '/blade-transport/customer-archive/list?current=1&size=9999&customerType=承运商&approvalStatus=approved&status=1', - dicFormatter: listDicFormatter, - props: { - label: 'fullName', - value: 'fullName', - }, filterable: true, minWidth: 160, rules: selectRule('乙方'), diff --git a/src/option/business/shipping-template.js b/src/option/business/shipping-template.js index 43823f2..598b263 100644 --- a/src/option/business/shipping-template.js +++ b/src/option/business/shipping-template.js @@ -40,6 +40,9 @@ export const config = { projectQueryParams: { approvalStatuses: 'approved,change_approved', }, + contractQueryParams: { + contractCategory: '客户合同', + }, excludeVoidedProjects: true, enableAttachmentTable: true, detailAttachmentDescriptionPlain: true, diff --git a/src/option/business/transport-plan.js b/src/option/business/transport-plan.js index 96c1365..d1475df 100644 --- a/src/option/business/transport-plan.js +++ b/src/option/business/transport-plan.js @@ -167,6 +167,9 @@ export const config = { projectQueryParams: { approvalStatuses: 'approved,change_approved', }, + contractQueryParams: { + contractCategory: '客户合同', + }, templateCreateTarget: 'transport-plan', enableAttachmentTable: true, enableTransportPlanForm: true, diff --git a/src/option/business/waybill-manage.js b/src/option/business/waybill-manage.js index d0e80fc..c788ae5 100644 --- a/src/option/business/waybill-manage.js +++ b/src/option/business/waybill-manage.js @@ -329,6 +329,9 @@ export const config = { projectQueryParams: { approvalStatuses: 'approved,change_approved', }, + contractQueryParams: { + contractCategory: '客户合同', + }, templateCreateTarget: 'waybill-manage', enableContractSelect: true, enableShippingPlanSelect: true, diff --git a/src/views/business/components/billing-plan-editor.vue b/src/views/business/components/billing-plan-editor.vue index 9de5f4c..7fd95fb 100644 --- a/src/views/business/components/billing-plan-editor.vue +++ b/src/views/business/components/billing-plan-editor.vue @@ -18,7 +18,7 @@ - + @@ -45,7 +45,7 @@ import { getLazyTree as getRegionLazyTree } from '@/api/base/region'; import { getDictionary } from '@/api/system/dictbiz'; const clone = value => JSON.parse(JSON.stringify(value)); -const defaultRule = () => ({ feeType: '', feeItem: '', billingElement: '', billingType: '', billingUnit: '', unitPrice: '', lowerLimit: '', upperLimit: '', limitRanges: [{ lowerLimit: '', upperLimit: '', unitPrice: '' }], minimumBillingWeight: '', remark: '', matchCondition: { origin: '', originCode: '', originPath: [], destination: '', destinationCode: '', destinationPath: [], transportMode: '', cargoType: '', cargoTypeCode: '', cargoTypePath: [] } }); +const defaultRule = () => ({ feeType: '', feeItem: '', billingElement: '', billingType: '', billingUnit: '', unitPrice: '', lowerLimit: '', upperLimit: '', limitRanges: [{ lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }], minimumBillingWeight: '', remark: '', matchCondition: { origin: '', originCode: '', originPath: [], destination: '', destinationCode: '', destinationPath: [], transportMode: '', cargoType: '', cargoTypeCode: '', cargoTypePath: [] } }); export default { props: { modelValue: Boolean, value: { type: Object, default: () => ({}) }, index: { type: Number, default: -1 }, readonly: Boolean }, @@ -56,9 +56,9 @@ export default { watch: { value: { deep: true, handler(value) { if (this.modelValue) { this.draft = this.normalizePlan(value); this.loadRuleItems(); } } } }, methods: { normalizePlan(value = {}) { const plan = { planName: '', defaultPlan: false, remark: '', ...clone(value || {}) }; plan.rules = (value?.rules?.length ? value.rules : [defaultRule()]).map(rule => this.normalizeRule(rule)); return plan; }, - normalizeRule(rule = {}) { const next = { ...defaultRule(), ...clone(rule) }; next.limitRanges = this.normalizeRanges(next); this.syncLegacyLimit(next); next.matchCondition = { ...defaultRule().matchCondition, ...(rule.matchCondition || {}) }; return next; }, - normalizeRanges(row) { const ranges = Array.isArray(row.limitRanges) ? row.limitRanges.map(item => ({ lowerLimit: item?.lowerLimit ?? '', upperLimit: item?.upperLimit ?? '', unitPrice: item?.unitPrice === undefined || item?.unitPrice === '' ? row.unitPrice ?? '' : item.unitPrice })).filter(item => item.lowerLimit !== '' || item.upperLimit !== '' || item.unitPrice !== '') : []; if (!ranges.length && (row.lowerLimit !== '' || row.upperLimit !== '' || row.unitPrice !== '')) ranges.push({ lowerLimit: row.lowerLimit ?? '', upperLimit: row.upperLimit ?? '', unitPrice: row.unitPrice ?? '' }); return ranges.length ? ranges : [{ lowerLimit: '', upperLimit: '', unitPrice: '' }]; }, - syncLegacyLimit(row) { const first = row.limitRanges?.[0] || {}; row.lowerLimit = first.lowerLimit || ''; row.upperLimit = first.upperLimit || ''; if (this.usesRangeUnitPrice(row)) row.unitPrice = first.unitPrice || ''; }, + normalizeRule(rule = {}) { const next = { ...defaultRule(), ...clone(rule) }; if (next.billingType === '阶梯单价' && next.minimumBillingWeight === '') { const rangeMinimum = (Array.isArray(next.limitRanges) ? next.limitRanges : []).find(item => item?.minimumBillingWeight !== '')?.minimumBillingWeight; if (rangeMinimum !== undefined) next.minimumBillingWeight = rangeMinimum; } next.limitRanges = this.normalizeRanges(next); if (!this.usesRangeMinimum(next)) next.limitRanges = next.limitRanges.map(item => ({ ...item, minimumBillingWeight: '' })); this.syncLegacyLimit(next); next.matchCondition = { ...defaultRule().matchCondition, ...(rule.matchCondition || {}) }; return next; }, + normalizeRanges(row) { const ranges = Array.isArray(row.limitRanges) ? row.limitRanges.map(item => ({ lowerLimit: item?.lowerLimit ?? '', upperLimit: item?.upperLimit ?? '', unitPrice: item?.unitPrice === undefined || item?.unitPrice === '' ? row.unitPrice ?? '' : item.unitPrice, minimumBillingWeight: item?.minimumBillingWeight === undefined || item?.minimumBillingWeight === '' ? (this.usesRangeMinimum(row) ? row.minimumBillingWeight ?? '' : '') : item.minimumBillingWeight })).filter(item => item.lowerLimit !== '' || item.upperLimit !== '' || item.unitPrice !== '' || item.minimumBillingWeight !== '') : []; if (!ranges.length && (row.lowerLimit !== '' || row.upperLimit !== '' || row.unitPrice !== '' || row.minimumBillingWeight !== '')) ranges.push({ lowerLimit: row.lowerLimit ?? '', upperLimit: row.upperLimit ?? '', unitPrice: row.unitPrice ?? '', minimumBillingWeight: this.usesRangeMinimum(row) ? row.minimumBillingWeight ?? '' : '' }); return ranges.length ? ranges : [{ lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }]; }, + syncLegacyLimit(row) { const first = row.limitRanges?.[0] || {}; row.lowerLimit = first.lowerLimit || ''; row.upperLimit = first.upperLimit || ''; if (this.usesRangeUnitPrice(row)) row.unitPrice = first.unitPrice || ''; if (this.usesRangeMinimum(row)) row.minimumBillingWeight = first.minimumBillingWeight || ''; }, loadDictionaries() { this.feeCategoryLoading = true; getDictionary({ code: 'fee_category' }).then(res => { this.feeCategories = res.data?.data || []; this.loadRuleItems(); }).finally(() => { this.feeCategoryLoading = false; }); this.unitLoading = true; getDictionary({ code: 'unit_fee' }).then(res => { this.unitOptions = res.data?.data || []; }).finally(() => { this.unitLoading = false; }); }, feeTypeKey(row) { const option = this.feeCategories.find(item => String(item.dictKey) === String(row.feeType) || String(item.dictValue) === String(row.feeType)); return option?.dictKey || row.feeType || ''; }, feeItemOptions(row) { return this.feeItems[this.feeTypeKey(row)] || []; }, @@ -66,23 +66,26 @@ export default { loadFeeItems(value) { const key = this.feeTypeKey({ feeType: value }); if (!key || this.feeItems[key]) return; this.feeItemLoadingMap[key] = true; getFeeItemList(1, 9999, { feeCategory: key }).then(res => { const data = res?.data?.data || res?.data || {}; this.feeItems[key] = Array.isArray(data) ? data : (data.records || []); }).finally(() => { this.feeItemLoadingMap[key] = false; }); }, handleFeeTypeChange(row, value) { row.feeType = this.feeTypeKey({ feeType: value }); row.feeItem = ''; this.loadFeeItems(row.feeType); }, billingTypes(row) { return this.typeMap[row.billingElement] || []; }, - handleElementChange(row) { if (!this.billingTypes(row).includes(row.billingType)) row.billingType = ''; if (!this.canEditMinimum(row)) row.minimumBillingWeight = ''; this.handleTypeChange(row); }, - handleTypeChange(row) { if (!this.canEditLimit(row)) { row.limitRanges = [{ lowerLimit: '', upperLimit: '', unitPrice: '' }]; row.lowerLimit = ''; row.upperLimit = ''; } else { row.limitRanges = this.normalizeRanges(row); this.syncLegacyLimit(row); } }, + handleElementChange(row) { if (!this.billingTypes(row).includes(row.billingType)) row.billingType = ''; if (!this.canEditMinimum(row)) { row.minimumBillingWeight = ''; row.limitRanges = (row.limitRanges || []).map(item => ({ ...item, minimumBillingWeight: '' })); } this.handleTypeChange(row); }, + handleTypeChange(row) { if (!this.canEditMinimum(row)) row.minimumBillingWeight = ''; if (!this.usesRangeMinimum(row)) row.limitRanges = (row.limitRanges || []).map(item => ({ ...item, minimumBillingWeight: '' })); if (!this.canEditLimit(row)) { row.limitRanges = [{ lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }]; row.lowerLimit = ''; row.upperLimit = ''; } else { row.limitRanges = this.normalizeRanges(row); this.syncLegacyLimit(row); } }, canEditLimit(row) { return !this.readonly && Boolean(row.billingElement) && Boolean(row.billingType) && (row.billingType.includes('区间') || row.billingType.includes('阶梯')); }, - usesRangeUnitPrice(row) { return ['区间单价', '阶梯单价'].includes(row.billingType); }, - canEditMinimum(row) { return !this.readonly && ['按重量', '按吨·公里'].includes(row.billingElement); }, - getRanges(row) { return Array.isArray(row.limitRanges) && row.limitRanges.length ? row.limitRanges : [{ lowerLimit: '', upperLimit: '', unitPrice: '' }]; }, - addRange(row, index) { row.limitRanges = this.getRanges(row); row.limitRanges.splice(index + 1, 0, { lowerLimit: '', upperLimit: '', unitPrice: '' }); }, - removeRange(row, index) { row.limitRanges = this.getRanges(row); row.limitRanges.splice(index, 1); if (!row.limitRanges.length) row.limitRanges.push({ lowerLimit: '', upperLimit: '', unitPrice: '' }); this.syncLegacyLimit(row); }, + usesRangeUnitPrice(row) { return ['区间单价', '阶梯单价', '区间阶梯一口价'].includes(row.billingType); }, + usesRangeMinimum(row) { return this.supportsMinimum(row) && row.billingType === '区间单价'; }, + supportsMinimum(row) { return ['按重量', '按吨·公里'].includes(row.billingElement) && Boolean(row.billingType) && !row.billingType.includes('一口价'); }, + canEditMinimum(row) { return !this.readonly && this.supportsMinimum(row); }, + getRanges(row) { return Array.isArray(row.limitRanges) && row.limitRanges.length ? row.limitRanges : [{ lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }]; }, + addRange(row, index) { row.limitRanges = this.getRanges(row); row.limitRanges.splice(index + 1, 0, { lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }); }, + removeRange(row, index) { row.limitRanges = this.getRanges(row); row.limitRanges.splice(index, 1); if (!row.limitRanges.length) row.limitRanges.push({ lowerLimit: '', upperLimit: '', unitPrice: '', minimumBillingWeight: '' }); this.syncLegacyLimit(row); }, limitInput(row, index, prop, value) { row.limitRanges = this.getRanges(row); const text = String(value || '').replace(/[^\d.]/g, ''); const parts = text.split('.'); row.limitRanges[index][prop] = parts.length > 1 ? `${parts[0]}.${parts.slice(1).join('').slice(0, 2)}` : parts[0]; this.syncLegacyLimit(row); }, decimalInput(row, prop, value) { const text = String(value || '').replace(/[^\d.]/g, ''); const parts = text.split('.'); row[prop] = parts.length > 1 ? `${parts[0]}.${parts.slice(1).join('').slice(0, 2)}` : parts[0]; }, rangeUnitPriceInput(row, index, value) { row.limitRanges = this.getRanges(row); const target = { value }; this.decimalInput(target, 'value', value); row.limitRanges[index].unitPrice = target.value; if (index === 0) row.unitPrice = target.value; }, + rangeMinimumInput(row, index, value) { row.limitRanges = this.getRanges(row); const target = { value }; this.decimalInput(target, 'value', value); row.limitRanges[index].minimumBillingWeight = target.value; if (index === 0) row.minimumBillingWeight = target.value; }, addRule() { this.draft.rules.push(defaultRule()); }, copyRule(row) { const next = clone(row); this.draft.rules.push(this.normalizeRule(next)); this.loadFeeItems(next.feeType); }, removeRule(index) { this.draft.rules.splice(index, 1); if (!this.draft.rules.length) this.addRule(); }, validateRules() { const groups = {}; const feeItemSet = new Set(); const required = [['feeType', '费用类型'], ['feeItem', '费用项'], ['billingElement', '计费要素'], ['billingType', '计费类型'], ['billingUnit', '计费单位']]; for (const [i, row] of this.draft.rules.entries()) { const empty = required.find(([key]) => row[key] === undefined || row[key] === null || String(row[key]).trim() === ''); if (empty) { this.$message.warning(`第${i + 1}行${empty[1]}不能为空`); return false; } const feeItem = String(row.feeItem).trim(); if (feeItemSet.has(feeItem)) { this.$message.warning(`费用项“${feeItem}”不能重复`); return false; } feeItemSet.add(feeItem); if (!this.usesRangeUnitPrice(row) && (row.unitPrice === undefined || row.unitPrice === null || String(row.unitPrice).trim() === '')) { this.$message.warning(`第${i + 1}行单价不能为空`); return false; } if (!this.billingTypes(row).includes(row.billingType)) { this.$message.warning('请选择计费要素对应的计费类型'); return false; } if (!this.canEditLimit(row)) continue; const key = row.billingElement; groups[key] = groups[key] || []; for (const range of this.getRanges(row)) { const lower = Number(range.lowerLimit); const upper = Number(range.upperLimit); if (range.lowerLimit === '' || range.upperLimit === '' || Number.isNaN(lower) || Number.isNaN(upper)) { this.$message.warning('请完整填写计费要素上下限'); return false; } if (this.usesRangeUnitPrice(row) && (range.unitPrice === undefined || range.unitPrice === null || String(range.unitPrice).trim() === '')) { this.$message.warning('请为每组计费要素区间填写单价'); return false; } if (lower > upper) { this.$message.warning('计费要素下限不能大于上限'); return false; } groups[key].push({ lower, upper }); } } return this.validateRangeGroups(groups); }, validateRangeGroups(groups) { const precision = 0.000001; for (const [element, ranges] of Object.entries(groups)) { const sorted = [...ranges].sort((a, b) => a.lower - b.lower || a.upper - b.upper); for (let i = 1; i < sorted.length; i += 1) { if (sorted[i].lower < sorted[i - 1].upper - precision) { this.$message.warning(`${element}的计费要素区间不能重叠`); return false; } if (sorted[i].lower > sorted[i - 1].upper + precision) { this.$message.warning(`${element}的计费要素区间必须连续,不能存在间隙`); return false; } } } return true; }, - save() { this.$refs.formRef.validate(valid => { if (!valid || !this.validateRules()) return; const plan = clone(this.draft); plan.rules = plan.rules.map(rule => { const ranges = this.canEditLimit(rule) ? this.getRanges(rule) : []; return { ...rule, unitPrice: this.usesRangeUnitPrice(rule) ? ranges[0]?.unitPrice || '' : rule.unitPrice, limitRanges: ranges, lowerLimit: ranges[0]?.lowerLimit || '', upperLimit: ranges[0]?.upperLimit || '', minimumBillingWeight: this.canEditMinimum(rule) ? rule.minimumBillingWeight : '' }; }); this.$emit('save', plan, this.index); this.visible = false; }); }, + save() { this.$refs.formRef.validate(valid => { if (!valid || !this.validateRules()) return; const plan = clone(this.draft); plan.rules = plan.rules.map(rule => { const ranges = this.canEditLimit(rule) ? this.getRanges(rule) : []; return { ...rule, unitPrice: this.usesRangeUnitPrice(rule) ? ranges[0]?.unitPrice || '' : rule.unitPrice, limitRanges: ranges, lowerLimit: ranges[0]?.lowerLimit || '', upperLimit: ranges[0]?.upperLimit || '', minimumBillingWeight: this.canEditMinimum(rule) ? (this.usesRangeMinimum(rule) ? ranges[0]?.minimumBillingWeight || '' : rule.minimumBillingWeight) : '' }; }); this.$emit('save', plan, this.index); this.visible = false; }); }, openMatch(row, index) { this.matchIndex = index; this.matchForm = { ...defaultRule().matchCondition, ...(row.matchCondition || {}) }; this.matchVisible = true; this.ensureRegions(); this.ensureCargo().then(() => { const path = this.resolveCargoPath(this.matchForm); if (path.length) this.matchCargoChange(path); }); }, ensureRegions() { if (this.regionOptions.length) return Promise.resolve(this.regionOptions); if (this.regionRequest) return this.regionRequest; this.regionLoading = true; this.regionRequest = getRegionLazyTree().then(res => { const raw = res.data?.data || []; this.regionOptions = this.normalizeRegionTree(raw); return this.regionOptions; }).finally(() => { this.regionLoading = false; this.regionRequest = null; }); return this.regionRequest; }, normalizeRegionTree(list) { const map = new Map(); const flat = []; const walk = items => (items || []).forEach(item => { flat.push({ ...item, children: undefined }); if (item.children?.length) walk(item.children); }); walk(list); flat.forEach(item => map.set(String(item.id ?? item.code ?? item.value), { ...item, id: String(item.id ?? item.code ?? item.value), parentId: String(item.parentId ?? item.parentCode ?? ''), children: [] })); const roots = []; map.forEach(node => { const parent = map.get(node.parentId); if (parent && parent !== node) parent.children.push(node); else roots.push(node); }); const china = roots.find(item => ['中国', '中华人民共和国'].includes(item.title || item.name)); const source = china?.children?.length ? china.children : roots; const normalize = (node, level) => ({ ...node, title: node.title || node.name || '', leaf: level === 2, children: level === 1 ? (node.children || []).map(child => normalize(child, 2)) : undefined }); return source.map(node => normalize(node, 1)); }, diff --git a/src/views/business/components/business-crud-page.vue b/src/views/business/components/business-crud-page.vue index 4e90d4c..398df6c 100644 --- a/src/views/business/components/business-crud-page.vue +++ b/src/views/business/components/business-crud-page.vue @@ -230,6 +230,44 @@ + + + +