// pages/invoice/pages/detail/detail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    invoiceId: '',
    InvoiceInfo: {},
    email: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      invoiceId: options.invoiceId
    })
    this.getInvoiceInfoById();
  },
  setEmail(e) {
    const {
      value
    } = e.target.dataset;
    this.setData({
      email: value || e.detail.value,
    })
  },
  submit() {
    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;
    }
    wx.navigateTo({
      url: '/pages/invoice/pages/send/send?email='+this.data.email+'&imgUrl='+this.data.imgUrl+"&invoiceId="+this.data.invoiceId
    })
  },
  // /invoice/getInvoiceInfoById
  getInvoiceInfoById() {
    app.showLoading();
    app.$http.get('/invoice/getInvoiceInfoById', {
      invoiceId: this.data.invoiceId
    }).then(({ status, data = {} }) => {
      if (status == 0) {
        data.totalPrintAmount = app.$util.numberFormat(data.totalPrintAmount, 2);
        this.setData({
          InvoiceInfo: data,
          email: data.email,
          imgUrl: data.imgUrl.split(',')[0]
        })
      }
      app.hideLoading();
    }).catch(() => {
      app.hideLoading();
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})