|
|
@@ -45,15 +45,32 @@
|
|
|
<span class="pl-stop-product-dual-item__label"
|
|
|
>包装规格<span class="pl-stop-field-required" aria-hidden="true">*</span></span
|
|
|
>
|
|
|
+ <el-select
|
|
|
+ v-if="sharedEditable && useContractPackageSelect(row)"
|
|
|
+ v-model="row.packageSpec"
|
|
|
+ class="pl-plan-product-cell-control pl-stop-product-dual-dict"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ placeholder="包装"
|
|
|
+ @change="() => onPackageChange(row)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="opt in packageOptionsFor(row)"
|
|
|
+ :key="opt"
|
|
|
+ :label="opt"
|
|
|
+ :value="opt"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
<DictSelect
|
|
|
- v-if="sharedEditable"
|
|
|
+ v-else-if="sharedEditable"
|
|
|
v-model="row.packageSpec"
|
|
|
class="pl-plan-product-cell-control pl-stop-product-dual-dict"
|
|
|
dict-type="crm_product_gg"
|
|
|
placeholder="包装"
|
|
|
+ @change="() => onPackageChange(row)"
|
|
|
/>
|
|
|
<span v-else class="pl-stop-product-dual-item__readonly">{{
|
|
|
- resolveDictLabel('crm_product_gg', row.packageSpec)
|
|
|
+ resolvePackageDisplay(row)
|
|
|
}}</span>
|
|
|
</div>
|
|
|
<div class="pl-stop-product-dual-item__field">
|
|
|
@@ -295,17 +312,39 @@
|
|
|
<span>包装规格<span class="pl-stop-field-required" aria-hidden="true">*</span></span>
|
|
|
</template>
|
|
|
<template #default="{ row }">
|
|
|
+ <el-select
|
|
|
+ v-if="sharedEditable && useContractPackageSelect(row)"
|
|
|
+ v-model="row.packageSpec"
|
|
|
+ class="pl-plan-product-cell-control"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ placeholder="请选择包装规格"
|
|
|
+ style="width: 100%"
|
|
|
+ @change="() => onPackageChange(row)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="opt in packageOptionsFor(row)"
|
|
|
+ :key="opt"
|
|
|
+ :label="opt"
|
|
|
+ :value="opt"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
<DictSelect
|
|
|
- v-if="sharedEditable"
|
|
|
+ v-else-if="sharedEditable"
|
|
|
v-model="row.packageSpec"
|
|
|
class="pl-plan-product-cell-control"
|
|
|
dict-type="crm_product_gg"
|
|
|
placeholder="请选择包装规格"
|
|
|
style="width: 100%"
|
|
|
+ @change="() => onPackageChange(row)"
|
|
|
/>
|
|
|
<template v-else>
|
|
|
- <DictTag v-if="row.packageSpec" dict-type="crm_product_gg" :value="row.packageSpec" />
|
|
|
- <span v-else>—</span>
|
|
|
+ <DictTag
|
|
|
+ v-if="row.packageSpec && !useContractPackageSelect(row)"
|
|
|
+ dict-type="crm_product_gg"
|
|
|
+ :value="row.packageSpec"
|
|
|
+ />
|
|
|
+ <span v-else>{{ resolvePackageDisplay(row) }}</span>
|
|
|
</template>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -453,6 +492,7 @@
|
|
|
:contract-id="arrangeQtyContractId"
|
|
|
:product-id="arrangeQtyProductId"
|
|
|
:product-name="arrangeQtyProductName"
|
|
|
+ :package-spec="arrangeQtyPackageSpec"
|
|
|
:exclude-plan-id="excludePlanId"
|
|
|
/>
|
|
|
</div>
|
|
|
@@ -467,6 +507,11 @@
|
|
|
resolveStopActualQty,
|
|
|
resolveStopUnitPrice
|
|
|
} from '@/utils/pl-plan-stop-form'
|
|
|
+ import {
|
|
|
+ normalizePackageSpec,
|
|
|
+ packageSpecsForProduct,
|
|
|
+ type ContractProductRowLite
|
|
|
+ } from '@/utils/pl-plan-contract-product'
|
|
|
import { getDeliveryMethodLabel } from '@/composables/usePlContractToPlan'
|
|
|
import {
|
|
|
applyBrandSelectChange,
|
|
|
@@ -502,6 +547,8 @@
|
|
|
contractId?: string
|
|
|
/** 当前编辑计划 id,计算可安排时排除 */
|
|
|
excludePlanId?: string
|
|
|
+ /** 本合同产品行摘要(有包装选项时包装列用合同下拉) */
|
|
|
+ contractProductRows?: ContractProductRowLite[]
|
|
|
}>(),
|
|
|
{
|
|
|
compact: false,
|
|
|
@@ -511,7 +558,8 @@
|
|
|
showStopArchivePrice: false,
|
|
|
stopArchiveMode: 'load',
|
|
|
contractId: '',
|
|
|
- excludePlanId: ''
|
|
|
+ excludePlanId: '',
|
|
|
+ contractProductRows: () => []
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -540,21 +588,44 @@
|
|
|
const arrangeQtyContractId = ref('')
|
|
|
const arrangeQtyProductId = ref('')
|
|
|
const arrangeQtyProductName = ref('')
|
|
|
+ const arrangeQtyPackageSpec = ref('')
|
|
|
|
|
|
- function cacheKey(productId: string) {
|
|
|
- return `${props.contractId || ''}::${productId}::${props.excludePlanId || ''}`
|
|
|
+ function packageOptionsFor(row: PlanStopProductFormRow) {
|
|
|
+ return packageSpecsForProduct(props.contractProductRows || [], String(row.productId || ''))
|
|
|
}
|
|
|
|
|
|
- async function ensureArrangeQty(productId: string) {
|
|
|
+ function useContractPackageSelect(row: PlanStopProductFormRow) {
|
|
|
+ return Boolean(String(props.contractId || '').trim() && packageOptionsFor(row).length > 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ function resolvePackageDisplay(row: PlanStopProductFormRow) {
|
|
|
+ const raw = normalizePackageSpec(row.packageSpec)
|
|
|
+ if (!raw) return '—'
|
|
|
+ if (useContractPackageSelect(row)) return raw
|
|
|
+ return resolveDictLabel('crm_product_gg', raw)
|
|
|
+ }
|
|
|
+
|
|
|
+ function requiresPackageBeforeArrange(row: PlanStopProductFormRow) {
|
|
|
+ return useContractPackageSelect(row) && !normalizePackageSpec(row.packageSpec)
|
|
|
+ }
|
|
|
+
|
|
|
+ function cacheKey(productId: string, packageSpec?: string | null) {
|
|
|
+ return `${props.contractId || ''}::${productId}::${normalizePackageSpec(packageSpec)}::${props.excludePlanId || ''}`
|
|
|
+ }
|
|
|
+
|
|
|
+ async function ensureArrangeQty(row: PlanStopProductFormRow) {
|
|
|
const cid = String(props.contractId || '').trim()
|
|
|
- const pid = String(productId || '').trim()
|
|
|
+ const pid = String(row.productId || '').trim()
|
|
|
if (!cid || !pid) return null
|
|
|
- const key = cacheKey(pid)
|
|
|
+ if (requiresPackageBeforeArrange(row)) return null
|
|
|
+ const pkg = normalizePackageSpec(row.packageSpec)
|
|
|
+ const key = cacheKey(pid, pkg)
|
|
|
if (key in arrangeQtyCache.value) return arrangeQtyCache.value[key]
|
|
|
try {
|
|
|
const res = await planApi.getContractProductArrangeQty({
|
|
|
contractId: cid,
|
|
|
productId: pid,
|
|
|
+ packageSpec: pkg || undefined,
|
|
|
excludePlanId: props.excludePlanId || undefined
|
|
|
})
|
|
|
const data = pickBxData<ContractProductArrangeQtyDetail>(res) || null
|
|
|
@@ -566,12 +637,25 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function onPackageChange(row: PlanStopProductFormRow) {
|
|
|
+ const pid = String(row.productId || '').trim()
|
|
|
+ if (!pid) return
|
|
|
+ const prefix = `${props.contractId || ''}::${pid}::`
|
|
|
+ const next: Record<string, ContractProductArrangeQtyDetail | null> = {}
|
|
|
+ for (const [key, value] of Object.entries(arrangeQtyCache.value)) {
|
|
|
+ if (!key.startsWith(prefix)) next[key] = value
|
|
|
+ }
|
|
|
+ arrangeQtyCache.value = next
|
|
|
+ void ensureArrangeQty(row)
|
|
|
+ }
|
|
|
+
|
|
|
function formatAvailableDisplay(row: PlanStopProductFormRow) {
|
|
|
const cid = String(props.contractId || '').trim()
|
|
|
if (!cid) return '—'
|
|
|
const pid = String(row.productId || '').trim()
|
|
|
if (!pid) return '—'
|
|
|
- const data = arrangeQtyCache.value[cacheKey(pid)]
|
|
|
+ if (requiresPackageBeforeArrange(row)) return '请先选包装'
|
|
|
+ const data = arrangeQtyCache.value[cacheKey(pid, row.packageSpec)]
|
|
|
if (!data) return '…'
|
|
|
if (!data.hasFixedQty) return '—'
|
|
|
if (data.availableQty == null) return '—'
|
|
|
@@ -581,8 +665,8 @@
|
|
|
function isPlanQtyOverAvailable(row: PlanStopProductFormRow) {
|
|
|
const cid = String(props.contractId || '').trim()
|
|
|
const pid = String(row.productId || '').trim()
|
|
|
- if (!cid || !pid) return false
|
|
|
- const data = arrangeQtyCache.value[cacheKey(pid)]
|
|
|
+ if (!cid || !pid || requiresPackageBeforeArrange(row)) return false
|
|
|
+ const data = arrangeQtyCache.value[cacheKey(pid, row.packageSpec)]
|
|
|
if (!data?.hasFixedQty || data.availableQty == null) return false
|
|
|
const planQty = Number(row.planQty)
|
|
|
if (!Number.isFinite(planQty)) return false
|
|
|
@@ -590,7 +674,11 @@
|
|
|
}
|
|
|
|
|
|
function canOpenArrangeQty(row: PlanStopProductFormRow) {
|
|
|
- return Boolean(String(props.contractId || '').trim() && String(row.productId || '').trim())
|
|
|
+ return Boolean(
|
|
|
+ String(props.contractId || '').trim() &&
|
|
|
+ String(row.productId || '').trim() &&
|
|
|
+ !requiresPackageBeforeArrange(row)
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
function openArrangeQtyDialog(row: PlanStopProductFormRow) {
|
|
|
@@ -599,9 +687,14 @@
|
|
|
return
|
|
|
}
|
|
|
if (!row.productId) return
|
|
|
+ if (requiresPackageBeforeArrange(row)) {
|
|
|
+ ElMessage.warning('请先选择包装规格')
|
|
|
+ return
|
|
|
+ }
|
|
|
arrangeQtyContractId.value = String(props.contractId)
|
|
|
arrangeQtyProductId.value = String(row.productId)
|
|
|
arrangeQtyProductName.value = String(row.productName || row.standardProductName || '')
|
|
|
+ arrangeQtyPackageSpec.value = normalizePackageSpec(row.packageSpec)
|
|
|
arrangeQtyDialogVisible.value = true
|
|
|
}
|
|
|
|
|
|
@@ -611,7 +704,9 @@
|
|
|
props.editable,
|
|
|
props.contractId,
|
|
|
props.excludePlanId,
|
|
|
- (props.products || []).map((p) => p.productId).join(',')
|
|
|
+ (props.products || [])
|
|
|
+ .map((p) => `${p.productId}:${normalizePackageSpec(p.packageSpec)}`)
|
|
|
+ .join(',')
|
|
|
] as const,
|
|
|
() => {
|
|
|
if (!props.editable) return
|
|
|
@@ -619,7 +714,7 @@
|
|
|
if (!cid) return
|
|
|
for (const row of props.products || []) {
|
|
|
const pid = String(row.productId || '').trim()
|
|
|
- if (pid) void ensureArrangeQty(pid)
|
|
|
+ if (pid) void ensureArrangeQty(row)
|
|
|
}
|
|
|
},
|
|
|
{ immediate: true }
|