fix: 修复月卡无法编辑次数的问题
This commit is contained in:
@@ -55,9 +55,16 @@
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view v-if="isTimeBasedCard" class="field">
|
||||
<text class="field-label">剩余次数</text>
|
||||
<input class="field-input" type="number" v-model="editForm.remainingTimes" placeholder="请输入剩余次数" />
|
||||
<view v-if="selectedCardType" class="field">
|
||||
<text class="field-label">
|
||||
{{ canLeaveTimesEmpty ? '剩余次数(留空不限次)' : '剩余次数' }}
|
||||
</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="number"
|
||||
v-model="editForm.remainingTimes"
|
||||
:placeholder="canLeaveTimesEmpty ? '留空表示不限次' : '请输入剩余次数'"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
@@ -124,7 +131,7 @@ const editForm = ref({
|
||||
membershipId: '' as string | '',
|
||||
cardTypeIndex: 0,
|
||||
cardTypeId: '',
|
||||
remainingTimes: null as number | null,
|
||||
remainingTimes: null as number | string | null,
|
||||
startDate: '',
|
||||
expireDate: '',
|
||||
manuallyEditedExpire: false,
|
||||
@@ -137,9 +144,15 @@ const membershipPickerLabels = computed(() =>
|
||||
existingMemberships.value.map((item) => `${item.cardType.name} · ${item.status}`),
|
||||
)
|
||||
|
||||
const isTimeBasedCard = computed(() => {
|
||||
const card = cardTypes.value[editForm.value.cardTypeIndex]
|
||||
return card && (card.type === 'TIMES' || card.type === 'TRIAL')
|
||||
const selectedCardType = computed(() => cardTypes.value[editForm.value.cardTypeIndex] ?? null)
|
||||
const canLeaveTimesEmpty = computed(() => {
|
||||
const cardType = selectedCardType.value
|
||||
const membership = editingMembership.value
|
||||
if (!cardType || cardType.type !== 'DURATION') return false
|
||||
|
||||
return cardType.totalTimes === null || (
|
||||
membership?.cardTypeId === cardType.id && membership.remainingTimes === null
|
||||
)
|
||||
})
|
||||
|
||||
function calculateExpireDate(startDate: string, durationDays: number): string {
|
||||
@@ -183,11 +196,11 @@ function onMembershipPick(e: { detail: { value: number } }) {
|
||||
function onCardTypeChange(e: { detail: { value: number } }) {
|
||||
const idx = Number(e.detail.value)
|
||||
const cardType = cardTypes.value[idx]
|
||||
if (!cardType) return
|
||||
|
||||
editForm.value.cardTypeIndex = idx
|
||||
editForm.value.cardTypeId = cardType.id
|
||||
if (cardType.totalTimes != null) {
|
||||
editForm.value.remainingTimes = cardType.totalTimes
|
||||
}
|
||||
editForm.value.remainingTimes = cardType.totalTimes
|
||||
if (!editForm.value.manuallyEditedExpire) {
|
||||
editForm.value.startDate = formatDateLocal(new Date())
|
||||
editForm.value.expireDate = calculateExpireDate(formatDateLocal(new Date()), cardType.durationDays)
|
||||
@@ -209,6 +222,17 @@ function onExpireDateChange(e: { detail: { value: string } }) {
|
||||
editForm.value.manuallyEditedExpire = true
|
||||
}
|
||||
|
||||
function parseRemainingTimes(): number | null | undefined {
|
||||
const rawValue = editForm.value.remainingTimes
|
||||
if (rawValue === null || (typeof rawValue === 'string' && rawValue.trim() === '')) {
|
||||
return null
|
||||
}
|
||||
|
||||
const remainingTimes = Number(rawValue)
|
||||
if (!Number.isInteger(remainingTimes) || remainingTimes < 0) return undefined
|
||||
return remainingTimes
|
||||
}
|
||||
|
||||
async function loadPage() {
|
||||
pageLoading.value = true
|
||||
try {
|
||||
@@ -237,6 +261,17 @@ async function onSave() {
|
||||
uni.showToast({ title: '请选择卡类型', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const remainingTimes = parseRemainingTimes()
|
||||
if (remainingTimes === undefined) {
|
||||
uni.showToast({ title: '剩余次数需为非负整数', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (remainingTimes === null && !canLeaveTimesEmpty.value) {
|
||||
uni.showToast({ title: '请输入剩余次数', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await adminStore.updateMemberProfile(userId.value, {
|
||||
@@ -246,7 +281,7 @@ async function onSave() {
|
||||
await adminStore.updateUserMembership(userId.value, {
|
||||
...(editForm.value.membershipId ? { membershipId: editForm.value.membershipId } : {}),
|
||||
cardTypeId: editForm.value.cardTypeId,
|
||||
remainingTimes: isTimeBasedCard.value ? Number(editForm.value.remainingTimes) || 0 : null,
|
||||
remainingTimes,
|
||||
startDate: editForm.value.startDate,
|
||||
expireDate: editForm.value.expireDate,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user