// pages/home/customer-info/index.js import Scene from '../../index/scene' import { getRoleList, editCustomer, saveCustomer} from "../../../api/saas" const util = require('../../../utils/util') const event = require('../../../utils/event') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { form: {}, visible: false, roleList: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ let channel = this.getOpenerEventChannel() let that = this channel.on('onParam', function (data) { that.setData({ form: data }) }) } getRoleList().then(result => { this.setData({ roleList: result.data.records }) }) }, bindInput: function(e){ this.data.form[e.currentTarget.id] = e.detail }, chooseMethod: function(e){ if(e.currentTarget.id == 'bankName'){ this.setData({ visible: true }) } else { this.setData({ show: true }) } }, registCustomer: function(){ wx.navigateTo({ url: `/pages/client/registe/index?id=${this.data.form.id}` }) }, onHide: function() { this.setData({ visible: false }) }, onConfirm: function({detail}) { this.setData({ visible: false, ['form.bankName']: detail.value }) }, submitForm: function(){ if (util.isEmpty(this.data.form.name)) { util.showToast('请输入客户姓名') return } if (util.isEmpty(this.data.form.defaultPaymentMethod)) { util.showToast('请选择客户的付款方式') return } if (util.isEmpty(this.data.form.defaultPaymentMethod)) { this.data.form.defaultPaymentMethod = 1 } wx.showLoading({ title: '正在获取', mask: true }) if(this.data.form.id) { 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) }) } else { saveCustomer(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) }) } } })