// pages/Pay/Pay.js
let app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:0,
    tagID:-1,
    Commoditydetails:{},
    code:{},
    PayOrder:"",
    payway:'',
    codeInfo:{},
    codeshow:false,
    url: 'OnlinePay_post_GetCodeUrlForAirB2B'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options", options)
    // 团
    if (options.tagID !== "4" && options.tagID !== "-1") {
      let userinfo = wx.getStorageSync('admin')
      let info = wx.getStorageSync('payInfoMsg');
      console.log(info)
      this.data.Commoditydetails = info;
      this.data.Commoditydetails.airOrderId = info.orderId;
      this.data.code.OrderSource = 8;
      this.data.code.total_fee = info.preferPrice + '';
      this.data.code.body = info.ltName + '-' + info.startDate;
      this.data.code.attach = `${77}|${userinfo.customerName}|${info.orderId}|${userinfo.id}|${info.branchId}`;
      this.setData({
        Commoditydetails: this.data.Commoditydetails,
        code: this.data.code,
        url: "OnlinePay_post_GetCodeUrlForCommonB2B"
      })
    }
    // 机票
    if (options.tagID=="4"){ 
      this.setData({
        orderId: options.orderId,
        url: "OnlinePay_post_GetCodeUrlForCommonB2B"
      })
      this.getAirTicket(options.orderId)
    }
    if (options.tagID == "-1") {
      
      let Visainfo = wx.getStorageSync('payInfoMsg');
      this.data.Commoditydetails = Visainfo;
      this.data.Commoditydetails.airOrderId = Visainfo.airOrderId;
      this.data.code.OrderSource = Visainfo.orderResourceId;
      this.data.code.total_fee = Visainfo.preferPrice + '';
      this.data.code.body = Visainfo.description;
      this.data.code.attach = `${Visainfo.costType}|${Visainfo.customerName}|${Visainfo.AirOrderId}|${Visainfo.customerId}|${Visainfo.outBranchId}`;
      this.setData({
        Commoditydetails: this.data.Commoditydetails,
        code: this.data.code
      })
      console.log("Commoditydetails", this.data.Commoditydetails)
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  getAirTicket(){
    let that=this;
    app.$apiJavaNew('/api/dmc/airticket/GetB2BAirtickOrderPayInfo', { AirOrderId: this.data.orderId }).then(res => {
      that.data.Commoditydetails = res;
      that.data.code.OrderSource = that.data.Commoditydetails.orderResourceId;
      that.data.code.total_fee = that.data.Commoditydetails.preferPrice + '';
      that.data.code.body = that.data.Commoditydetails.description;
      that.data.code.attach = `${that.data.Commoditydetails.costType}|${that.data.Commoditydetails.customerName}|${this.data.orderId}|${that.data.Commoditydetails.customerId}|${that.data.Commoditydetails.outBranchId}`
      that.setData({
        code: that.data.code,
        Commoditydetails: that.data.Commoditydetails,
      })
      // that.Code('3');
    }).catch(err => { })
  },
  Code(e) {
    let str = e.currentTarget.dataset.num;
    this.data.payway = str ? this.data.payway = str : this.data.payway;
    this.data.code.payway = this.data.payway;
    app.$api(this.data.url, this.data.code).then(res => {
      let codeInfo = res;
      this.data.PayOrder = codeInfo.Pay_Order;
      
      this.setData({
        codeInfo: res,
        PayOrder: this.data.PayOrder,
        codeshow:true,
      })
      // console.log("codeInfo", this.data.codeInfo)
      // clearInterval(this.Pay_timer);
      // this.PayStatus();

      if (res.IsUpdateAirOrderPayStatus == 1) {

      }

    }).catch(err => { })
   
  },
  closeCode(e){
    let self = e.currentTarget.dataset.self;
    if(self="self"){
      this.setData({
        codeshow:false,
      })
    }
  },
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})