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: '预约已提交' });
|
||||
|
||||
Reference in new issue
Block a user