refactor: 按行业模板驱动需求表单
This commit is contained in:
1 parent
5b831b6740
commit
0228112846
3 files changed
+11
-10
No files matched your search
@@ -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: '预约已提交' });
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user