123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // pages/buyerAdd/buyerAdd.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: 0, //0是新增,1是编辑
- list: [{
- selected: true,
- customerType: 2,
- text: '企业'
- }, {
- selected: false,
- customerType: 1,
- text: '个人及政府事业单位'
- }],
- currentIndex: 0,
- customerName: '',
- entTaxId: '',
- customerMobile: '',
- email: '',
- address: '',
- contactPhone: '',
- bankName: '',
- bankAccountNumber:""
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- type: Number(options.type)
- })
- if (this.data.type === 1) {
- this.getDetail()
- wx.setNavigationBarTitle({
- title: '编辑购方'
- })
- }
- },
- //如果是编辑操作,就获取回显信息
- getDetail() {
- let detail = wx.getStorageSync('configBuyer')
- this.setData({
- customerName: detail.customerName,
- entTaxId: detail.customerEntTaxId,
- address: detail.address,
- contactPhone: detail.contactPhone,
- bankName: detail.bankName,
- bankAccountNumber: detail.bankAccountNumber,
- customerMobile: detail.customerMobile,
- email: detail.email,
- customerId: detail.customerId
- })
- },
- //提交
- submitData() {
- let params = {
- mobile: utils.getInfo().mobile,
- entTaxId: wx.getStorageSync('entTaxId'),
- reqChannel: 5,
- customerType: this.data.list[this.data.currentIndex].customerType,
- customerName: utils.trimAll(this.data.customerName),
- customerMobile: utils.trimAll(this.data.customerMobile),
- email: utils.trimAll(this.data.email)
- }
- if (this.data.type === 1) {
- params.customerId = this.data.customerId
- }
- if (params.customerName === '') {
- utils.toast('购方名称不能为空')
- return
- }
- if (this.data.currentIndex === 0) {
- if (utils.trimAll(this.data.entTaxId) === '') {
- utils.toast('税号不能为空')
- return
- } else {
- params.customerEntTaxId = utils.trimAll(this.data.entTaxId)
- }
- if (utils.trimAll(this.data.address) !== '') {
- params.address = utils.trimAll(this.data.address)
- }
- if (utils.trimAll(this.data.contactPhone) !== '') {
- params.contactPhone = utils.trimAll(this.data.contactPhone)
- }
- if (utils.trimAll(this.data.bankName) !== '') {
- params.bankName = utils.trimAll(this.data.bankName)
- }
- if (utils.trimAll(this.data.bankAccountNumber) !== '') {
- params.bankAccountNumber = utils.trimAll(this.data.bankAccountNumber)
- }
- }
- /* if (params.customerMobile === '') {
- utils.toast('您的个人手机号不能为空')
- return
- }
- if (params.email === '') {
- utils.toast('您的个人邮箱不能为空')
- return
- } */
- if (params.customerMobile !== '') {
- if (!utils.testMobile(params.customerMobile)) {
- utils.toast('请填写正确的手机号')
- return
- }
- }
- if (params.email !== '') {
- if (!utils.testEmail(params.email)) {
- utils.toast('请填写正确的邮箱')
- return
- }
- }
- utils.axios({
- method: 'post',
- url: '/sys/customer/saveOrUpdate',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '购方保存中...',
- mask: true
- })
- },
- complete() {
- wx.hideLoading()
- },
- success: res => {
- utils.funPrev(prev => {
- prev.toFresh()
- utils.toast('购方保存成功')
- wx.navigateBack()
- })
- }
- })
- },
- //选择
- choose(e) {
- let index = Number(e.currentTarget.dataset.index)
- let list = this.data.list
- for (let i = 0; i < list.length; i++) {
- list[i].selected = false
- }
- list[index].selected = true
- this.setData({
- list,
- currentIndex: index
- })
- },
- //购方名
- getcustomerName(e) {
- let value = e.detail.value
- this.setData({
- customerName: value
- })
- },
- getentTaxId(e) {
- let value = e.detail.value
- this.setData({
- entTaxId: value
- })
- },
- getcustomerMobile(e) {
- let value = e.detail.value
- this.setData({
- customerMobile: value
- })
- },
- getemail(e) {
- let value = e.detail.value
- this.setData({
- email: value
- })
- },
- getaddress(e) {
- let value = e.detail.value
- this.setData({
- address: value
- })
- },
- getcontactPhone(e) {
- let value = e.detail.value
- this.setData({
- contactPhone: value
- })
- },
- getbankName(e) {
- let value = e.detail.value
- this.setData({
- bankName: value
- })
- },
- getbankAccountNumber(e) {
- let value = e.detail.value
- this.setData({
- bankAccountNumber: value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|