// pages/home/customer-info/index.js import { getCustomerInfo, editCustomer } from "../../../api/saas" const util = require('../../../utils/util') const event = require('../../../utils/event') Page({ /** * 页面的初始数据 */ data: { form: null, show: false, actions: [ { id: 2, name: '转账' }, { id: 1, name: '现金' } ], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ wx.showLoading({ title: '正在获取', mask: true }) getCustomerInfo(options.id).then(result => { wx.hideLoading() this.setData({ form: result.data }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } }, bindInput: function(e){ this.data.form[e.currentTarget.id] = e.detail }, chooseMethod: function(){ this.setData({ show: true }) }, onClose: function() { this.setData({ show: false }) }, onSelect: function({detail}) { this.setData({ ['form.defaultPaymentMethod']: detail.id }) }, registCustomer: function(){ wx.navigateTo({ url: `/pages/client/registe/index?id=${this.data.form.id}` }) }, submitForm: function(){ if (util.isEmpty(this.data.form.name)) { util.showToast('请输入客户姓名') return } if (util.isEmpty(this.data.form.defaultPaymentMethod)) { this.data.form.defaultPaymentMethod = 1 } wx.showLoading({ title: '正在获取', mask: true }) editCustomer(this.data.form).then(result => { wx.hideLoading() util.showBackToast('修改成功') event.emit('EventMessage', { what: 102, detail: this.data.form }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } })