const WxParse = require('../../wxParse/wxParse.js') const $ = global new $.Page({ data: { options: [], api: '' }, onLoad(options) { if (!options.id) { return $.wx.showToast({ title: '找不到对应id' }); } $.request(`classify/${options.id}`, 'GET', {}).then((res) => { var article = res.data && res.data.content || ''; const fields = res.data.fields || []; const options = []; WxParse.wxParse('article', 'html', article, this, 5); for (let item of fields) { const group = item.input_group; options.push({ value: group[0].value || '', key: item.name }); } this.setData({ banner: res.data.photo || '', fields, options, api: res.data.api }); }); }, bookServer() { const { name, phone, address, notes, expectedDate, serviceDate, options } = this.data; if (!name || !phone || !address || !expectedDate || !serviceDate) { return $.wx.showToast({ title: '请把信息填写完整' }); } if (!this._isPhone(phone)) { return $.wx.showToast({ title: '请输入正确的手机号码' }); } $.wx.showToast({ title: '加载中' }, 'loading'); const data = { expected_date: expectedDate, special_demand: notes, server_time: serviceDate, address, contact: name, phone }; for (let option of options) { data[`${option.key}`] = option.value; } $.request(this.data.api, 'POST', data).then((res) => { $.wx.hideToast('loading'); $.router.goto({ path: '/pages/order/index', type: $.ROUTER_TYPE.SWITCH_TAB }); }); }, radioChange(e) { const { index } = e.currentTarget.dataset || 0; const { value } = e.detail; const { options } = this.data; options[index].value = value; this.setData({ options }); } })