refactor: 按行业模板驱动需求表单

This commit is contained in:
que01 committed 2026-09-19 12:32:16 +08:00
1 parent 5b831b6740
commit 0228112846
3 files changed
+11 -10

No files matched your search

+5 -4
View File
@@ -1,7 +1,8 @@
const { request, customerRequest } = require('../../utils/request');
const { getTemplate } = require('../../utils/templates');
Page({
data: { service: {}, form: {}, serviceId: '', quantity: 1, fulfillment: 'pickup', submitting: false },
onLoad(query) { request('/public/services').then((services) => { const list = Array.isArray(services) ? services : []; const service = list.find((item) => item.id === query.serviceId) || list.find((item) => item.priceAmount !== null) || {}; this.setData({ service, serviceId: service.id || '' }); }).catch(() => wx.showToast({ title: '服务加载失败', icon: 'none' })); },
data: { service: {}, form: {}, serviceId: '', quantity: 1, fulfillment: 'pickup', submitting: false, template: getTemplate('personal') },
onLoad(query) { Promise.all([request('/public/services'), request('/public/brand')]).then(([services, brand]) => { const list = Array.isArray(services) ? services : []; const service = list.find((item) => item.id === query.serviceId) || list.find((item) => item.priceAmount !== null) || {}; this.setData({ service, serviceId: service.id || '', template: getTemplate(brand.templateKey) }); }).catch(() => wx.showToast({ title: '服务加载失败', icon: 'none' })); },
input(event) { this.setData({ ['form.' + event.currentTarget.dataset.key]: event.detail.value }); },
chooseFulfillment(event) { this.setData({ fulfillment: event.currentTarget.dataset.value }); },
increase() { if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 }); },
@@ -10,11 +11,11 @@ Page({
const form = this.data.form;
if (!this.data.serviceId) return wx.showToast({ title: '请先选择服务', icon: 'none' });
if (!form.customerName || !form.wechatId) return wx.showToast({ title: '请填写称呼和联系方式', icon: 'none' });
if (this.data.fulfillment === 'delivery' && !form.deliveryAddress) return wx.showToast({ title: '请填写配送地址', icon: 'none' });
if (this.data.fulfillment === 'delivery' && !form.deliveryAddress) return wx.showToast({ title: '请填写' + this.data.template.locationLabel, icon: 'none' });
this.setData({ submitting: true });
const send = () => customerRequest('/customer/bookings', {
method: 'POST',
data: { requestType: 'package', customerName: form.customerName, wechatId: form.wechatId, contactPreference: 'wechat', fulfillmentType: this.data.fulfillment, deliveryAddress: form.deliveryAddress, requestedTime: form.requestedTime, note: form.note, items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }] },
data: { requestType: this.data.template.requestType, customerName: form.customerName, wechatId: form.wechatId, contactPreference: 'wechat', fulfillmentType: this.data.fulfillment, deliveryAddress: form.deliveryAddress, requestedTime: form.requestedTime, note: form.note, items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }] },
}).then(() => {
this.setData({ submitting: false });
wx.showToast({ title: '预约已提交' });
+4 -4
View File
@@ -1,7 +1,7 @@
<view class="page">
<view class="product"><view class="product-image"><image wx:if="{{service.coverUrl}}" src="{{service.coverUrl}}" mode="aspectFill"/><view wx:else class="dish-placeholder"></view></view><view class="product-copy"><text class="name">{{service.name || '选择预约服务'}}</text><text class="price">{{service.priceText || '人工沟通报价'}}</text></view><text class="available">今日可订</text></view>
<view class="product"><view class="product-image"><image wx:if="{{service.coverUrl}}" src="{{service.coverUrl}}" mode="aspectFill"/><view wx:else class="dish-placeholder"></view></view><view class="product-copy"><text class="name">{{service.name || '选择服务'}}</text><text class="price">{{service.priceText || '沟通报价'}}</text></view><text class="available">{{template.available}}</text></view>
<view class="quantity"><text>数量</text><view class="stepper"><button bindtap="decrease">−</button><text>{{quantity}} 份</text><button bindtap="increase">+</button></view></view>
<view class="fulfillment"><text class="field-title">合作方式</text><view class="choices"><button class="choice {{fulfillment === 'pickup' ? 'active' : ''}}" data-value="pickup" bindtap="chooseFulfillment">线上沟通</button><button class="choice {{fulfillment === 'delivery' ? 'active' : ''}}" data-value="delivery" bindtap="chooseFulfillment">线下沟通</button></view></view>
<view class="form"><label>怎么称呼<input name="customerName" placeholder="请输入你的称呼" bindinput="input" data-key="customerName"/></label><label>联系方式<input name="wechatId" placeholder="手机号或微信号" bindinput="input" data-key="wechatId"/></label><label>期望时间<input name="requestedTime" placeholder="例如:下周三 14:00" bindinput="input" data-key="requestedTime"/></label><label wx:if="{{fulfillment === 'delivery'}}">见面地点<input name="deliveryAddress" placeholder="请输入地点或线上会议方式" bindinput="input" data-key="deliveryAddress"/></label><label>需求说明<textarea placeholder="请介绍你的需求、预算或期待结果" bindinput="input" data-key="note"></textarea></label></view>
<view class="notice">● 提交后品牌方会与你确认需求、时间和合作方式。</view><button class="submit" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">{{submitting ? '提交中...' : '提交需求'}}</button>
<view class="fulfillment"><text class="field-title">{{template.modeLabel}}</text><view class="choices"><button class="choice {{fulfillment === 'pickup' ? 'active' : ''}}" data-value="pickup" bindtap="chooseFulfillment">{{template.modeA}}</button><button class="choice {{fulfillment === 'delivery' ? 'active' : ''}}" data-value="delivery" bindtap="chooseFulfillment">{{template.modeB}}</button></view></view>
<view class="form"><label>怎么称呼<input name="customerName" placeholder="请输入你的称呼" bindinput="input" data-key="customerName"/></label><label>联系方式<input name="wechatId" placeholder="手机号或微信号" bindinput="input" data-key="wechatId"/></label><label>期望时间<input name="requestedTime" placeholder="例如:下周三 14:00" bindinput="input" data-key="requestedTime"/></label><label wx:if="{{fulfillment === 'delivery'}}">{{template.locationLabel}}<input name="deliveryAddress" placeholder="{{template.locationPlaceholder}}" bindinput="input" data-key="deliveryAddress"/></label><label>{{template.requestType === 'package' ? '备注' : '需求说明'}}<textarea placeholder="{{template.notePlaceholder}}" bindinput="input" data-key="note"></textarea></label></view>
<view class="notice">● {{template.submitNotice}}</view><button class="submit" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">{{submitting ? '提交中...' : template.submitLabel}}</button>
</view>
+2 -2
View File
@@ -1,6 +1,6 @@
const TEMPLATES = {
food: { hero: '今天吃什么', heroSub: '现做家常饭', about: '品牌简介', description: '个人经营的家常小灶,套餐现做,也可预约小型聚餐和私厨定制。', primary: '预约套餐', secondary: '咨询私厨', timeLabel: '营业时间', time: '11:00—20:00', addressLabel: '摊位地址', address: '校园路社区便民点 12 号', noteLabel: '配送说明', note: '满 30 元周边配送,也可自取', serviceSub: '今日可订', first: '普通套餐', firstSub: '日常家常饭', second: '私厨服务', secondSub: '聚餐定制', available: '今日可订', unavailable: '暂不可订', empty: '暂无可订服务' },
personal: { hero: '个人品牌', heroSub: '把专业能力,变成值得信赖的体验', about: '关于我', description: '这里展示你的专业背景、工作方式与品牌理念。', primary: '查看服务', secondary: '发起咨询', timeLabel: '服务时间', time: '工作日 10:00—18:00', addressLabel: '所在位置', address: '线上 / 线下均可沟通', noteLabel: '合作说明', note: '提交需求后,我会尽快与你联系', serviceSub: '可咨询', first: '标准服务', firstSub: '清晰的服务方案', second: '定制合作', secondSub: '按需求沟通', available: '可咨询', unavailable: '暂不可用', empty: '暂无可咨询服务' },
food: { hero: '今天吃什么', heroSub: '现做家常饭', about: '品牌简介', description: '个人经营的家常小灶,套餐现做,也可预约小型聚餐和私厨定制。', primary: '预约套餐', secondary: '咨询私厨', timeLabel: '营业时间', time: '11:00—20:00', addressLabel: '摊位地址', address: '校园路社区便民点 12 号', noteLabel: '配送说明', note: '满 30 元周边配送,也可自取', serviceSub: '今日可订', first: '普通套餐', firstSub: '日常家常饭', second: '私厨服务', secondSub: '聚餐定制', available: '今日可订', unavailable: '暂不可订', empty: '暂无可订服务', bookingTitle: '预约套餐', requestType: 'package', modeLabel: '取餐方式', modeA: '自取', modeB: '配送', locationLabel: '配送地址', locationPlaceholder: '请输入配送地址', notePlaceholder: '口味、餐具或其他说明', submitNotice: '提交后由摊主人工确认,确认后再安排制作。', submitLabel: '提交预约' },
personal: { hero: '个人品牌', heroSub: '把专业能力,变成值得信赖的体验', about: '关于我', description: '这里展示你的专业背景、工作方式与品牌理念。', primary: '查看服务', secondary: '发起咨询', timeLabel: '服务时间', time: '工作日 10:00—18:00', addressLabel: '所在位置', address: '线上 / 线下均可沟通', noteLabel: '合作说明', note: '提交需求后,我会尽快与你联系', serviceSub: '可咨询', first: '标准服务', firstSub: '清晰的服务方案', second: '定制合作', secondSub: '按需求沟通', available: '可咨询', unavailable: '暂不可用', empty: '暂无可咨询服务', bookingTitle: '合作咨询', requestType: 'package', modeLabel: '沟通方式', modeA: '线上沟通', modeB: '线下沟通', locationLabel: '沟通方式或地点', locationPlaceholder: '请输入会议方式、地点或链接', notePlaceholder: '请介绍你的需求、预算或期待结果', submitNotice: '提交后品牌方会与你确认需求、时间和合作方式。', submitLabel: '提交需求' },
};
function getTemplate(key) { return TEMPLATES[key] || TEMPLATES.personal; }
module.exports = { getTemplate, TEMPLATES };