This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const { showErrorToast } = require('../../utils/toast')
|
||||
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
|
||||
const DEFAULT_COLOR = '#247B63'
|
||||
|
||||
function normalizeColor(value) {
|
||||
const raw = String(value || '').trim()
|
||||
if (!raw) return ''
|
||||
const color = raw[0] === '#' ? raw : `#${raw}`
|
||||
return color.toUpperCase()
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
selected: '#247B63',
|
||||
customColor: '#247B63',
|
||||
id: '',
|
||||
saving: false,
|
||||
selected: DEFAULT_COLOR,
|
||||
customColor: DEFAULT_COLOR,
|
||||
wheelColors: [
|
||||
'#E0627A', '#E7785B', '#E2A64B', '#D8C85C', '#9EBB63', '#63B77B',
|
||||
'#4CB7A6', '#56A7D6', '#5F82D7', '#7C70D4', '#A66BC8', '#CF72A8'
|
||||
@@ -15,6 +30,21 @@ Page({
|
||||
'#6D8491', '#829A9A', '#A9B3A2', '#C6B7D1', '#E0C2B6', '#F0D6A8'
|
||||
]
|
||||
},
|
||||
onLoad(options) {
|
||||
this.setData({ id: options && options.id ? options.id : '' })
|
||||
if (this.data.id) {
|
||||
this.loadColor()
|
||||
}
|
||||
},
|
||||
async loadColor() {
|
||||
try {
|
||||
const detail = await employeesApi.detail(this.data.id)
|
||||
const color = normalizeColor(detail && detail.color) || DEFAULT_COLOR
|
||||
this.setData({ selected: color, customColor: color })
|
||||
} catch (error) {
|
||||
showErrorToast(error, '美甲师颜色加载失败')
|
||||
}
|
||||
},
|
||||
select(event) {
|
||||
const color = event.currentTarget.dataset.color
|
||||
this.setData({ selected: color, customColor: color })
|
||||
@@ -27,14 +57,39 @@ Page({
|
||||
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 (!/^#[0-9A-F]{6}$/.test(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.saving) {
|
||||
return
|
||||
}
|
||||
if (!this.data.id) {
|
||||
wx.showToast({ title: '缺少美甲师信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const color = normalizeColor(this.data.selected)
|
||||
if (!/^#[0-9A-F]{6}$/.test(color)) {
|
||||
wx.showToast({ title: '请选择颜色', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
const saved = await employeesApi.updateColor(this.data.id, color)
|
||||
const savedColor = normalizeColor(saved && saved.color) || color
|
||||
this.setData({ selected: savedColor, customColor: savedColor, saving: false })
|
||||
markPlanningRefresh()
|
||||
wx.showToast({ title: '颜色已保存', icon: 'success' })
|
||||
} catch (error) {
|
||||
this.setData({ saving: false })
|
||||
showErrorToast(error, '颜色保存失败')
|
||||
}
|
||||
},
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user