You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.6 KiB
131 lines
3.6 KiB
// pages/home/customer-info/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getCustomerInfo, getBankList, editCustomer, saveCustomer} from "../../../api/saas"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
cardNo: null,
|
|
form: {
|
|
cardNo: ''
|
|
},
|
|
show: false,
|
|
actions: [
|
|
{ id: 2, name: '银行卡转账' },
|
|
{ id: 1, name: '现金支付' }
|
|
],
|
|
visible: false,
|
|
bankList: null
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(!util.isEmpty(options.id)){
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
getCustomerInfo(options.id).then(result => {
|
|
wx.hideLoading()
|
|
if(!util.isEmpty(options.userId)){
|
|
result.data.userId = options.userId
|
|
}
|
|
this.setData({ form: result.data })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
getBankList().then(result => {
|
|
var bankList = []
|
|
for (let index = 0; index < result.data.length; index++) {
|
|
bankList.push(result.data[index].bank)
|
|
}
|
|
this.setData({ bankList })
|
|
})
|
|
if(options.cardNo){
|
|
this.data.form.factoryId = app.userInfo.factoryId
|
|
this.setData({ cardNo: options.cardNo, ['form.cardNo']: options.cardNo })
|
|
}
|
|
},
|
|
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 })
|
|
}
|
|
},
|
|
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}` })
|
|
},
|
|
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)
|
|
})
|
|
}
|
|
},
|
|
chooseMember: function(){
|
|
if(!this.data.cardNo){
|
|
return
|
|
}
|
|
var that = this
|
|
wx.navigateTo({
|
|
url: `/pages/home/customer-list/index?type=1`,
|
|
events: {
|
|
onCallback: (data) => {
|
|
if (data.what == 130) {
|
|
if(!util.isEmpty(that.data.cardNo)){
|
|
data.detail.cardNo = that.data.cardNo
|
|
}
|
|
that.setData({ form: data.detail })
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|