// pages/invoice/pages/tickets/tickets.js
const util = require('../../../../utils/util');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'开票提交',
    AccountInvoiceInfo:{},
    email:'',
    fee:'',
    payseriesno:'',
    loading: false,
    color: '#000',
    background: '#ffffff',
    show: true,
    animated: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      fee:options.fee,
      payseriesno:options.payseriesno
    })
    this.getAccountInvoiceInfo();
  },
  goBack(){
    wx.navigateBack({
      delta: 1
    })
  },
  setEmail(e){
    const {
      value
    } = e.target.dataset;
    this.setData({
      email: value || e.detail.value,
    })
  },
  // GET /invoice/getAccountInvoiceInfo
getAccountInvoiceInfo(){
  app.showLoading();
    app.$http.get('/invoice/getAccountInvoiceInfo').then(({status, data = {}}) => {
      if(status == 0) {
        this.setData({
          AccountInvoiceInfo: data,
          email:data.email || ''
        })
      }
      app.hideLoading();
    }).catch(() => {
      app.hideLoading();
    })
},
// GET /invoice/InvoicePrintRequest
PrintRequest(){
  app.$http.get('/invoice/InvoicePrintRequest',{
    email:this.data.email,
    payseriesno:this.data.payseriesno
  }).then(({status, data = {}}) => {
    if(status == 0) {
      wx.navigateTo({
        url: '/pages/invoice/pages/operation/operation?operate=tickets&status=1'
      })
    }else{
      wx.navigateTo({
        url: '/pages/invoice/pages/operation/operation?operate=tickets&status=0'
      })
    }
  }).catch(() => {
     wx.navigateTo({
        url: '/pages/invoice/pages/operation/operation?operate=tickets&status=0'
      })
  })
},
submit:util.throttle(function(){
  const {email} = this.data;
  if(!email) {
    wx.showToast({
      title: '请输入电子邮箱',
      icon:'none',
      duration: 2000
    })
    return;
  }
  if(!(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(email))) {
    wx.showToast({
      title: '您输入的格式有误，请重新输入',
      icon:'none',
      duration: 2000
    })
    return;
  }
  this.PrintRequest();
},3000),
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

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

  },

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

  },

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

  }
})