266 lines
8.4 KiB
Vue
266 lines
8.4 KiB
Vue
<template>
|
||
<div class="app-container" v-loading="loading">
|
||
<!-- 编辑模式:整屏切换,等同独立页面 -->
|
||
<price-edit-panel
|
||
v-if="editVisible"
|
||
:price-set-id="set.priceSetId"
|
||
:psv-id="editPsvId"
|
||
@close="closeEdit"
|
||
/>
|
||
|
||
<template v-else>
|
||
<set-detail-header
|
||
:set="set"
|
||
@back="goList"
|
||
@disable="onDisable"
|
||
@enable="onEnable"
|
||
/>
|
||
|
||
<set-basic-info-card :set="set" />
|
||
|
||
<set-customer-table :set="set" />
|
||
|
||
<set-version-table
|
||
v-model="currentPsvId"
|
||
:versions="set.versions || []"
|
||
@copy-version="onCopyVersion"
|
||
@open-details="onOpenVersionDetails"
|
||
@activate="onActivateVersion"
|
||
@reschedule="onRescheduleVersion"
|
||
@edit="onEditVersion"
|
||
@remove="onRemoveVersion"
|
||
/>
|
||
|
||
<set-version-detail-drawer
|
||
v-model="detailDrawerVisible"
|
||
:version="detailVersion"
|
||
:set-type="set.setType"
|
||
/>
|
||
|
||
<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.versionNo || '-' }}</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:mm:ss"
|
||
:placeholder="activatePh"
|
||
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>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup name="PriceSetDetail">
|
||
import SetDetailHeader from './components/detail/SetDetailHeader.vue'
|
||
import SetBasicInfoCard from './components/detail/SetBasicInfoCard.vue'
|
||
import SetCustomerTable from './components/detail/SetCustomerTable.vue'
|
||
import SetVersionTable from './components/detail/SetVersionTable.vue'
|
||
import SetVersionDetailDrawer from './components/detail/SetVersionDetailDrawer.vue'
|
||
import PriceEditPanel from './components/create/PriceEditPanel.vue'
|
||
import { usePriceSetRefData } from './composables/usePriceSetRefData'
|
||
import {
|
||
getPriceSet, disablePriceSet, enablePriceSet, activatePriceSetVersion, copyPriceSetVersion, deletePriceSetVersion
|
||
} from '@/api/price/set'
|
||
|
||
const { proxy } = getCurrentInstance()
|
||
const route = useRoute()
|
||
const refData = usePriceSetRefData()
|
||
|
||
const loading = ref(false)
|
||
const set = ref({})
|
||
const currentPsvId = ref()
|
||
const detailDrawerVisible = ref(false)
|
||
const detailVersion = ref(null)
|
||
const editVisible = ref(false)
|
||
const editPsvId = ref(undefined)
|
||
|
||
function onOpenVersionDetails(row) {
|
||
detailVersion.value = row || null
|
||
detailDrawerVisible.value = true
|
||
}
|
||
|
||
function load() {
|
||
const id = route.query.priceSetId
|
||
if (!id) return
|
||
loading.value = true
|
||
getPriceSet(id).then(res => {
|
||
set.value = res.data || {}
|
||
const versions = set.value.versions || []
|
||
const cur = set.value.version || versions[0]
|
||
currentPsvId.value = cur ? cur.psvId : undefined
|
||
}).finally(() => {
|
||
loading.value = false
|
||
})
|
||
}
|
||
|
||
function confirmAction(text, request, successText, done) {
|
||
proxy.$modal.confirm(text).then(() => request()).then(() => {
|
||
proxy.$modal.msgSuccess(successText)
|
||
done ? done() : load()
|
||
}).catch(() => {})
|
||
}
|
||
|
||
function onDisable() {
|
||
confirmAction('停用后不再参与计费命中,确认停用?', () => disablePriceSet(set.value.priceSetId), '已停用')
|
||
}
|
||
function onEnable() {
|
||
confirmAction('启用后套餐将重新参与计费命中,确认启用?', () => enablePriceSet(set.value.priceSetId), '已启用')
|
||
}
|
||
function formatNow() {
|
||
const d = new Date()
|
||
const p = n => String(n).padStart(2, '0')
|
||
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate())
|
||
+ ' ' + p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds())
|
||
}
|
||
|
||
const activateVisible = ref(false)
|
||
const activateSubmitting = ref(false)
|
||
const activateFormRef = ref()
|
||
const activateMode = ref('activate')
|
||
const activatePh = '请选择生效时间'
|
||
const activateForm = reactive({
|
||
psvId: undefined,
|
||
versionNo: '',
|
||
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 onActivateVersion(row) {
|
||
if (!row || row.psvId == null) return
|
||
activateMode.value = 'activate'
|
||
activateForm.psvId = row.psvId
|
||
activateForm.versionNo = row.versionNo || ''
|
||
activateForm.effectiveTime = formatNow()
|
||
activateVisible.value = true
|
||
}
|
||
|
||
function onRescheduleVersion(row) {
|
||
if (!row || row.psvId == null) return
|
||
activateMode.value = 'reschedule'
|
||
activateForm.psvId = row.psvId
|
||
activateForm.versionNo = row.versionNo || ''
|
||
activateForm.effectiveTime = row.effectiveTime || formatNow()
|
||
activateVisible.value = true
|
||
}
|
||
|
||
function onActivateClosed() {
|
||
activateMode.value = 'activate'
|
||
activateForm.psvId = undefined
|
||
activateForm.versionNo = ''
|
||
activateForm.effectiveTime = undefined
|
||
activateFormRef.value && activateFormRef.value.clearValidate()
|
||
}
|
||
|
||
function submitActivate() {
|
||
activateFormRef.value.validate(valid => {
|
||
if (!valid) return
|
||
activateSubmitting.value = true
|
||
activatePriceSetVersion(activateForm.psvId, { effectiveTime: activateForm.effectiveTime })
|
||
.then(() => {
|
||
const eff = activateForm.effectiveTime
|
||
const pending = eff && new Date(eff.replace(/-/g, '/')).getTime() > Date.now()
|
||
const okMsg = activateMode.value === 'reschedule'
|
||
? (pending ? '已更新为待生效' : '生效时间已更新,版本已生效')
|
||
: (pending ? '已设为待生效' : '版本已启动')
|
||
proxy.$modal.msgSuccess(okMsg)
|
||
activateVisible.value = false
|
||
load()
|
||
})
|
||
.finally(() => {
|
||
activateSubmitting.value = false
|
||
})
|
||
})
|
||
}
|
||
function onCopyVersion(row) {
|
||
if (!row || row.psvId == null) return
|
||
const hasDraft = (set.value.versions || []).some(v => v && String(v.status) === '0')
|
||
if (hasDraft) {
|
||
proxy.$modal.msgWarning('已有草稿版本,请先启动或删除后再复制')
|
||
return
|
||
}
|
||
proxy.$modal.confirm(
|
||
'确认复制版本 ' + (row.versionNo || '') + '为新草稿?将新增版本并拷贝全部明细。'
|
||
).then(() => copyPriceSetVersion(row.psvId)).then(res => {
|
||
proxy.$modal.msgSuccess('已复制为新版本')
|
||
const newPsvId = res.data
|
||
load()
|
||
if (newPsvId != null) {
|
||
editPsvId.value = newPsvId
|
||
editVisible.value = true
|
||
}
|
||
}).catch(() => {})
|
||
}
|
||
function onRemoveVersion(row) {
|
||
if (!row || row.psvId == null) return
|
||
proxy.$modal.confirm(
|
||
'确认删除草稿版本 ' + (row.versionNo || '') + '?其明细与附加费将一并删除。'
|
||
).then(() => deletePriceSetVersion(row.psvId)).then(() => {
|
||
proxy.$modal.msgSuccess('版本已删除')
|
||
load()
|
||
}).catch(() => {})
|
||
}
|
||
function onEditVersion(row) {
|
||
editPsvId.value = row && row.psvId != null ? row.psvId : undefined
|
||
editVisible.value = true
|
||
}
|
||
|
||
/** 关闭内嵌编辑面板,刷新版本列表(明细数、状态可能变化) */
|
||
function closeEdit() {
|
||
editVisible.value = false
|
||
load()
|
||
}
|
||
function goList() {
|
||
const obj = { path: '/customer/set' }
|
||
if (proxy.$tab) {
|
||
proxy.$tab.closeOpenPage(obj)
|
||
} else {
|
||
proxy.$router.push(obj)
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
refData.loadProducts()
|
||
load()
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.activate-hint {
|
||
margin: -4px 0 0 100px;
|
||
color: #909399;
|
||
font-size: 12px;
|
||
line-height: 1.5;
|
||
}
|
||
</style>
|