纸通宝SAAS仓库
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.
 

165 lines
5.0 KiB

// pages/home/customer-info/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { getCustomerInfo, getBankList, editCustomer, saveCustomer, deleteCustomer} 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: '现金支付' }
],
columns: [],
typeList: [
{ id: 1, text: '普通现结' },
{ id: 2, text: '押金+现结' },
{ id: 3, text: '押金+预付款' },
{ id: 4, text: '押金+月结' },
{ id: 5, text: '预付款' },
{ id: 6, text: '月结' }
],
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
}
if(util.isEmpty(result.data.customerSettleType) || Number(result.data.customerSettleType) < 1){
result.data.customerSettleType = 1
}
result.data.customerSettleName = this.data.typeList[result.data.customerSettleType - 1].text
this.setData({ form: result.data })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
getBankList().then(result => {
this.data.bankList = []
for (let index = 0; index < result.data.length; index++) {
this.data.bankList.push(result.data[index].bank)
}
})
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, columns: this.data.bankList })
} else if(e.currentTarget.id == 'settleType'){
this.setData({ visible: true, columns: this.data.typeList })
} 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/home/registe/index?id=${this.data.form.id}` })
},
onHide: function() {
this.setData({ visible: false })
},
onConfirm: function({detail}) {
if(typeof detail.value === 'string'){
this.setData({ visible: false, ['form.bankName']: detail.value })
} else {
this.data.form.customerSettleType = detail.value.id
this.setData({ visible: false, ['form.customerSettleName']: detail.value.text })
}
},
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: 101, 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 })
}
}
}
})
},
deleteForm: function(){
Dialog.confirm({ title: '温馨提示', message: '确定删除该客户?' }).then(() => {
wx.showLoading({ title: '正在处理', mask: true })
deleteCustomer(this.data.form.id).then(result => {
wx.hideLoading()
util.showBackToast('客户已删除')
event.emit('EventMessage', { what: 101 })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}).catch(err => {
})
}
})