402 lines
13 KiB
Vue
402 lines
13 KiB
Vue
<template>
|
||
<el-drawer
|
||
:model-value="modelValue"
|
||
:title="title"
|
||
size="72%"
|
||
append-to-body
|
||
destroy-on-close
|
||
@close="close"
|
||
>
|
||
<div class="drawer-body" v-loading="loading">
|
||
<div v-show="!detailOpen" class="product-pane">
|
||
<div class="toolbar">
|
||
<el-input v-model="productKeyword" clearable :placeholder="phSearch" style="width: 220px" />
|
||
<el-button type="primary" @click="noop">查询</el-button>
|
||
<el-button @click="productKeyword = ''">重置</el-button>
|
||
</div>
|
||
<el-alert type="info" :closable="false" show-icon class="mb12" :title="hint" />
|
||
<el-empty v-if="!filteredProducts.length" :description="emptyProduct" :image-size="72" />
|
||
<el-table v-else :data="filteredProducts" border height="calc(100vh - 280px)">
|
||
<el-table-column :label="colCode" min-width="100">
|
||
<template #default="{ row }"><b>{{ row.productCode }}</b></template>
|
||
</el-table-column>
|
||
<el-table-column :label="colName" prop="productName" min-width="140" show-overflow-tooltip />
|
||
<el-table-column :label="colLevel" prop="serviceLevel" width="90" align="center" />
|
||
<el-table-column :label="colCargo" min-width="140" align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.cargoAttr" type="primary" size="small" effect="plain">{{ row.cargoAttr }}</el-tag>
|
||
<span v-else>-</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colRegion" prop="destRegion" width="100" align="center" />
|
||
<el-table-column :label="colAction" width="110" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" @click.stop="openProductDetail(row)">查看明细</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="product-count">{{ productCountText }}</div>
|
||
</div>
|
||
|
||
<div v-show="detailOpen" class="detail-pane">
|
||
<div class="toolbar">
|
||
<el-button link type="primary" @click="backToProducts">
|
||
<el-icon><arrow-left /></el-icon>
|
||
返回产品
|
||
</el-button>
|
||
<span class="detail-title">{{ detailTitleText }}</span>
|
||
<el-input
|
||
v-if="isFixed"
|
||
v-model="detailKeyword"
|
||
clearable
|
||
:placeholder="phDetailSearch"
|
||
style="width: 200px; margin-left: auto"
|
||
/>
|
||
</div>
|
||
<el-table
|
||
v-loading="detailLoading"
|
||
:data="displayDetailRows"
|
||
border
|
||
height="calc(100vh - 260px)"
|
||
:empty-text="emptyDetail"
|
||
:span-method="spanMethod"
|
||
>
|
||
<template v-if="isFixed">
|
||
<el-table-column :label="colCountry" min-width="100">
|
||
<template #default="{ row }">{{ row.countryName || row.countryCode || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colZone" min-width="90">
|
||
<template #default="{ row }">{{ row.zoneName || row.zoneCode || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colWeight" prop="weightLabel" min-width="120" />
|
||
<el-table-column :label="colFv" min-width="130" align="right">
|
||
<template #default="{ row }">
|
||
<el-tooltip placement="top" :disabled="!hasBaseFreight(row)">
|
||
<template #content>
|
||
<span>产品基础运费:{{ formatBase(row.baseFreightPrice, 4) }} RMB/KG</span>
|
||
</template>
|
||
<span class="price-tip">
|
||
<template v-if="row.fvValue == null">
|
||
<span class="unit">未覆盖</span>
|
||
</template>
|
||
<template v-else>
|
||
<span class="hl">{{ row.fvValue }}</span>
|
||
<span class="unit"> RMB/KG</span>
|
||
</template>
|
||
</span>
|
||
</el-tooltip>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colReg" min-width="120" align="right">
|
||
<template #default="{ row }">
|
||
<el-tooltip placement="top" :disabled="!hasBaseReg(row)">
|
||
<template #content>
|
||
<span>产品基础挂号费:{{ formatBase(row.baseRegistrationFee, 2) }} RMB/票</span>
|
||
</template>
|
||
<span class="price-tip">
|
||
<span class="reg">{{ row.fvRegistrationFee }}</span>
|
||
<span class="unit"> RMB/票</span>
|
||
</span>
|
||
</el-tooltip>
|
||
</template>
|
||
</el-table-column>
|
||
</template>
|
||
<el-table-column v-else :label="colDisc" min-width="120" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.discountValue == null" size="small" type="info" effect="plain">默认折扣</el-tag>
|
||
<span v-else class="pct">{{ row.discountValue }}%</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colSc" min-width="200">
|
||
<template #default="{ row }">
|
||
<surcharge-tags :list="row.surcharges || []" :empty-text="noneSc" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column :label="colRound" min-width="100" align="center">
|
||
<template #default="{ row }">{{ roundModeLabel(row.roundMode) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button v-if="detailOpen" @click="backToProducts">返回产品</el-button>
|
||
<el-button @click="close">关闭</el-button>
|
||
</template>
|
||
</el-drawer>
|
||
</template>
|
||
|
||
<script setup name="SetVersionDetailDrawer">
|
||
import { ArrowLeft } from '@element-plus/icons-vue'
|
||
import SurchargeTags from '../SurchargeTags.vue'
|
||
import { isFixedType } from '../../utils/priceSet'
|
||
import { usePriceSetModule } from '../../composables/usePriceSetModule'
|
||
|
||
const { api } = usePriceSetModule()
|
||
|
||
const props = defineProps({
|
||
modelValue: { type: Boolean, default: false },
|
||
version: { type: Object, default: null },
|
||
setType: { type: String, default: 'FIXED' }
|
||
})
|
||
const emit = defineEmits(['update:modelValue'])
|
||
|
||
const { bms_round_mode } = useDict('bms_round_mode')
|
||
|
||
const loading = ref(false)
|
||
const productKeyword = ref('')
|
||
const products = ref([])
|
||
const detailOpen = ref(false)
|
||
const detailLoading = ref(false)
|
||
const detailKeyword = ref('')
|
||
const detailRows = ref([])
|
||
const activeProduct = ref(null)
|
||
|
||
const phSearch = '产品代码/名称'
|
||
const phDetailSearch = '搜索国家/分区'
|
||
const hint = '点击「查看明细」查看国家/重量段明细(仅查看)'
|
||
const emptyProduct = '暂无产品'
|
||
const emptyDetail = '暂无明细'
|
||
const colCode = '产品代码'
|
||
const colName = '产品名称'
|
||
const colLevel = '时效等级'
|
||
const colCargo = '走货属性'
|
||
const colRegion = '目的区域'
|
||
const colAction = '操作'
|
||
const colCountry = '国家'
|
||
const colZone = '分区'
|
||
const colWeight = '重量段'
|
||
const colFv = '运费单价'
|
||
const colReg = '挂号费'
|
||
const colDisc = '产品折扣'
|
||
const colSc = '附加费'
|
||
const colRound = '取值方式'
|
||
const noneSc = '无'
|
||
|
||
const isFixed = computed(() => isFixedType(props.setType))
|
||
const title = computed(() => {
|
||
const v = props.version || {}
|
||
const eff = v.effectiveTime || '未设置生效时间'
|
||
return eff + ' · 版本明细'
|
||
})
|
||
const detailTitleText = computed(() => {
|
||
const p = activeProduct.value || {}
|
||
return (p.productCode || '') + ' · ' + (p.productName || '') + ' · 国家服务价格'
|
||
})
|
||
|
||
const filteredProducts = computed(() => {
|
||
const kw = (productKeyword.value || '').trim().toLowerCase()
|
||
return (products.value || []).filter(p => {
|
||
if (!p || !p.productCode) return false
|
||
if (!kw) return true
|
||
const blob = [p.productCode, p.productName].filter(Boolean).join(' ').toLowerCase()
|
||
return blob.includes(kw)
|
||
})
|
||
})
|
||
|
||
/** Footer: "共 N 个产品" (show filtered vs total when searching). */
|
||
const productCountText = computed(() => {
|
||
const n = filteredProducts.value.length
|
||
const total = (products.value || []).length
|
||
if (n === total) {
|
||
return '共 ' + n + ' 个产品'
|
||
}
|
||
return '共 ' + n + ' 个产品(全部 ' + total + ' 个)'
|
||
})
|
||
|
||
function countryKey(row) {
|
||
return String((row && (row.countryCode || row.countryName)) || '').toUpperCase()
|
||
}
|
||
|
||
function zoneKey(row) {
|
||
return String((row && (row.zoneCode || row.zoneName)) || '')
|
||
}
|
||
|
||
const displayDetailRows = computed(() => {
|
||
const kw = (detailKeyword.value || '').trim().toLowerCase()
|
||
let list = [...(detailRows.value || [])]
|
||
if (kw) {
|
||
list = list.filter(r => {
|
||
if (!r) return false
|
||
const blob = [r.countryName, r.countryCode, r.zoneName, r.zoneCode, r.weightLabel]
|
||
.filter(Boolean).join(' ').toLowerCase()
|
||
return blob.includes(kw)
|
||
})
|
||
}
|
||
list.sort((a, b) => {
|
||
const ca = countryKey(a)
|
||
const cb = countryKey(b)
|
||
if (ca !== cb) return ca.localeCompare(cb)
|
||
const za = zoneKey(a)
|
||
const zb = zoneKey(b)
|
||
if (za !== zb) return za.localeCompare(zb)
|
||
return String((a && a.weightLabel) || '').localeCompare(String((b && b.weightLabel) || ''))
|
||
})
|
||
return list
|
||
})
|
||
|
||
function buildSpans(rows, keyOf) {
|
||
const spans = new Array(rows.length).fill(1)
|
||
let i = 0
|
||
while (i < rows.length) {
|
||
let j = i + 1
|
||
const key = keyOf(rows[i])
|
||
while (j < rows.length && keyOf(rows[j]) === key) j++
|
||
spans[i] = j - i
|
||
for (let k = i + 1; k < j; k++) spans[k] = 0
|
||
i = j
|
||
}
|
||
return spans
|
||
}
|
||
|
||
const countrySpans = computed(() => buildSpans(displayDetailRows.value, countryKey))
|
||
const zoneSpans = computed(() => buildSpans(displayDetailRows.value, r => countryKey(r) + '|' + zoneKey(r)))
|
||
|
||
function spanOf(spans, rowIndex) {
|
||
const rowspan = spans[rowIndex] || 0
|
||
return rowspan > 0 ? { rowspan, colspan: 1 } : { rowspan: 0, colspan: 0 }
|
||
}
|
||
|
||
function spanMethod({ columnIndex, rowIndex }) {
|
||
if (!isFixed.value) return { rowspan: 1, colspan: 1 }
|
||
if (columnIndex === 0) return spanOf(countrySpans.value, rowIndex)
|
||
if (columnIndex === 1) return spanOf(zoneSpans.value, rowIndex)
|
||
return { rowspan: 1, colspan: 1 }
|
||
}
|
||
|
||
function noop() {}
|
||
|
||
function hasBaseFreight(row) {
|
||
return row && row.baseFreightPrice != null && row.baseFreightPrice !== ''
|
||
}
|
||
function hasBaseReg(row) {
|
||
return row && row.baseRegistrationFee != null && row.baseRegistrationFee !== ''
|
||
}
|
||
function formatBase(v, precision) {
|
||
if (v == null || v === '') return '-'
|
||
const n = Number(v)
|
||
if (Number.isNaN(n)) return String(v)
|
||
return n.toFixed(precision)
|
||
}
|
||
function roundModeLabel(mode) {
|
||
const hit = (bms_round_mode.value || []).find(d => d.value === mode)
|
||
return hit ? hit.label : (mode || '四舍五入')
|
||
}
|
||
|
||
function close() {
|
||
emit('update:modelValue', false)
|
||
}
|
||
|
||
function backToProducts() {
|
||
detailOpen.value = false
|
||
activeProduct.value = null
|
||
detailRows.value = []
|
||
detailKeyword.value = ''
|
||
}
|
||
|
||
function normalizeProducts(list) {
|
||
return (list || [])
|
||
.filter(p => p && (p.productCode || p.code))
|
||
.map(p => ({
|
||
productCode: p.productCode || p.code,
|
||
productName: p.productName || p.name || p.productCode || p.code,
|
||
serviceLevel: p.serviceLevel,
|
||
cargoAttr: p.cargoAttr,
|
||
destRegion: p.destRegion,
|
||
taxMode: p.taxMode
|
||
}))
|
||
}
|
||
|
||
async function loadProducts() {
|
||
const v = props.version || {}
|
||
const psvId = v.psvId
|
||
if (!psvId) {
|
||
products.value = []
|
||
return
|
||
}
|
||
loading.value = true
|
||
try {
|
||
const fromVersion = normalizeProducts(v.products)
|
||
if (fromVersion.length) {
|
||
products.value = fromVersion
|
||
return
|
||
}
|
||
const res = await api.listSetDetailOptions(psvId)
|
||
const data = res.data || {}
|
||
products.value = normalizeProducts(data.products || [])
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
async function openProductDetail(row) {
|
||
if (!row || !row.productCode) return
|
||
const psvId = props.version && props.version.psvId
|
||
if (!psvId) return
|
||
activeProduct.value = row
|
||
detailOpen.value = true
|
||
detailKeyword.value = ''
|
||
detailLoading.value = true
|
||
try {
|
||
const res = await api.listSetDetailByProduct(psvId, row.productCode)
|
||
detailRows.value = res.data || []
|
||
} catch (e) {
|
||
detailRows.value = []
|
||
} finally {
|
||
detailLoading.value = false
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => [props.modelValue, props.version && props.version.psvId],
|
||
([open]) => {
|
||
if (open) {
|
||
productKeyword.value = ''
|
||
backToProducts()
|
||
loadProducts()
|
||
}
|
||
}
|
||
)
|
||
</script>
|
||
|
||
<style scoped>
|
||
.drawer-body {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
.toolbar {
|
||
display: flex;
|
||
gap: 8px;
|
||
margin-bottom: 12px;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
}
|
||
.mb12 { margin-bottom: 12px; }
|
||
.product-count {
|
||
margin-top: 10px;
|
||
text-align: right;
|
||
color: #606266;
|
||
font-size: 13px;
|
||
}
|
||
.detail-title {
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
.hl { color: #1890ff; font-weight: 600; }
|
||
.reg { color: #d48806; font-weight: 600; }
|
||
.pct { color: #1890ff; font-weight: 600; }
|
||
.unit { font-size: 12px; color: #909399; }
|
||
.price-tip {
|
||
cursor: help;
|
||
border-bottom: 1px dashed transparent;
|
||
}
|
||
.price-tip:hover {
|
||
border-bottom-color: #c0c4cc;
|
||
}
|
||
:deep(.el-table__row) {
|
||
cursor: pointer;
|
||
}
|
||
</style>
|