修复店务预约与小程序生产问题
This commit is contained in:
@@ -1,7 +1,28 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
|
||||
function normalizeColor(value) {
|
||||
let color = String(value || '').trim()
|
||||
if (!color) {
|
||||
return ''
|
||||
}
|
||||
if (color[0] !== '#') {
|
||||
color = `#${color}`
|
||||
}
|
||||
if (!/^#[0-9a-fA-F]{6}$/.test(color)) {
|
||||
return ''
|
||||
}
|
||||
return color.toUpperCase()
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
id: '',
|
||||
employee: {},
|
||||
selected: '#7BA7C7',
|
||||
customColor: '#7BA7C7',
|
||||
saving: false,
|
||||
loadError: '',
|
||||
wheelColors: [
|
||||
'#E0627A', '#E7785B', '#E2A64B', '#D8C85C', '#9EBB63', '#63B77B',
|
||||
'#4CB7A6', '#56A7D6', '#5F82D7', '#7C70D4', '#A66BC8', '#CF72A8'
|
||||
@@ -15,26 +36,93 @@ Page({
|
||||
'#6D8491', '#829A9A', '#A9B3A2', '#C6B7D1', '#E0C2B6', '#F0D6A8'
|
||||
]
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({ id: options.id || '' })
|
||||
this.loadDetail()
|
||||
},
|
||||
|
||||
async loadDetail() {
|
||||
const userId = this.data.id
|
||||
if (!userId) {
|
||||
this.setData({ loadError: '员工ID不能为空' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = await employeesApi.detail(userId)
|
||||
const color = normalizeColor(data.color) || this.data.selected
|
||||
this.setData({
|
||||
loadError: '',
|
||||
employee: data,
|
||||
selected: color,
|
||||
customColor: color
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
employee: {},
|
||||
loadError: error.message || '美甲师详情加载失败'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
select(event) {
|
||||
const color = event.currentTarget.dataset.color
|
||||
const color = normalizeColor(event.currentTarget.dataset.color)
|
||||
if (!color) {
|
||||
return
|
||||
}
|
||||
this.setData({ selected: color, customColor: color })
|
||||
},
|
||||
|
||||
selectWheelColor(event) {
|
||||
const color = event.currentTarget.dataset.color
|
||||
const color = normalizeColor(event.currentTarget.dataset.color)
|
||||
if (!color) {
|
||||
return
|
||||
}
|
||||
this.setData({ selected: color, customColor: color })
|
||||
},
|
||||
|
||||
onCustomInput(event) {
|
||||
this.setData({ customColor: event.detail.value })
|
||||
},
|
||||
|
||||
applyCustomColor() {
|
||||
let color = (this.data.customColor || '').trim()
|
||||
if (color && color[0] !== '#') color = `#${color}`
|
||||
if (!/^#[0-9a-fA-F]{6}$/.test(color)) {
|
||||
const color = normalizeColor(this.data.customColor)
|
||||
if (!color) {
|
||||
wx.showToast({ title: '请输入6位色值', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ selected: color.toUpperCase(), customColor: color.toUpperCase() })
|
||||
this.setData({ selected: color, customColor: color })
|
||||
},
|
||||
save() { wx.showToast({ title: '已保存到本地' }) },
|
||||
back() { wx.navigateBack() }
|
||||
|
||||
async save() {
|
||||
if (!this.data.id) {
|
||||
wx.showToast({ title: '员工ID不能为空', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const color = normalizeColor(this.data.selected)
|
||||
if (!color) {
|
||||
wx.showToast({ title: '请选择正确颜色', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
await employeesApi.save({
|
||||
userId: this.data.id,
|
||||
color
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.showToast({ title: '已保存', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
wx.navigateBack()
|
||||
}, 300)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
},
|
||||
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card color-preview" style="background: {{selected}};">{{selected}}</view>
|
||||
<view class="section-title">推荐色</view>
|
||||
<view class="palette recommended-palette">
|
||||
<view wx:for="{{recommendedColors}}" wx:key="*this" class="color-swatch recommended {{selected === item ? 'active' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="select"></view>
|
||||
<view wx:if="{{loadError}}" class="empty card">
|
||||
<text>{{loadError}}</text>
|
||||
<button class="secondary-btn retry-btn" bindtap="loadDetail">重试</button>
|
||||
</view>
|
||||
<view class="section-title">色盘选择</view>
|
||||
<view class="card color-wheel-card">
|
||||
<view class="color-wheel-wrap">
|
||||
<view class="color-wheel">
|
||||
<view wx:for="{{wheelColors}}" wx:key="*this" class="wheel-hit hit-{{index}}" data-color="{{item}}" bindtap="selectWheelColor"></view>
|
||||
<view class="wheel-center" style="background: {{selected}};">
|
||||
<text>{{selected}}</text>
|
||||
|
||||
<block wx:else>
|
||||
<view class="card color-preview" style="background: {{selected}};">
|
||||
<text class="color-preview-name">{{employee.nickname || employee.name || '员工颜色'}}</text>
|
||||
<text class="color-preview-value">{{selected}}</text>
|
||||
</view>
|
||||
<view class="section-title">推荐色</view>
|
||||
<view class="palette recommended-palette">
|
||||
<view wx:for="{{recommendedColors}}" wx:key="*this" class="color-swatch recommended {{selected === item ? 'active' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="select"></view>
|
||||
</view>
|
||||
<view class="section-title">色盘选择</view>
|
||||
<view class="card color-wheel-card">
|
||||
<view class="color-wheel-wrap">
|
||||
<view class="color-wheel">
|
||||
<view wx:for="{{wheelColors}}" wx:key="*this" class="wheel-hit hit-{{index}}" data-color="{{item}}" bindtap="selectWheelColor"></view>
|
||||
<view class="wheel-center" style="background: {{selected}};">
|
||||
<text>{{selected}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="palette-grid compact">
|
||||
<view wx:for="{{paletteColors}}" wx:key="*this" class="palette-dot {{selected === item ? 'active' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="select"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="palette-grid compact">
|
||||
<view wx:for="{{paletteColors}}" wx:key="*this" class="palette-dot {{selected === item ? 'active' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="select"></view>
|
||||
<view class="card custom-color-card">
|
||||
<view class="custom-color-preview" style="background: {{customColor}};"></view>
|
||||
<input class="custom-color-input" value="{{customColor}}" maxlength="7" placeholder="#7BA7C7" bindinput="onCustomInput" />
|
||||
<button class="small-action" bindtap="applyCustomColor">应用</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="card custom-color-card">
|
||||
<view class="custom-color-preview" style="background: {{customColor}};"></view>
|
||||
<input class="custom-color-input" value="{{customColor}}" maxlength="7" placeholder="#7BA7C7" bindinput="onCustomInput" />
|
||||
<button class="small-action" bindtap="applyCustomColor">应用</button>
|
||||
</view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" bindtap="save">保存颜色</button></view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" loading="{{saving}}" bindtap="save">保存颜色</button></view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
.color-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10rpx;
|
||||
height: 168rpx;
|
||||
color: #fff;
|
||||
font-size: 34rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.color-preview-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.color-preview-value {
|
||||
font-size: 34rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.palette {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
|
||||
Reference in New Issue
Block a user