diff --git a/JC-Salon-WeChat/pages/account-settings/index.js b/JC-Salon-WeChat/pages/account-settings/index.js index 0fd720ac..ce14e22c 100644 --- a/JC-Salon-WeChat/pages/account-settings/index.js +++ b/JC-Salon-WeChat/pages/account-settings/index.js @@ -14,9 +14,7 @@ Page({ timer: null, smsExpanded: false, unbindMode: false, - closureRequest: null, - businessExpireDateText: '', - businessExpiryStatusText: '' + closureRequest: null }, onShow() { this.loadProfile(); this.loadClosureRequest() }, @@ -64,15 +62,7 @@ Page({ this.setData({ loading: true }) 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, 'smsForm.phone': profile.phone || '' }) + this.setData({ profile, 'smsForm.phone': profile.phone || '' }) const app = getApp() const session = auth.getSession() app.setSession({ ...session, userInfo: { ...(session.userInfo || {}), ...profile } }) diff --git a/JC-Salon-WeChat/pages/account-settings/index.test.js b/JC-Salon-WeChat/pages/account-settings/index.test.js index ebd2d4d7..06ea929a 100644 --- a/JC-Salon-WeChat/pages/account-settings/index.test.js +++ b/JC-Salon-WeChat/pages/account-settings/index.test.js @@ -38,8 +38,7 @@ async function run() { shopBusinessExpired: false, shopBusinessRemainingDays: null }) - assert.strictEqual(empty.businessExpireDateText, '未设置') - assert.strictEqual(empty.businessExpiryStatusText, '有效期未设置') + assert.strictEqual(empty.profile.shopBusinessExpireTime, null) const active = await loadProfile({ type: 2, @@ -47,8 +46,7 @@ async function run() { shopBusinessExpired: false, shopBusinessRemainingDays: 66 }) - assert.strictEqual(active.businessExpireDateText, '2026-12-31') - assert.strictEqual(active.businessExpiryStatusText, '剩余 66 天') + assert.strictEqual(active.profile.shopBusinessExpireTime, '2026-12-31T23:59:59') } run().catch(error => { diff --git a/JC-Salon-WeChat/pages/account-settings/index.wxml b/JC-Salon-WeChat/pages/account-settings/index.wxml index 48178d80..eccf4059 100644 --- a/JC-Salon-WeChat/pages/account-settings/index.wxml +++ b/JC-Salon-WeChat/pages/account-settings/index.wxml @@ -1,10 +1,5 @@ 微微信身份已安全关联当前账号已关联 - - 门店经营有效期{{businessExpiryStatusText}} - 有效期至{{businessExpireDateText}} - 到期后暂不可新增普通预约,历史订单、查询和补录不受影响。请联系平台管理员办理续期。 - 手机号 {{profile.phoneVerified == 1 ? (profile.maskedPhone || profile.phone) : '尚未绑定'}}{{profile.phoneVerified == 1 ? '已验证' : '待绑定'}} diff --git a/JC-Salon-WeChat/pages/account-settings/index.wxss b/JC-Salon-WeChat/pages/account-settings/index.wxss index 51de9c1a..e5a31a34 100644 --- a/JC-Salon-WeChat/pages/account-settings/index.wxss +++ b/JC-Salon-WeChat/pages/account-settings/index.wxss @@ -1,5 +1,4 @@ .settings-page { padding-top:24rpx; }.identity-card { display:flex; align-items:center; padding:26rpx; }.identity-mark { display:flex; align-items:center; justify-content:center; width:68rpx; height:68rpx; border-radius:20rpx; background:#e5f4ed; color:#247b63; font-size:28rpx; font-weight:800; }.identity-copy { display:flex; flex:1; flex-direction:column; margin-left:18rpx; }.identity-title,.section-title { color:#17211f; font-size:28rpx; font-weight:800; }.identity-status { margin-top:6rpx; color:#71807a; font-size:21rpx; }.linked-badge,.status-tag { padding:7rpx 14rpx; border-radius:999rpx; background:#e5f2e8; color:#397055; font-size:20rpx; } -.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; } .phone-card { margin-top:20rpx; padding:28rpx; }.phone-status { display:flex; align-items:center; justify-content:space-between; margin-top:20rpx; padding:20rpx; border-radius:14rpx; background:#f3f7f4; color:#71807a; font-size:26rpx; }.status-tag { background:#fff0db; color:#9a682e; }.status-tag.done { background:#e5f2e8; color:#397055; }.wechat-phone-btn,.sms-bind-btn { height:80rpx; margin-top:22rpx; border-radius:14rpx; background:#247b63; color:#fff; font-size:26rpx; line-height:80rpx; }.sms-entry { display:flex; min-height:82rpx; align-items:center; margin-top:22rpx; border-top:1rpx solid #e5ebe7; color:#71807a; font-size:23rpx; }.sms-arrow { margin-left:auto; color:#95a198; font-size:36rpx; transition:transform 180ms ease; }.sms-arrow.expanded { transform:rotate(90deg); }.sms-panel { padding-top:2rpx; }.field input,.code-row input { box-sizing:border-box; height:78rpx; padding:0 20rpx; border:1rpx solid #dde8e0; border-radius:12rpx; background:#f8faf8; }.code-row { display:flex; gap:12rpx; margin-top:14rpx; }.code-row input { min-width:0; flex:1; }.code-row button { width:190rpx; height:78rpx; padding:0; border-radius:12rpx; background:#e7f0ea; color:#426c57; font-size:23rpx; line-height:78rpx; }.sms-bind-btn { background:#eef4f0; color:#247b63; }.account-note { margin:24rpx 18rpx; color:#71807a; font-size:21rpx; line-height:1.6; }.logout-btn { margin-top:52rpx; background:transparent; color:#a24f42; font-size:25rpx; } .privacy-note { margin: 12rpx 0; diff --git a/JC-Salon-WeChat/pages/shop-settings/index.js b/JC-Salon-WeChat/pages/shop-settings/index.js index 7cd3ab61..4400f0d3 100644 --- a/JC-Salon-WeChat/pages/shop-settings/index.js +++ b/JC-Salon-WeChat/pages/shop-settings/index.js @@ -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 }) }, diff --git a/JC-Salon-WeChat/pages/shop-settings/index.test.js b/JC-Salon-WeChat/pages/shop-settings/index.test.js new file mode 100644 index 00000000..57c512be --- /dev/null +++ b/JC-Salon-WeChat/pages/shop-settings/index.test.js @@ -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 +}) diff --git a/JC-Salon-WeChat/pages/shop-settings/index.wxml b/JC-Salon-WeChat/pages/shop-settings/index.wxml index b34e416f..e555991d 100644 --- a/JC-Salon-WeChat/pages/shop-settings/index.wxml +++ b/JC-Salon-WeChat/pages/shop-settings/index.wxml @@ -1,4 +1,9 @@ + + 门店经营有效期{{businessExpiryStatusText}} + 有效期至{{businessExpireDateText}} + 到期后暂不可新增普通预约,历史订单、查询和补录不受影响。请联系平台管理员办理续期。 + 店铺名称 营业开始{{form.startTime}} diff --git a/JC-Salon-WeChat/pages/shop-settings/index.wxss b/JC-Salon-WeChat/pages/shop-settings/index.wxss index 91836ac1..67414de8 100644 --- a/JC-Salon-WeChat/pages/shop-settings/index.wxss +++ b/JC-Salon-WeChat/pages/shop-settings/index.wxss @@ -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;