将门店有效期展示移至店铺设置
This commit is contained in:
@@ -1,9 +1,30 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
profile: {},
|
||||
businessExpireDateText: '未设置',
|
||||
businessExpiryStatusText: '有效期未设置',
|
||||
form: { shopName: BRAND_CONFIG.defaultShopName, startTime: '10:00', endTime: '22:00', defaultDuration: 60, rule: '必须选择已有作品作为项目来源' }
|
||||
},
|
||||
onShow() { this.loadProfile() },
|
||||
async loadProfile(options = {}) {
|
||||
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
|
||||
? '已过期,暂不能新增预约'
|
||||
: hasRemainingDays
|
||||
? `剩余 ${remainingDays} 天`
|
||||
: '有效期未设置'
|
||||
this.setData({ profile, businessExpireDateText, businessExpiryStatusText })
|
||||
} catch (error) {
|
||||
this.setData({ profile: {} })
|
||||
}
|
||||
},
|
||||
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||
onStartChange(event) { this.setData({ 'form.startTime': event.detail.value }) },
|
||||
onEndChange(event) { this.setData({ 'form.endTime': event.detail.value }) },
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
let pageDefinition
|
||||
let currentProfile
|
||||
|
||||
global.Page = definition => { pageDefinition = definition }
|
||||
global.wx = { showToast: () => {} }
|
||||
|
||||
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 天')
|
||||
|
||||
const expired = await loadProfile({
|
||||
type: 2,
|
||||
shopBusinessExpireTime: '2026-10-01T00:00:00',
|
||||
shopBusinessExpired: true,
|
||||
shopBusinessRemainingDays: 0
|
||||
})
|
||||
assert.strictEqual(expired.businessExpiryStatusText, '已过期,暂不能新增预约')
|
||||
|
||||
const shopSettingsWxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
||||
const accountSettingsWxml = fs.readFileSync(path.join(__dirname, '../account-settings/index.wxml'), 'utf8')
|
||||
assert(shopSettingsWxml.includes('wx:if="{{profile.type == 2}}" class="card business-expiry-card"'))
|
||||
assert(!accountSettingsWxml.includes('business-expiry-card'))
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
@@ -1,4 +1,9 @@
|
||||
<view class="page no-tab">
|
||||
<view wx:if="{{profile.type == 2}}" class="card business-expiry-card">
|
||||
<view class="business-expiry-head"><text class="section-title">门店经营有效期</text><text class="business-expiry-status {{profile.shopBusinessExpired ? 'expired' : ''}}">{{businessExpiryStatusText}}</text></view>
|
||||
<view class="business-expiry-date"><text>有效期至</text><strong>{{businessExpireDateText}}</strong></view>
|
||||
<text wx:if="{{profile.shopBusinessExpired}}" class="business-expiry-note">到期后暂不可新增普通预约,历史订单、查询和补录不受影响。请联系平台管理员办理续期。</text>
|
||||
</view>
|
||||
<view class="card form-card">
|
||||
<view class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" /></view>
|
||||
<view class="field"><text class="field-label">营业开始</text><picker mode="time" value="{{form.startTime}}" bindchange="onStartChange"><view class="field-value">{{form.startTime}}</view></picker></view>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
.business-expiry-card { margin-top:20rpx; padding:26rpx; }.business-expiry-head,.business-expiry-date { display:flex; align-items:center; justify-content:space-between; gap:16rpx; }.business-expiry-status { color:#397055; font-size:22rpx; }.business-expiry-status.expired { color:#a24f42; }.business-expiry-date { margin-top:20rpx; padding-top:18rpx; border-top:1rpx solid #e5ebe7; color:#71807a; font-size:23rpx; }.business-expiry-date strong { color:#17211f; font-size:25rpx; }.business-expiry-note { display:block; margin-top:14rpx; color:#a24f42; font-size:21rpx; line-height:1.6; }
|
||||
|
||||
.label-with-help {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user