Refactor billing options retrieval to include data permissions and add effective date handling for product imports
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
v-model="currentPsvId"
|
||||
:versions="set.versions || []"
|
||||
@copy-version="onCopyVersion"
|
||||
@create-version="onCreateVersion"
|
||||
@open-details="onOpenVersionDetails"
|
||||
@activate="onActivateVersion"
|
||||
@reschedule="onRescheduleVersion"
|
||||
@@ -52,9 +53,15 @@
|
||||
<el-date-picker
|
||||
v-model="activateForm.effectiveTime"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
format="YYYY-MM-DD HH:00"
|
||||
value-format="YYYY-MM-DD HH:00:00"
|
||||
popper-class="activate-hour-picker"
|
||||
:placeholder="activatePh"
|
||||
:disabled-date="disabledActivateDate"
|
||||
:disabled-hours="disabledActivateHours"
|
||||
style="width: 100%"
|
||||
@change="onActivateTimeChange"
|
||||
@visible-change="onActivatePickerVisible"
|
||||
/>
|
||||
</el-form-item>
|
||||
<div class="activate-hint">{{ activateDialogHint }}</div>
|
||||
@@ -77,11 +84,13 @@ import SetVersionDetailDrawer from './components/detail/SetVersionDetailDrawer.v
|
||||
import PriceEditPanel from './components/create/PriceEditPanel.vue'
|
||||
import { usePriceSetRefData } from './composables/usePriceSetRefData'
|
||||
import {
|
||||
getPriceSet, disablePriceSet, enablePriceSet, activatePriceSetVersion, copyPriceSetVersion, deletePriceSetVersion
|
||||
getPriceSet, disablePriceSet, enablePriceSet, activatePriceSetVersion, copyPriceSetVersion, createPriceSetVersion, deletePriceSetVersion
|
||||
} from '@/api/price/set'
|
||||
import { isDraftVersion } from './utils/priceSet'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const refData = usePriceSetRefData()
|
||||
|
||||
const loading = ref(false)
|
||||
@@ -124,11 +133,35 @@ function onDisable() {
|
||||
function onEnable() {
|
||||
confirmAction('启用后套餐将重新参与计费命中,确认启用?', () => enablePriceSet(set.value.priceSetId), '已启用')
|
||||
}
|
||||
/** Effective time precision: hour only (mm:ss always 00) */
|
||||
function pad2(n) {
|
||||
return String(n).padStart(2, '0')
|
||||
}
|
||||
|
||||
function formatHour(d) {
|
||||
if (!d || Number.isNaN(d.getTime())) return undefined
|
||||
return d.getFullYear() + '-' + pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
|
||||
+ ' ' + pad2(d.getHours()) + ':00:00'
|
||||
}
|
||||
|
||||
function normalizeToHour(val) {
|
||||
if (val == null || val === '') return val
|
||||
if (val instanceof Date) return formatHour(val)
|
||||
const s = String(val).trim().replace('T', ' ')
|
||||
const m = s.match(/^(\d{4}-\d{2}-\d{2})[ ](\d{2})/)
|
||||
if (m) return m[1] + ' ' + m[2] + ':00:00'
|
||||
return formatHour(new Date(s.replace(/-/g, '/'))) || val
|
||||
}
|
||||
|
||||
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())
|
||||
return formatHour(new Date())
|
||||
}
|
||||
|
||||
function onActivateTimeChange(val) {
|
||||
activateForm.effectiveTime = normalizeToHour(val)
|
||||
if (activateFormRef.value) {
|
||||
activateFormRef.value.validateField('effectiveTime')
|
||||
}
|
||||
}
|
||||
|
||||
const activateVisible = ref(false)
|
||||
@@ -147,13 +180,93 @@ const activateDialogTitle = computed(() =>
|
||||
const activateConfirmText = computed(() =>
|
||||
activateMode.value === 'reschedule' ? '确认修改' : '确认启动'
|
||||
)
|
||||
const activateDialogHint = computed(() =>
|
||||
activateMode.value === 'reschedule'
|
||||
const activatePrevEffectiveTime = ref(undefined)
|
||||
const activateEffBeforePrevMsg = '生效时间不能早于上一版本的生效时间'
|
||||
const activateDialogHint = computed(() => {
|
||||
const base = activateMode.value === 'reschedule'
|
||||
? '仅待生效版本可修改;若时间晚于当前仍为待生效,到时自动生效并使上一版本失效。'
|
||||
: '若生效时间晚于当前,版本将进入「待生效」;到时自动生效并使上一版本失效。'
|
||||
)
|
||||
const prev = activatePrevEffectiveTime.value
|
||||
if (!prev) return base
|
||||
return base + '不得早于上一版:' + prev + '。'
|
||||
})
|
||||
const activateRules = {
|
||||
effectiveTime: [{ required: true, message: '请选择生效时间', trigger: 'change' }]
|
||||
effectiveTime: [
|
||||
{ required: true, message: '请选择生效时间', trigger: 'change' },
|
||||
{
|
||||
validator: (_r, v, cb) => {
|
||||
const prev = activatePrevEffectiveTime.value
|
||||
if (!v || !prev) return cb()
|
||||
if (toTimeMs(v) < toTimeMs(prev)) return cb(new Error(activateEffBeforePrevMsg))
|
||||
cb()
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function toTimeMs(val) {
|
||||
if (val == null || val === '') return NaN
|
||||
const n = normalizeToHour(val)
|
||||
if (!n) return NaN
|
||||
return new Date(String(n).replace(/-/g, '/')).getTime()
|
||||
}
|
||||
|
||||
function findPrevVersionEffectiveTime(row) {
|
||||
if (!row) return undefined
|
||||
const versions = set.value.versions || []
|
||||
const curSeq = Number(row.versionSeq) || 0
|
||||
let prev = null
|
||||
for (const v of versions) {
|
||||
if (!v || v.psvId == null || String(v.psvId) === String(row.psvId)) continue
|
||||
const vs = Number(v.versionSeq) || 0
|
||||
if (vs >= curSeq || !v.effectiveTime) continue
|
||||
if (!prev || vs > (Number(prev.versionSeq) || 0)) prev = v
|
||||
}
|
||||
return prev ? normalizeToHour(prev.effectiveTime) : undefined
|
||||
}
|
||||
|
||||
function pickActivateDefaultTime(prev) {
|
||||
const now = formatNow()
|
||||
if (!prev) return now
|
||||
return toTimeMs(now) >= toTimeMs(prev) ? now : prev
|
||||
}
|
||||
|
||||
function disabledActivateDate(date) {
|
||||
const prev = activatePrevEffectiveTime.value
|
||||
if (!prev || !date) return false
|
||||
const prevDay = new Date(String(prev).replace(/-/g, '/'))
|
||||
prevDay.setHours(0, 0, 0, 0)
|
||||
const d = new Date(date)
|
||||
d.setHours(0, 0, 0, 0)
|
||||
return d.getTime() < prevDay.getTime()
|
||||
}
|
||||
|
||||
function disabledActivateHours() {
|
||||
const prev = activatePrevEffectiveTime.value
|
||||
const cur = activateForm.effectiveTime
|
||||
if (!prev) return []
|
||||
const prevD = new Date(String(prev).replace(/-/g, '/'))
|
||||
const curD = cur
|
||||
? new Date(String(normalizeToHour(cur)).replace(/-/g, '/'))
|
||||
: new Date()
|
||||
if (
|
||||
prevD.getFullYear() !== curD.getFullYear() ||
|
||||
prevD.getMonth() !== curD.getMonth() ||
|
||||
prevD.getDate() !== curD.getDate()
|
||||
) {
|
||||
return []
|
||||
}
|
||||
const minH = prevD.getHours()
|
||||
const hours = []
|
||||
for (let h = 0; h < minH; h++) hours.push(h)
|
||||
return hours
|
||||
}
|
||||
|
||||
function onActivatePickerVisible(visible) {
|
||||
if (visible && activateFormRef.value) {
|
||||
activateFormRef.value.validateField('effectiveTime')
|
||||
}
|
||||
}
|
||||
|
||||
function onActivateVersion(row) {
|
||||
@@ -161,7 +274,8 @@ function onActivateVersion(row) {
|
||||
activateMode.value = 'activate'
|
||||
activateForm.psvId = row.psvId
|
||||
activateForm.versionNo = row.versionNo || ''
|
||||
activateForm.effectiveTime = formatNow()
|
||||
activatePrevEffectiveTime.value = findPrevVersionEffectiveTime(row)
|
||||
activateForm.effectiveTime = pickActivateDefaultTime(activatePrevEffectiveTime.value)
|
||||
activateVisible.value = true
|
||||
}
|
||||
|
||||
@@ -170,7 +284,14 @@ function onRescheduleVersion(row) {
|
||||
activateMode.value = 'reschedule'
|
||||
activateForm.psvId = row.psvId
|
||||
activateForm.versionNo = row.versionNo || ''
|
||||
activateForm.effectiveTime = row.effectiveTime || formatNow()
|
||||
activatePrevEffectiveTime.value = findPrevVersionEffectiveTime(row)
|
||||
const cur = normalizeToHour(row.effectiveTime)
|
||||
const prev = activatePrevEffectiveTime.value
|
||||
if (cur && (!prev || toTimeMs(cur) >= toTimeMs(prev))) {
|
||||
activateForm.effectiveTime = cur
|
||||
} else {
|
||||
activateForm.effectiveTime = pickActivateDefaultTime(prev)
|
||||
}
|
||||
activateVisible.value = true
|
||||
}
|
||||
|
||||
@@ -179,12 +300,14 @@ function onActivateClosed() {
|
||||
activateForm.psvId = undefined
|
||||
activateForm.versionNo = ''
|
||||
activateForm.effectiveTime = undefined
|
||||
activatePrevEffectiveTime.value = undefined
|
||||
activateFormRef.value && activateFormRef.value.clearValidate()
|
||||
}
|
||||
|
||||
function submitActivate() {
|
||||
activateFormRef.value.validate(valid => {
|
||||
if (!valid) return
|
||||
activateForm.effectiveTime = normalizeToHour(activateForm.effectiveTime)
|
||||
activateSubmitting.value = true
|
||||
activatePriceSetVersion(activateForm.psvId, { effectiveTime: activateForm.effectiveTime })
|
||||
.then(() => {
|
||||
@@ -202,6 +325,23 @@ function submitActivate() {
|
||||
})
|
||||
})
|
||||
}
|
||||
function onCreateVersion() {
|
||||
const priceSetId = set.value.priceSetId
|
||||
if (priceSetId == null) return
|
||||
const hasDraft = (set.value.versions || []).some(v => v && String(v.status) === '0')
|
||||
if (hasDraft) {
|
||||
proxy.$modal.msgWarning('已有草稿版本,请先启动或删除后再新建')
|
||||
return
|
||||
}
|
||||
createPriceSetVersion(priceSetId).then(res => {
|
||||
const newPsvId = res.data
|
||||
proxy.$modal.msgSuccess('已创建草稿版本,请继续编辑产品价格')
|
||||
router.push({
|
||||
path: '/customer/setCreate',
|
||||
query: { priceSetId, psvId: newPsvId, step: '2', newVersion: '1' }
|
||||
})
|
||||
}).catch(() => {})
|
||||
}
|
||||
function onCopyVersion(row) {
|
||||
if (!row || row.psvId == null) return
|
||||
const hasDraft = (set.value.versions || []).some(v => v && String(v.status) === '0')
|
||||
@@ -231,7 +371,19 @@ function onRemoveVersion(row) {
|
||||
}).catch(() => {})
|
||||
}
|
||||
function onEditVersion(row) {
|
||||
editPsvId.value = row && row.psvId != null ? row.psvId : undefined
|
||||
if (!row || row.psvId == null) return
|
||||
const priceSetId = set.value.priceSetId
|
||||
const noMode = !row.priceBuildMode
|
||||
const noProducts = !(row.products || []).some(p => p && p.productCode)
|
||||
// Empty unfinished draft (new version, not finished): resume create step2 with build-mode choice
|
||||
if (isDraftVersion(row) && noMode && noProducts && priceSetId != null) {
|
||||
router.push({
|
||||
path: '/customer/setCreate',
|
||||
query: { priceSetId, psvId: row.psvId, step: '2', newVersion: '1' }
|
||||
})
|
||||
return
|
||||
}
|
||||
editPsvId.value = row.psvId
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
@@ -263,3 +415,14 @@ onMounted(() => {
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* Hour-only: hide minute/second columns in activate datetime popper */
|
||||
.activate-hour-picker .el-time-spinner__wrapper:nth-child(2),
|
||||
.activate-hour-picker .el-time-spinner__wrapper:nth-child(3) {
|
||||
display: none;
|
||||
}
|
||||
.activate-hour-picker .el-time-spinner__wrapper:nth-child(1) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user