invoiceInformation.js 6.8 KB
// pages/my/invoiceInformation/invoiceInformation.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
         invioce:1, 
         flag:1,
         info:{},
         order_sn:0,
         user:'', 
         mobile:0,
         address:'',
         email:'',
         type:1,
        title_type:1,
        title:'',
        identify_number:''
  },
fetchInvoiceNotice() {
        let url = '/wxapp/user/invoiceOrder'
        app.post(url).then(r => {
                if (r.code == 1) { 
                        console.log(r)
                        this.setData({
                                info:r.data,
                                order_sn:r.data.order_sn,
                                user:r.data.sh_name,
                                mobile:r.data.sh_mobile,
                                address:r.data.sh_address,
                        })
                }
        })
},
//监测发票抬头
fromTitle(e){
        this.setData({
                title:e.detail.value
        })
},
//监测识别号
fromIdenfity(e){
        this.setData({
                identify_number:e.detail.value
        })
},
//监测收件人
fromUser(e){
        this.setData({
                user:e.detail.value
        })
},
//监测手机号
fromMobile(e) {
        this.setData({
                mobile: e.detail.value
        })
},
//监测地址
fromAddress(e) {
        this.setData({
                address: e.detail.value
        })
},
//监测电子邮件
fromEmail(e) {
        this.setData({
                email: e.detail.value
        })
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
          this.fetchInvoiceNotice();
  },
  // 返回上一页
  get_back(){
    wx.navigateBack({})
  },
  // 提交
  get_sumbit(){
          let that=this
          let url ='/wxapp/user/invoicePost'
          let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
          if (!myreg.test(that.data.mobile)) {
                  wx.showToast({
                          title: '请输入合法的手机号',
                          icon:'none'
                  })
                  return false;
          } 
          if(!that.data.title){
                  wx.showToast({
                          title: '请输入发票抬头',
                          icon:'none'
                  })
                  return
          }
          if (!that.data.identify_number) {
                  wx.showToast({
                          title: '请输入识别号',
                          icon: 'none'
                  })
                  return
          }
          if (!that.data.user) {
                  wx.showToast({
                          title: '请输入收件人',
                          icon: 'none'
                  })
                  return
          }
          if (!that.data.mobile) {
                  wx.showToast({
                          title: '请输入手机号',
                          icon: 'none'
                  })
                  return
          }
          if (!that.data.address) {
                  wx.showToast({
                          title: '请输入地址',
                          icon: 'none'
                  })
                  return
          }
          if(that.data.flag==1){
                  if(that.data.email==''){
                          wx.showToast({
                                  title: '请输入邮箱号',
                                  icon:'none'
                          })
                          return;
                  }
          }
          let re = /^[a-z0-9_][a-z0-9_\-]*@[a-z0-9]+\.[a-z]{2,3}$/i
          if (!re.test(that.data.email)&&that.data.flag==1) {
                  wx.showToast({
                          title: '请输入正确的邮箱',
                          icon: 'none'
                  })
                  return;
          } 
          let params={}
          if(that.data.flag==1){
                 params = {
                          order_sn: that.data.order_sn,
                          type: that.data.flag,
                          title_type: that.data.invioce,
                          title: that.data.title,
                          identify_number: that.data.identify_number,
                          sh_name: that.data.user,
                          sh_mobile: that.data.mobile,
                          address: that.data.address,
                          email: that.data.email
                  }
          }else{
                  params = {
                          order_sn: that.data.order_sn,
                          type: that.data.flag,
                          title_type: that.data.invioce,
                          title: that.data.title,
                          identify_number: that.data.identify_number,
                          sh_name: that.data.user,
                          sh_mobile: that.data.mobile,
                          address: that.data.address,
                  }
          }
          
          app.post(url,params).then(r=>{
                  if(r.code==1){
                         wx.showToast({
                                 title: '提交成功',
                                 icon:'none',
                                 duration: 1000
                         })
                         wx.switchTab({
                                 url: '../my'
                         })
                  }else{
                          wx.showToast({
                                  title: r.msg,
                                  icon:'none'
                          })
                  }
          })
  },
  //切换栏目
    //切换电子发票
        changeFlag1(){
                this.setData({
                        flag:1
                });
        },
//切换纸质发票
changeFlag2(){
        this.setData({
                flag: 2
        });
},
  //选择公司或个人
    //修改成公司
        changeInvioce1(){
                this.setData({
                        invioce:1
                });
        },
        //修改成个人
        changeInvioce2() {
                this.setData({
                        invioce:2
                });
        },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})