补充历史补单小程序页面

This commit is contained in:
2026-10-13 12:40:21 +08:00
parent bd8d95fcd9
commit 5145dc44c6
4 changed files with 73 additions and 0 deletions
@@ -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 }) }
}
})
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "补录历史订单",
"usingComponents": { "entity-selector-sheet": "/components/entity-selector-sheet/index" }
}
@@ -0,0 +1,19 @@
<view class="page no-tab">
<view class="card form-card">
<view class="page-hint">历史补单不校验员工排班,也不会占用预约时段。</view>
<view class="field"><text class="field-label required">服务日期</text><picker mode="date" value="{{form.serviceDate}}" bindchange="onDateChange"><view class="field-value">{{form.serviceDate}}</view></picker></view>
<view class="field"><text class="field-label required">项目</text><view class="field-value" bindtap="openProductSelector">{{selectedProductTitle || form.manualProductTitle || '选择已有项目或手动填写'}}</view><input value="{{form.manualProductTitle}}" bindinput="onProductNameInput" placeholder="手动录入项目名称(选填)" /></view>
<view class="field"><text class="field-label required">金额</text><input type="digit" value="{{form.amount}}" data-field="amount" bindinput="onInput" placeholder="请输入实际金额" /></view>
<view class="field"><text class="field-label required">员工</text><view class="field-value" bindtap="openArtistSelector">{{selectedArtistName || '请选择员工'}}</view></view>
<view class="field"><text class="field-label">客户</text><view class="field-value" bindtap="openCustomerSelector">{{form.customerName || '请选择客户(可选)'}}</view><input value="{{form.customerName}}" data-field="customerName" bindinput="onCustomerNameInput" placeholder="或填写散客姓名" /></view>
<view class="field"><text class="field-label">手机号</text><input type="number" maxlength="11" value="{{form.phone}}" data-field="phone" bindinput="onInput" placeholder="选填" /></view>
<view class="field"><text class="field-label">服务时间</text><picker mode="time" value="{{form.serviceTime}}" bindchange="onTimeChange"><view class="field-value">{{form.serviceTime || '时间未记录'}}</view></picker></view>
<view class="field"><text class="field-label">状态</text><view class="status-segment"><view class="status-option {{form.status == 4 ? 'active' : ''}}" data-status="4" bindtap="selectStatus">服务中</view><view class="status-option {{form.status == 2 ? 'active' : ''}}" data-status="2" bindtap="selectStatus">已完成</view></view></view>
<view class="field textarea-field"><text class="field-label">备注</text><textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="补单备注(选填)" /></view>
</view>
<view class="card submit-tip">提交后订单会直接进入所选状态,不创建预约占用。</view>
<button class="primary-btn" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">保存历史补单</button>
<entity-selector-sheet visible="{{productSelectorVisible}}" title="选择项目" keyword="{{productKeyword}}" placeholder="搜索项目名称" items="{{productOptions}}" selected-id="{{form.productId}}" loading="{{loadingProducts}}" error-text="{{productError}}" empty-text="暂无项目,可直接手动录入" bind:search="searchProducts" bind:select="selectProduct" bind:retry="loadProducts" bind:close="closeProductSelector" />
<entity-selector-sheet visible="{{artistSelectorVisible}}" title="选择员工" keyword="{{artistKeyword}}" placeholder="搜索员工姓名" items="{{artistOptions}}" selected-id="{{form.artistId}}" loading="{{loadingArtists}}" error-text="{{artistError}}" empty-text="暂无可选员工" bind:search="searchArtists" bind:select="selectArtist" bind:retry="loadArtists" bind:close="closeArtistSelector" />
<entity-selector-sheet visible="{{customerSelectorVisible}}" title="选择客户" keyword="{{customerKeyword}}" placeholder="搜索客户姓名或手机号" items="{{customerOptions}}" selected-id="{{form.customerUserId}}" loading="{{loadingCustomers}}" error-text="{{customerError}}" empty-text="暂无客户,可留空记为散客" action-text="按散客记录" bind:search="searchCustomers" bind:select="selectCustomer" bind:retry="loadCustomers" bind:action="useWalkIn" bind:close="closeCustomerSelector" />
</view>
@@ -0,0 +1 @@
.page{padding:24rpx;background:#f7f5f1;min-height:100vh;box-sizing:border-box}.form-card{padding:28rpx}.page-hint,.submit-tip{font-size:26rpx;color:#8b8177;line-height:1.6}.field{padding:24rpx 0;border-bottom:1rpx solid #eee7df}.field-label{display:block;color:#4d463f;font-size:28rpx;margin-bottom:14rpx}.required:after{content:' *';color:#c9795d}.field-value,input,textarea{font-size:30rpx;color:#2d2925}.field-value{min-height:42rpx;color:#6f665d}.status-segment{display:flex;gap:16rpx}.status-option{flex:1;text-align:center;padding:18rpx;border:1rpx solid #ddd4ca;border-radius:12rpx;color:#756b61}.status-option.active{background:#4f766d;color:#fff;border-color:#4f766d}.submit-tip{margin:22rpx 0;padding:22rpx}.primary-btn{margin-top:28rpx;background:#4f766d;color:#fff;border-radius:14rpx}