实现预约草稿和资料头像编辑
This commit is contained in:
@@ -3,6 +3,9 @@ const productsApi = require('../../api/products')
|
||||
const customersApi = require('../../api/customers')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
||||
|
||||
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
|
||||
|
||||
function buildClientRequestId(prefix) {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||||
@@ -22,6 +25,49 @@ function canCreateAppointment() {
|
||||
return Number(userInfo.type) !== 3
|
||||
}
|
||||
|
||||
function buildDraftKey() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo || {}
|
||||
return `${DRAFT_STORAGE_PREFIX}:${userInfo.id || 'guest'}:${userInfo.shopId || 'default'}`
|
||||
}
|
||||
|
||||
function hasPresetOptions(options) {
|
||||
return Boolean(options.customerName || options.phone || options.date || options.artistId)
|
||||
}
|
||||
|
||||
function readDraftForm() {
|
||||
try {
|
||||
const draft = wx.getStorageSync(buildDraftKey())
|
||||
return draft && draft.form ? draft.form : null
|
||||
} catch (error) {
|
||||
throw new Error(`读取预约草稿失败:${error.message || error}`)
|
||||
}
|
||||
}
|
||||
|
||||
function writeDraftForm(form) {
|
||||
try {
|
||||
wx.setStorageSync(buildDraftKey(), {
|
||||
form,
|
||||
savedAt: Date.now()
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error(`保存预约草稿失败:${error.message || error}`)
|
||||
}
|
||||
}
|
||||
|
||||
function removeDraftForm() {
|
||||
try {
|
||||
wx.removeStorageSync(buildDraftKey())
|
||||
} catch (error) {
|
||||
throw new Error(`清空预约草稿失败:${error.message || error}`)
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeDuration(value) {
|
||||
const duration = Number(value)
|
||||
return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0
|
||||
}
|
||||
|
||||
function parseProductTags(product) {
|
||||
if (Array.isArray(product.tagList) && product.tagList.length > 0) {
|
||||
return product.tagList
|
||||
@@ -90,6 +136,12 @@ Page({
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductPrice: '',
|
||||
manualProductDescription: '',
|
||||
manualProductTags: '',
|
||||
manualProductTargetAudience: '',
|
||||
manualProductPrecautions: '',
|
||||
manualProductImageFileIds: '',
|
||||
manualProductImageUrl: '',
|
||||
durationMinutes: '',
|
||||
artistId: '',
|
||||
remark: ''
|
||||
@@ -109,17 +161,26 @@ Page({
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free',
|
||||
canCreateAppointment: true,
|
||||
draftSavedAtText: '',
|
||||
manualImageUploading: false,
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const creatable = canCreateAppointment()
|
||||
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null
|
||||
const baseForm = draftForm || {}
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
'form.customerName': options.customerName ? decodeURIComponent(options.customerName) : '',
|
||||
'form.phone': options.phone ? decodeURIComponent(options.phone) : '',
|
||||
'form.appointmentDate': options.date || dateUtil.formatDate(new Date()),
|
||||
'form.artistId': options.artistId || ''
|
||||
form: {
|
||||
...this.data.form,
|
||||
...baseForm,
|
||||
customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''),
|
||||
phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''),
|
||||
appointmentDate: options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()),
|
||||
artistId: options.artistId || baseForm.artistId || ''
|
||||
},
|
||||
draftSavedAtText: draftForm ? '已恢复本机草稿' : ''
|
||||
})
|
||||
if (!creatable) {
|
||||
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
|
||||
@@ -290,7 +351,13 @@ Page({
|
||||
'form.productId': selectedProduct.id,
|
||||
'form.manualProductTitle': '',
|
||||
'form.manualProductPrice': '',
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || 60)
|
||||
'form.manualProductDescription': '',
|
||||
'form.manualProductTags': '',
|
||||
'form.manualProductTargetAudience': '',
|
||||
'form.manualProductPrecautions': '',
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': '',
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || '')
|
||||
})
|
||||
this.closeProductModal()
|
||||
this.checkAvailability()
|
||||
@@ -313,6 +380,40 @@ Page({
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
async chooseManualProductImage() {
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
return
|
||||
}
|
||||
this.setData({ manualImageUploading: true })
|
||||
const uploadResult = await uploadObjectFile(filePath)
|
||||
const fileId = uploadResult.id || uploadResult.fileId
|
||||
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
|
||||
if (!fileId) {
|
||||
throw new Error('作品图片上传成功但未返回文件ID')
|
||||
}
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': String(fileId),
|
||||
'form.manualProductImageUrl': fileUrl
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ manualImageUploading: false })
|
||||
}
|
||||
},
|
||||
|
||||
removeManualProductImage() {
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': ''
|
||||
})
|
||||
},
|
||||
|
||||
onArtistChange(event) {
|
||||
const selectedArtist = this.data.artists[Number(event.detail.value)] || {}
|
||||
this.setData({
|
||||
@@ -328,7 +429,11 @@ Page({
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
const durationMinutes = Number(form.durationMinutes || 0) || 60
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!durationMinutes) {
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
const startMinute = dateUtil.minutesOfDay(form.appointmentTime)
|
||||
const endMinute = startMinute + durationMinutes
|
||||
if (startMinute < dateUtil.minutesOfDay('10:00') || endMinute > dateUtil.minutesOfDay('22:00')) {
|
||||
@@ -380,10 +485,15 @@ Page({
|
||||
}
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!durationMinutes) {
|
||||
wx.showToast({ title: '请填写预约时长', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const availability = await this.checkAvailability()
|
||||
if (!availability.ok) {
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
@@ -395,7 +505,7 @@ Page({
|
||||
...form,
|
||||
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
|
||||
artistId: String(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined,
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
if (form.productId) {
|
||||
@@ -406,17 +516,43 @@ Page({
|
||||
payload.productId = undefined
|
||||
payload.manualProductTitle = String(form.manualProductTitle || '').trim()
|
||||
payload.manualProductPrice = Number(form.manualProductPrice)
|
||||
payload.manualProductDescription = String(form.manualProductDescription || '').trim() || undefined
|
||||
payload.manualProductTags = String(form.manualProductTags || '').trim() || undefined
|
||||
payload.manualProductTargetAudience = String(form.manualProductTargetAudience || '').trim() || undefined
|
||||
payload.manualProductPrecautions = String(form.manualProductPrecautions || '').trim() || undefined
|
||||
payload.manualProductImageFileIds = String(form.manualProductImageFileIds || '').trim() || undefined
|
||||
}
|
||||
const result = await planningApi.createAppointment(payload)
|
||||
removeDraftForm()
|
||||
markPlanningRefresh()
|
||||
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
saveDraft() {
|
||||
try {
|
||||
writeDraftForm(this.data.form)
|
||||
this.setData({ draftSavedAtText: '草稿已保存到本机' })
|
||||
wx.showToast({ title: '草稿已保存', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '草稿保存失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
clearDraft() {
|
||||
try {
|
||||
removeDraftForm()
|
||||
this.setData({ draftSavedAtText: '' })
|
||||
wx.showToast({ title: '草稿已清空', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '草稿清空失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">预计时长</text>
|
||||
<input value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" type="number" placeholder="默认读取作品时长" />
|
||||
<text class="field-label required">预计时长</text>
|
||||
<input value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" type="number" placeholder="请输入预约时长" />
|
||||
<text class="unit">分钟</text>
|
||||
</view>
|
||||
<view class="field">
|
||||
@@ -62,7 +62,12 @@
|
||||
|
||||
<view class="capacity-tip card">
|
||||
<text class="tip-title">容量校验</text>
|
||||
<text class="tip-text">保存时会校验营业时间、美甲师休息和同时间段容量,冲突会直接拦截。</text>
|
||||
<text class="tip-text">提交预约时会校验营业时间、美甲师休息和同时间段容量,冲突会直接拦截。</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{draftSavedAtText}}" class="draft-tip card">
|
||||
<text>{{draftSavedAtText}}</text>
|
||||
<button class="text-btn draft-clear" bindtap="clearDraft">清空</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{conflictTip}}" class="availability-tip card {{conflictLevel}}">
|
||||
@@ -103,12 +108,27 @@
|
||||
<input value="{{form.manualProductTitle}}" data-field="manualProductTitle" bindinput="onInput" placeholder="作品名称" />
|
||||
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" type="digit" placeholder="价格" />
|
||||
</view>
|
||||
<textarea class="manual-textarea" value="{{form.manualProductDescription}}" data-field="manualProductDescription" bindinput="onInput" placeholder="作品描述(选填)" />
|
||||
<view class="manual-grid single">
|
||||
<input value="{{form.manualProductTags}}" data-field="manualProductTags" bindinput="onInput" placeholder="标签,多个用逗号分隔(选填)" />
|
||||
<input value="{{form.manualProductTargetAudience}}" data-field="manualProductTargetAudience" bindinput="onInput" placeholder="适合人群(选填)" />
|
||||
<input value="{{form.manualProductPrecautions}}" data-field="manualProductPrecautions" bindinput="onInput" placeholder="注意事项(选填)" />
|
||||
</view>
|
||||
<view class="manual-image-row">
|
||||
<image wx:if="{{form.manualProductImageUrl}}" class="manual-image" src="{{form.manualProductImageUrl}}" mode="aspectFill"></image>
|
||||
<view wx:else class="manual-image placeholder">图</view>
|
||||
<button class="secondary-btn image-btn" loading="{{manualImageUploading}}" bindtap="chooseManualProductImage">上传图片</button>
|
||||
<button wx:if="{{form.manualProductImageUrl}}" class="text-btn image-remove" bindtap="removeManualProductImage">移除</button>
|
||||
</view>
|
||||
<button class="secondary-btn manual-btn" bindtap="useManualProduct">使用手动预约作品</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<button wx:if="{{canCreateAppointment}}" class="primary-btn" loading="{{loading}}" bindtap="submit">保存预约</button>
|
||||
<view wx:if="{{canCreateAppointment}}" class="action-row">
|
||||
<button class="secondary-btn draft-btn" bindtap="saveDraft">保存草稿</button>
|
||||
<button class="primary-btn submit-btn" loading="{{loading}}" bindtap="submit">提交预约</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -147,6 +147,21 @@
|
||||
color: #c36a6a;
|
||||
}
|
||||
|
||||
.draft-tip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin-top: 16rpx;
|
||||
padding: 18rpx 22rpx;
|
||||
color: #6f655b;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.draft-clear {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
@@ -228,7 +243,7 @@
|
||||
}
|
||||
|
||||
.product-list {
|
||||
max-height: 560rpx;
|
||||
max-height: 440rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
@@ -355,6 +370,11 @@
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.manual-grid.single {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.manual-grid input {
|
||||
height: 70rpx;
|
||||
padding: 0 18rpx;
|
||||
@@ -364,6 +384,62 @@
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.manual-textarea {
|
||||
width: 100%;
|
||||
min-height: 120rpx;
|
||||
margin-top: 14rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #fffaf4;
|
||||
color: #302923;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.manual-image-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.manual-image {
|
||||
flex: 0 0 auto;
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #efe5da;
|
||||
}
|
||||
|
||||
.manual-image.placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #b79b82;
|
||||
font-size: 26rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.image-btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.image-remove {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.manual-btn {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.action-row {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.draft-btn,
|
||||
.submit-btn {
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
||||
|
||||
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
|
||||
const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
|
||||
@@ -20,8 +21,11 @@ Page({
|
||||
phone: '',
|
||||
account: '',
|
||||
password: DEFAULT_EMPLOYEE_PASSWORD,
|
||||
wechatId: ''
|
||||
}
|
||||
wechatId: '',
|
||||
avatar: '',
|
||||
avatarUrl: ''
|
||||
},
|
||||
avatarUploading: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -90,11 +94,43 @@ Page({
|
||||
phone: '',
|
||||
account: '',
|
||||
password: DEFAULT_EMPLOYEE_PASSWORD,
|
||||
wechatId: ''
|
||||
wechatId: '',
|
||||
avatar: '',
|
||||
avatarUrl: ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async chooseEmployeeAvatar() {
|
||||
if (this.data.avatarUploading || this.data.creating) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
return
|
||||
}
|
||||
this.setData({ avatarUploading: true })
|
||||
const uploadResult = await uploadObjectFile(filePath)
|
||||
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
|
||||
this.setData({
|
||||
'createForm.avatar': avatarUrl,
|
||||
'createForm.avatarUrl': avatarUrl
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ avatarUploading: false })
|
||||
}
|
||||
},
|
||||
|
||||
removeEmployeeAvatar() {
|
||||
this.setData({
|
||||
'createForm.avatar': '',
|
||||
'createForm.avatarUrl': ''
|
||||
})
|
||||
},
|
||||
|
||||
async submitEmployee() {
|
||||
const form = this.data.createForm
|
||||
const nickname = String(form.nickname || '').trim()
|
||||
@@ -115,6 +151,7 @@ Page({
|
||||
account,
|
||||
password,
|
||||
wechatId,
|
||||
avatar: form.avatar || undefined,
|
||||
type: 3
|
||||
})
|
||||
wx.showToast({ title: '美甲师已新增', icon: 'success' })
|
||||
|
||||
@@ -34,6 +34,14 @@
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeCreateModal">×</view>
|
||||
</view>
|
||||
<view class="avatar-upload">
|
||||
<view wx:if="{{createForm.avatarUrl}}" class="avatar-preview image-avatar">
|
||||
<image src="{{createForm.avatarUrl}}" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view wx:else class="avatar-preview">头像</view>
|
||||
<button class="secondary-btn avatar-btn" loading="{{avatarUploading}}" bindtap="chooseEmployeeAvatar">上传头像</button>
|
||||
<button wx:if="{{createForm.avatarUrl}}" class="text-btn avatar-remove" bindtap="removeEmployeeAvatar">移除</button>
|
||||
</view>
|
||||
<view class="form-grid">
|
||||
<view class="modal-field">
|
||||
<text class="required-label">姓名</text>
|
||||
|
||||
@@ -169,6 +169,46 @@
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.avatar-upload {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 18rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f7efe7;
|
||||
}
|
||||
|
||||
.avatar-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
background: #6f8f83;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.avatar-preview image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.avatar-btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.avatar-remove {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const userApi = require('../../api/user')
|
||||
const auth = require('../../utils/auth')
|
||||
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
|
||||
|
||||
function resolveRoleText(type) {
|
||||
const role = Number(type)
|
||||
@@ -13,7 +16,19 @@ Page({
|
||||
shopName: BRAND_CONFIG.defaultShopName,
|
||||
phone: '店长端',
|
||||
roleText: '管理端',
|
||||
userInfo: {},
|
||||
editModalVisible: false,
|
||||
profileSaving: false,
|
||||
avatarUploading: false,
|
||||
profileForm: {
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
contactPhone: '',
|
||||
wechatId: '',
|
||||
signature: ''
|
||||
},
|
||||
menus: [
|
||||
{ title: '个人信息', action: 'editProfile' },
|
||||
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
||||
{ title: '数据导出', url: '/pages/export/index' },
|
||||
{ title: '修改密码', url: '/pages/password/index' },
|
||||
@@ -22,16 +37,145 @@ Page({
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.refreshFromSession()
|
||||
this.loadProfile()
|
||||
},
|
||||
|
||||
refreshFromSession() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo || {}
|
||||
this.setData({
|
||||
shopName: app.globalData.shopName || BRAND_CONFIG.appName,
|
||||
phone: userInfo.phone || userInfo.account || '店长端',
|
||||
roleText: resolveRoleText(userInfo.type)
|
||||
phone: userInfo.contactPhone || userInfo.phone || userInfo.account || '店长端',
|
||||
roleText: resolveRoleText(userInfo.type),
|
||||
userInfo
|
||||
})
|
||||
},
|
||||
|
||||
go(event) {
|
||||
const action = event.currentTarget.dataset.action
|
||||
if (action === 'editProfile') {
|
||||
this.openEditProfile()
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
||||
},
|
||||
|
||||
async loadProfile() {
|
||||
try {
|
||||
const profile = await userApi.info()
|
||||
this.syncProfileToSession(profile)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '个人信息加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
syncProfileToSession(profile) {
|
||||
const app = getApp()
|
||||
const session = auth.getSession()
|
||||
const currentUserInfo = session.userInfo || app.globalData.userInfo || {}
|
||||
const nextUserInfo = {
|
||||
...currentUserInfo,
|
||||
id: profile.id || currentUserInfo.id,
|
||||
account: profile.account || currentUserInfo.account,
|
||||
nickname: profile.nickname || '',
|
||||
avatar: profile.avatar || '',
|
||||
phone: profile.phone || currentUserInfo.phone || '',
|
||||
contactPhone: profile.contactPhone || '',
|
||||
wechatId: profile.wechatId || '',
|
||||
signature: profile.signature || '',
|
||||
type: profile.type || currentUserInfo.type,
|
||||
shopId: profile.shopId || currentUserInfo.shopId
|
||||
}
|
||||
app.setSession({
|
||||
...session,
|
||||
userInfo: nextUserInfo
|
||||
})
|
||||
this.setData({
|
||||
userInfo: nextUserInfo,
|
||||
phone: nextUserInfo.contactPhone || nextUserInfo.phone || nextUserInfo.account || '店长端',
|
||||
roleText: resolveRoleText(nextUserInfo.type)
|
||||
})
|
||||
},
|
||||
|
||||
openEditProfile() {
|
||||
const userInfo = this.data.userInfo || {}
|
||||
this.setData({
|
||||
editModalVisible: true,
|
||||
profileForm: {
|
||||
nickname: userInfo.nickname || '',
|
||||
avatar: userInfo.avatar || '',
|
||||
contactPhone: userInfo.contactPhone || '',
|
||||
wechatId: userInfo.wechatId || '',
|
||||
signature: userInfo.signature || ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
closeEditProfile() {
|
||||
if (this.data.profileSaving || this.data.avatarUploading) {
|
||||
return
|
||||
}
|
||||
this.setData({ editModalVisible: false })
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
},
|
||||
|
||||
onProfileInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`profileForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
async chooseProfileAvatar() {
|
||||
if (this.data.avatarUploading || this.data.profileSaving) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
return
|
||||
}
|
||||
this.setData({ avatarUploading: true })
|
||||
const avatar = await uploadProfileImage(filePath)
|
||||
this.setData({ 'profileForm.avatar': avatar })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ avatarUploading: false })
|
||||
}
|
||||
},
|
||||
|
||||
removeProfileAvatar() {
|
||||
this.setData({ 'profileForm.avatar': '' })
|
||||
},
|
||||
|
||||
async saveProfile() {
|
||||
const form = this.data.profileForm
|
||||
const nickname = String(form.nickname || '').trim()
|
||||
if (!nickname) {
|
||||
wx.showToast({ title: '请填写昵称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ profileSaving: true })
|
||||
try {
|
||||
await userApi.updateInfo({
|
||||
nickname,
|
||||
avatar: form.avatar || '',
|
||||
contactPhone: String(form.contactPhone || '').trim(),
|
||||
wechatId: String(form.wechatId || '').trim(),
|
||||
signature: String(form.signature || '').trim()
|
||||
})
|
||||
const profile = await userApi.info()
|
||||
this.syncProfileToSession(profile)
|
||||
this.setData({ editModalVisible: false })
|
||||
wx.showToast({ title: '已保存', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ profileSaving: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -11,9 +11,55 @@
|
||||
</view>
|
||||
|
||||
<view class="section menu-list card">
|
||||
<view wx:for="{{menus}}" wx:key="url" class="menu-row" data-url="{{item.url}}" bindtap="go">
|
||||
<view wx:for="{{menus}}" wx:key="title" class="menu-row" data-url="{{item.url}}" data-action="{{item.action}}" bindtap="go">
|
||||
<text>{{item.title}}</text>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{editModalVisible}}" class="modal-mask" bindtap="closeEditProfile">
|
||||
<view class="profile-modal" catchtap="stopTap">
|
||||
<view class="modal-head">
|
||||
<text class="modal-title">个人信息</text>
|
||||
<view class="modal-close" bindtap="closeEditProfile">×</view>
|
||||
</view>
|
||||
<view class="profile-avatar-row">
|
||||
<view wx:if="{{profileForm.avatar}}" class="profile-avatar image-avatar">
|
||||
<image src="{{profileForm.avatar}}" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view wx:else class="profile-avatar">头像</view>
|
||||
<button class="secondary-btn avatar-btn" loading="{{avatarUploading}}" bindtap="chooseProfileAvatar">上传头像</button>
|
||||
<button wx:if="{{profileForm.avatar}}" class="text-btn avatar-remove" bindtap="removeProfileAvatar">移除</button>
|
||||
</view>
|
||||
<view class="modal-field">
|
||||
<text class="required-label">昵称</text>
|
||||
<input value="{{profileForm.nickname}}" data-field="nickname" bindinput="onProfileInput" placeholder="请输入昵称" />
|
||||
</view>
|
||||
<view class="modal-field readonly-field">
|
||||
<text>登录账号</text>
|
||||
<view>{{userInfo.account || '未设置'}}</view>
|
||||
</view>
|
||||
<view class="modal-field readonly-field">
|
||||
<text>身份</text>
|
||||
<view>{{roleText}}</view>
|
||||
</view>
|
||||
<view class="modal-field readonly-field">
|
||||
<text>登录手机号</text>
|
||||
<view>{{userInfo.phone || '未绑定'}}</view>
|
||||
</view>
|
||||
<view class="modal-field">
|
||||
<text>联系电话</text>
|
||||
<input value="{{profileForm.contactPhone}}" data-field="contactPhone" bindinput="onProfileInput" type="number" placeholder="请输入联系电话" />
|
||||
</view>
|
||||
<view class="modal-field">
|
||||
<text>微信号</text>
|
||||
<input value="{{profileForm.wechatId}}" data-field="wechatId" bindinput="onProfileInput" placeholder="请输入微信号" />
|
||||
</view>
|
||||
<view class="modal-field">
|
||||
<text>签名</text>
|
||||
<textarea value="{{profileForm.signature}}" data-field="signature" bindinput="onProfileInput" placeholder="请输入个人签名" />
|
||||
</view>
|
||||
<button class="primary-btn modal-submit" loading="{{profileSaving}}" bindtap="saveProfile">保存个人信息</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -85,3 +85,172 @@
|
||||
color: #b0a79e;
|
||||
font-size: 44rpx;
|
||||
}
|
||||
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: center;
|
||||
background: rgba(18, 15, 12, 0.48);
|
||||
animation: maskIn 180ms ease both;
|
||||
}
|
||||
|
||||
.profile-modal {
|
||||
width: 100%;
|
||||
max-height: 88vh;
|
||||
overflow-y: auto;
|
||||
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
|
||||
border-radius: 28rpx 28rpx 0 0;
|
||||
background: #fffaf4;
|
||||
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
|
||||
animation: modalUp 220ms ease both;
|
||||
}
|
||||
|
||||
.modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
color: #27211d;
|
||||
font-size: 34rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48rpx;
|
||||
min-width: 48rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 50%;
|
||||
border: 1rpx solid #e4d8ca;
|
||||
background: #fffaf4;
|
||||
color: transparent;
|
||||
font-size: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.modal-close::before,
|
||||
.modal-close::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 22rpx;
|
||||
height: 3rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #61554c;
|
||||
}
|
||||
|
||||
.modal-close::before {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.modal-close::after {
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.profile-avatar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 18rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f7efe7;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
background: #6f8f83;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.profile-avatar image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.avatar-btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.avatar-remove {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.modal-field {
|
||||
margin-bottom: 16rpx;
|
||||
padding: 16rpx 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f7efe7;
|
||||
}
|
||||
|
||||
.modal-field text {
|
||||
display: block;
|
||||
margin-bottom: 8rpx;
|
||||
color: #6c5f54;
|
||||
font-size: 24rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.modal-field input,
|
||||
.modal-field textarea,
|
||||
.readonly-field view {
|
||||
width: 100%;
|
||||
color: #2c2722;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.modal-field input,
|
||||
.readonly-field view {
|
||||
min-height: 58rpx;
|
||||
line-height: 58rpx;
|
||||
}
|
||||
|
||||
.modal-field textarea {
|
||||
min-height: 120rpx;
|
||||
}
|
||||
|
||||
.readonly-field view {
|
||||
color: #7f756b;
|
||||
}
|
||||
|
||||
.modal-submit {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
@keyframes maskIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes modalUp {
|
||||
from {
|
||||
transform: translateY(40rpx);
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user