// pages/ticketRed/detail.js
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    result: '', //详情数据
    remark: '', //备注
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDetail()
  },

  //详情
  getDetail() {
    let result = wx.getStorageSync('ticketRedData')
    let remark = ''
    if (result.remark) {
      remark = result.remark
    }
    this.setData({
      result,
      remark
    })
  },

  //提交请求
  submitData() {
    let params = {
      mobile: utils.getInfo().mobile,
      reqChannel: 5,
      oriInvoiceReqFlowNo: this.data.result.invoiceReqFlowNo
    }
    let remark = utils.trimAll(this.data.remark)
    if (remark !== '') {
      params.remark = remark
    }
    utils.axios({
      method: 'post',
      url: '/sys/hongchongInfo/save',
      data: params,
      sendBefore() {
        wx.showLoading({
          title: '快速红冲中...',
          mask: true
        })
      },
      complete() {
        wx.hideLoading()
      },
      success: res => {
        utils.funPrev(prev => {
          prev.toFresh()
        })
        wx.redirectTo({
          url: '/pages/ticketRed/success'
        })
      }
    })
  },

  //商品详情
  toDetail() {
    let invoiceReqFlowNo = this.data.result.invoiceReqFlowNo
    wx.navigateTo({
      url: '/pages/ticketProdetail/ticketProdetail?invoiceReqFlowNo=' + invoiceReqFlowNo
    })
  },

  //获取备注
  getRemark(e) {
    this.setData({
      remark: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '诺信云',
      path: '/pages/index/index'
    }
  }
})