|
|
|
@@ -0,0 +1,49 @@
|
|
|
|
|
const planningApi = require('../../api/planning')
|
|
|
|
|
const employeesApi = require('../../api/employees')
|
|
|
|
|
const productsApi = require('../../api/products')
|
|
|
|
|
const customersApi = require('../../api/customers')
|
|
|
|
|
const dateUtil = require('../../utils/date')
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: { form: { serviceDate: dateUtil.formatDate(new Date()), manualProductTitle: '', amount: '', customerName: '', phone: '', serviceTime: '', status: 4, remark: '', artistId: '', productId: '', customerUserId: '' }, artists: [], artistOptions: [], allProductOptions: [], productOptions: [], customerOptions: [], allCustomerOptions: [], productSelectorVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProductTitle: '', submitting: false },
|
|
|
|
|
onLoad() { this.loadArtists(); this.loadProducts(); this.loadCustomers() },
|
|
|
|
|
async loadArtists() {
|
|
|
|
|
try {
|
|
|
|
|
const result = await employeesApi.list({ page: 1, size: 100 })
|
|
|
|
|
const list = result.list || result || []
|
|
|
|
|
const normalized = list.map(item => ({ ...item, name: item.name || item.nickname || item.account || `员工${item.id}` }))
|
|
|
|
|
this.setData({ artists: normalized, artistOptions: normalized.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: '', 'form.artistId': '' })
|
|
|
|
|
} catch (error) { wx.showToast({ title: error.message || '员工加载失败', icon: 'none' }) }
|
|
|
|
|
},
|
|
|
|
|
async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); const list = result.list || result || []; const options = list.map(item => ({ id: item.id, title: item.title, price: item.price, subtitle: item.price == null ? '' : `¥${item.price}` })); this.setData({ allProductOptions: options, productOptions: options, productError: '' }) } catch (error) { this.setData({ productError: error.message || '项目加载失败' }) } finally { this.setData({ loadingProducts: false }) } },
|
|
|
|
|
async loadCustomers() { this.setData({ loadingCustomers: true }); try { const result = await customersApi.list({ page: 1, size: 30 }); const list = result.list || result || []; const options = list.map(item => ({ id: item.id, title: item.nickname || item.name || item.account, subtitle: item.phone || item.contactPhone || '' })); this.setData({ allCustomerOptions: options, customerOptions: options, customerError: '' }) } catch (error) { this.setData({ customerError: error.message || '客户加载失败' }) } finally { this.setData({ loadingCustomers: false }) } },
|
|
|
|
|
openProductSelector() { this.setData({ productSelectorVisible: true }) },
|
|
|
|
|
closeProductSelector() { this.setData({ productSelectorVisible: false }) },
|
|
|
|
|
openArtistSelector() { this.setData({ artistSelectorVisible: true }) },
|
|
|
|
|
closeArtistSelector() { this.setData({ artistSelectorVisible: false }) },
|
|
|
|
|
openCustomerSelector() { this.setData({ customerSelectorVisible: true }) },
|
|
|
|
|
closeCustomerSelector() { this.setData({ customerSelectorVisible: false }) },
|
|
|
|
|
searchProducts(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ productKeyword: keyword, productOptions: this.data.allProductOptions.filter(item => !keyword || String(item.title).toLowerCase().includes(keyword)) }) },
|
|
|
|
|
searchArtists(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ artistKeyword: keyword, artistOptions: this.data.artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })).filter(item => !keyword || item.title.toLowerCase().includes(keyword)) }) },
|
|
|
|
|
searchCustomers(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ customerKeyword: keyword, customerOptions: this.data.allCustomerOptions.filter(item => !keyword || String(item.title).toLowerCase().includes(keyword) || String(item.subtitle).includes(keyword)) }) },
|
|
|
|
|
selectProduct(e) { const item = e.detail.item; this.setData({ 'form.productId': item.id, selectedProductTitle: item.title, 'form.manualProductTitle': '', 'form.amount': item.price == null ? this.data.form.amount : String(item.price), productSelectorVisible: false }) },
|
|
|
|
|
selectArtist(e) { const item = e.detail.item; this.setData({ 'form.artistId': item.id, selectedArtistName: item.title, artistSelectorVisible: false }) },
|
|
|
|
|
selectCustomer(e) { const item = e.detail.item; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.title, 'form.phone': item.subtitle, customerSelectorVisible: false }) },
|
|
|
|
|
useWalkIn() { this.setData({ 'form.customerUserId': '', 'form.customerName': '', 'form.phone': '', customerSelectorVisible: false }) },
|
|
|
|
|
onCustomerNameInput(e) { this.setData({ 'form.customerName': e.detail.value, 'form.customerUserId': '' }) },
|
|
|
|
|
onProductNameInput(e) { this.setData({ 'form.manualProductTitle': e.detail.value, 'form.productId': '', selectedProductTitle: '' }) },
|
|
|
|
|
onInput(e) { this.setData({ [`form.${e.currentTarget.dataset.field}`]: e.detail.value }) },
|
|
|
|
|
onDateChange(e) { this.setData({ 'form.serviceDate': e.detail.value }) },
|
|
|
|
|
onTimeChange(e) { this.setData({ 'form.serviceTime': e.detail.value }) },
|
|
|
|
|
onArtistChange(e) { const index = Number(e.detail.value); const item = this.data.artists[index] || {}; this.setData({ artistIndex: index, selectedArtistName: item.name || item.nickname || '', 'form.artistId': item.id }) },
|
|
|
|
|
selectStatus(e) { this.setData({ 'form.status': Number(e.currentTarget.dataset.status) }) },
|
|
|
|
|
async submit() {
|
|
|
|
|
const form = this.data.form
|
|
|
|
|
if (!form.serviceDate || (!form.productId && !form.manualProductTitle) || !form.amount || !form.artistId) { wx.showToast({ title: '请填写项目、金额、日期和员工', icon: 'none' }); return }
|
|
|
|
|
if (form.phone && !/^1[3-9]\d{9}$/.test(form.phone)) { wx.showToast({ title: '手机号格式不正确', icon: 'none' }); return }
|
|
|
|
|
this.setData({ submitting: true })
|
|
|
|
|
try { await planningApi.createBackfillOrder(form); wx.showToast({ title: '补单已保存', icon: 'success' }); const app = getApp(); app.globalData.planningNeedRefresh = true; setTimeout(() => wx.navigateBack(), 500) }
|
|
|
|
|
catch (error) { wx.showToast({ title: error.message || '保存失败', icon: 'none' }) }
|
|
|
|
|
finally { this.setData({ submitting: false }) }
|
|
|
|
|
}
|
|
|
|
|
})
|