Files
BMS/bms-front/src/views/price/label/detail.vue
T

374 lines
12 KiB
Vue

<template>
<div class="app-container">
<el-page-header class="page-header" @back="goBack">
<template #content>
<span class="title">{{ setInfo.priceSetName || '打单套餐详情' }}</span>
<el-tag v-if="setInfo.priceSetCode" size="small" class="code-tag">{{ setInfo.priceSetCode }}</el-tag>
<el-tag size="small" type="warning" effect="plain">打单 / LABEL</el-tag>
<el-tag v-if="setInfo.status" size="small" :type="setStatusTag" effect="plain" class="status-tag">{{ setStatusText }}</el-tag>
</template>
<template #extra>
<el-button
v-if="canStartPackage"
type="success"
v-hasPermi="['price:label:edit']"
@click="startPackage"
>启动套餐</el-button>
<el-button
v-if="setInfo.status === 'E'"
type="danger"
plain
v-hasPermi="['price:label:edit']"
@click="onDisablePackage"
>停用</el-button>
<el-button
v-if="setInfo.status === 'S'"
type="success"
plain
v-hasPermi="['price:label:edit']"
@click="onEnablePackage"
>启用</el-button>
</template>
</el-page-header>
<set-customer-table :set="setInfo" @refresh="loadHeader" />
<label-version-table
:versions="versions"
@edit="openEditVersion"
@activate="openActivate"
@reschedule="openReschedule"
@remove="removeVersion"
@open-details="openVersionDetails"
@create-version="openCreateVersion"
/>
<label-version-product-drawer
v-model:visible="productDrawerVisible"
:price-set-id="priceSetId"
:version="activeVersion"
@changed="reloadAll"
/>
<el-dialog
v-model="activateVisible"
:title="activateDialogTitle"
width="460px"
append-to-body
@closed="onActivateClosed"
>
<el-form ref="activateFormRef" :model="activateForm" :rules="activateRules" label-width="100px">
<el-form-item label="版本号">
<span>{{ activateForm.versionLabel }}</span>
</el-form-item>
<el-form-item label="生效时间" prop="effectiveTime">
<el-date-picker
v-model="activateForm.effectiveTime"
type="datetime"
value-format="YYYY-MM-DD HH:00:00"
format="YYYY-MM-DD HH:00"
placeholder="请选择生效时间"
style="width: 100%"
/>
</el-form-item>
<div class="activate-hint">{{ activateDialogHint }}</div>
</el-form>
<template #footer>
<el-button @click="activateVisible = false">取消</el-button>
<el-button type="primary" :loading="activateSubmitting" @click="submitActivate">{{ activateConfirmText }}</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup name="LabelPackageDetail">
import {
getLabelPackage,
listLabelVersions,
activateLabelVersion,
deleteLabelVersion,
enableLabelPackage,
disableLabelPackage,
listLabelCustomer,
addLabelCustomer,
batchAddLabelCustomer,
updateLabelCustomer,
delLabelCustomer
} from '@/api/price/label'
import { priceSetApi } from '@/api/price/set'
import { providePriceSetModule } from '../set/composables/usePriceSetModule'
import SetCustomerTable from '../set/components/detail/SetCustomerTable.vue'
import LabelVersionTable from './components/LabelVersionTable.vue'
import LabelVersionProductDrawer from './components/LabelVersionProductDrawer.vue'
const labelModuleApi = {
...priceSetApi,
listSetCustomer: listLabelCustomer,
addSetCustomer: addLabelCustomer,
batchAddSetCustomer: batchAddLabelCustomer,
updateSetCustomer: updateLabelCustomer,
delSetCustomer: delLabelCustomer
}
providePriceSetModule({
api: labelModuleApi,
permPrefix: 'price:label',
exclusiveQuote: false,
onlyImportFresh: false,
routes: Object.freeze({
list: '/customer/label',
create: '/customer/labelCreate',
detail: '/customer/labelDetail'
}),
labels: Object.freeze({
entity: '打单套餐',
entityCode: '套餐编码',
entityName: '套餐名称',
createButton: '新建打单套餐',
saveProgressTitle: '正在保存打单套餐',
savedSuccess: '打单套餐已保存',
noActiveVersion: '该打单套餐暂无生效版本',
disableConfirm: '停用后该打单套餐不再参与计费命中,确认停用【{name}】?',
enableConfirm: '启用后该打单套餐将重新参与计费命中,确认启用【{name}】?',
basicEditTitle: '修改打单套餐基本信息',
keywordPlaceholder: '套餐编码 / 名称',
detailTitleFallback: '打单套餐详情'
})
})
const { proxy } = getCurrentInstance()
const route = useRoute()
const priceSetId = computed(() => Number(route.query.priceSetId) || null)
const setInfo = reactive({
priceSetId: null,
priceSetCode: '',
priceSetName: '',
priceSetNote: '',
status: '',
customers: []
})
const versions = ref([])
const productDrawerVisible = ref(false)
const activeVersion = ref(null)
const setStatusText = computed(() => {
const map = { D: '待启用', A: '审核中', E: '生效', R: '驳回', S: '已停用' }
return map[setInfo.status] || setInfo.status || '-'
})
const setStatusTag = computed(() => {
const map = { D: 'info', A: 'warning', E: 'success', R: 'danger', S: 'info' }
return map[setInfo.status] || 'info'
})
/** 待启动:有待生效且未设生效时间的版本 */
const startableVersion = computed(() =>
(versions.value || []).find(v => v && String(v.status) === '0' && !v.effectiveTime)
)
const canStartPackage = computed(() =>
setInfo.status !== 'E' && setInfo.status !== 'S' && !!startableVersion.value
)
function startPackage() {
const row = startableVersion.value
if (!row) {
proxy.$modal.msgWarning('没有可启动的版本,请先导入价卡')
return
}
openActivate(row)
}
function onDisablePackage() {
if (!priceSetId.value) return
const name = setInfo.priceSetName || ''
proxy.$modal.confirm('停用后该打单套餐不再参与计费命中,确认停用【' + name + '】?').then(() => {
return disableLabelPackage(priceSetId.value)
}).then(() => {
proxy.$modal.msgSuccess('已停用')
reloadAll()
}).catch(() => {})
}
function onEnablePackage() {
if (!priceSetId.value) return
const name = setInfo.priceSetName || ''
proxy.$modal.confirm('启用后该打单套餐将重新参与计费命中,确认启用【' + name + '】?').then(() => {
return enableLabelPackage(priceSetId.value)
}).then(() => {
proxy.$modal.msgSuccess('已启用')
reloadAll()
}).catch(() => {})
}
const activateVisible = ref(false)
const activateSubmitting = ref(false)
const activateFormRef = ref()
/** activate=启动(首次设生效时间);reschedule=修改已设时间 */
const activateMode = ref('activate')
const activateForm = reactive({
versionNo: null,
versionLabel: '',
effectiveTime: undefined
})
const activateDialogTitle = computed(() =>
activateMode.value === 'reschedule' ? '修改生效时间' : '启动版本'
)
const activateConfirmText = computed(() =>
activateMode.value === 'reschedule' ? '确认修改' : '确认启动'
)
const activateDialogHint = computed(() =>
activateMode.value === 'reschedule'
? '仅待生效版本可修改;精确到小时。未到生效时间仍为待生效,到时自动按生效处理。'
: '启动时设置生效时间;精确到小时。若晚于当前则为待生效,到时自动生效并使套餐进入生效状态。'
)
const activateRules = {
effectiveTime: [{ required: true, message: '请选择生效时间', trigger: 'change' }]
}
function goBack() {
proxy.$router.push('/customer/label')
}
async function loadHeader() {
if (!priceSetId.value) return
const res = await getLabelPackage(priceSetId.value)
const data = res.data || {}
setInfo.priceSetId = data.priceSetId
setInfo.priceSetCode = data.priceSetCode || ''
setInfo.priceSetName = data.priceSetName || ''
setInfo.priceSetNote = data.priceSetNote || ''
setInfo.status = data.status || ''
setInfo.customers = data.customers || []
}
async function loadVersions() {
if (!priceSetId.value) return
const res = await listLabelVersions(priceSetId.value)
versions.value = res.data || []
}
async function reloadAll() {
await loadHeader()
await loadVersions()
}
function openVersionDetails(row) {
activeVersion.value = row || null
productDrawerVisible.value = true
}
/** 跳转新建版本页;已有待生效版时按钮会禁用 */
function openCreateVersion() {
if (!priceSetId.value) return
if ((versions.value || []).some(v => String(v.status) === '0')) {
proxy.$modal.msgWarning('已有待生效版本,请先处理后再新建')
return
}
proxy.$router.push({
path: '/customer/labelCreate',
query: { priceSetId: priceSetId.value, newVersion: '1' }
})
}
/** 编辑版本价卡(不限状态) */
function openEditVersion(row) {
if (!priceSetId.value || !row?.versionNo) return
proxy.$router.push({
path: '/customer/labelCreate',
query: {
priceSetId: priceSetId.value,
versionNo: row.versionNo,
editVersion: '1'
}
})
}
function removeVersion(row) {
if (!priceSetId.value || !row?.versionNo) return
const label = row.versionLabel || ('V' + row.versionNo)
proxy.$modal.confirm('确认删除待生效版本 ' + label + '?该版产品价卡将一起清除。').then(() => {
return deleteLabelVersion(priceSetId.value, row.versionNo)
}).then(() => {
proxy.$modal.msgSuccess('版本已删除')
reloadAll()
}).catch(() => {})
}
function toHourValue(val) {
const text = String(val || '').replace('T', ' ')
if (text.length >= 13) return text.slice(0, 13) + ':00:00'
if (text.length >= 10) return text.slice(0, 10) + ' 00:00:00'
return undefined
}
function formatNowHour() {
const d = new Date()
const pad = n => String(n).padStart(2, '0')
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
+ ' ' + pad(d.getHours()) + ':00:00'
}
function openActivateDialog(row, mode) {
activateMode.value = mode
activateForm.versionNo = row.versionNo
activateForm.versionLabel = row.versionLabel || ('V' + row.versionNo)
if (mode === 'reschedule' && row.effectiveTime) {
activateForm.effectiveTime = toHourValue(row.effectiveTime)
} else {
activateForm.effectiveTime = formatNowHour()
}
activateVisible.value = true
}
/** 首次启动:设置生效时间 */
function openActivate(row) {
openActivateDialog(row, 'activate')
}
/** 已设生效时间后修改 */
function openReschedule(row) {
openActivateDialog(row, 'reschedule')
}
function onActivateClosed() {
activateForm.versionNo = null
activateForm.versionLabel = ''
activateForm.effectiveTime = undefined
activateSubmitting.value = false
activateMode.value = 'activate'
}
function submitActivate() {
activateFormRef.value?.validate(valid => {
if (!valid) return
activateSubmitting.value = true
activateLabelVersion(priceSetId.value, activateForm.versionNo, {
effectiveTime: activateForm.effectiveTime
}).then(res => {
const data = res.data || {}
const fallback = activateMode.value === 'reschedule' ? '生效时间已修改' : '版本已启动'
proxy.$modal.msgSuccess(data.message || res.msg || fallback)
activateVisible.value = false
reloadAll()
}).finally(() => {
activateSubmitting.value = false
})
})
}
watch(priceSetId, async (id) => {
if (!id) return
await reloadAll()
}, { immediate: true })
</script>
<style scoped>
.page-header { margin-bottom: 16px; }
.page-header :deep(.el-page-header__extra) {
margin-left: auto;
}
.title { font-weight: 600; margin-right: 8px; }
.code-tag { margin-right: 8px; }
.status-tag { margin-left: 8px; }
.activate-hint { margin: -4px 0 0 100px; color: #909399; font-size: 12px; line-height: 1.5; }
</style>