修复小程序门店有效期展示
This commit is contained in:
@@ -65,10 +65,12 @@ Page({
|
||||
try {
|
||||
const profile = await profileCache.getProfile(options)
|
||||
const businessExpireDateText = profile.shopBusinessExpireTime ? String(profile.shopBusinessExpireTime).slice(0, 10) : '未设置'
|
||||
const remainingDays = profile.shopBusinessRemainingDays
|
||||
const hasRemainingDays = remainingDays !== null && remainingDays !== undefined && remainingDays !== '' && Number.isFinite(Number(remainingDays))
|
||||
const businessExpiryStatusText = profile.shopBusinessExpired
|
||||
? '已过期,暂不能新增预约'
|
||||
: Number.isFinite(Number(profile.shopBusinessRemainingDays))
|
||||
? `剩余 ${profile.shopBusinessRemainingDays} 天`
|
||||
: hasRemainingDays
|
||||
? `剩余 ${remainingDays} 天`
|
||||
: '有效期未设置'
|
||||
this.setData({ profile, businessExpireDateText, businessExpiryStatusText, 'smsForm.phone': profile.phone || '' })
|
||||
const app = getApp()
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const assert = require('assert')
|
||||
|
||||
let pageDefinition
|
||||
let currentProfile
|
||||
|
||||
global.Page = definition => { pageDefinition = definition }
|
||||
global.wx = {
|
||||
getStorageSync: () => ({}),
|
||||
setStorageSync: () => {},
|
||||
showToast: () => {}
|
||||
}
|
||||
global.getApp = () => ({ setSession: () => {} })
|
||||
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
profileCache.getProfile = async () => currentProfile
|
||||
require('./index')
|
||||
|
||||
async function loadProfile(profile) {
|
||||
currentProfile = profile
|
||||
const page = {
|
||||
data: { ...pageDefinition.data },
|
||||
setData(values) {
|
||||
Object.entries(values).forEach(([key, value]) => {
|
||||
const parts = key.split('.')
|
||||
if (parts.length === 1) this.data[key] = value
|
||||
else this.data[parts[0]] = { ...this.data[parts[0]], [parts[1]]: value }
|
||||
})
|
||||
}
|
||||
}
|
||||
await pageDefinition.loadProfile.call(page)
|
||||
return page.data
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const empty = await loadProfile({
|
||||
type: 2,
|
||||
shopBusinessExpireTime: null,
|
||||
shopBusinessExpired: false,
|
||||
shopBusinessRemainingDays: null
|
||||
})
|
||||
assert.strictEqual(empty.businessExpireDateText, '未设置')
|
||||
assert.strictEqual(empty.businessExpiryStatusText, '有效期未设置')
|
||||
|
||||
const active = await loadProfile({
|
||||
type: 2,
|
||||
shopBusinessExpireTime: '2026-12-31T23:59:59',
|
||||
shopBusinessExpired: false,
|
||||
shopBusinessRemainingDays: 66
|
||||
})
|
||||
assert.strictEqual(active.businessExpireDateText, '2026-12-31')
|
||||
assert.strictEqual(active.businessExpiryStatusText, '剩余 66 天')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in New Issue
Block a user