// packageH/superior_payment/superiorPaymentIndex/superiorPaymentIndex.js
var app = getApp();
let plugin_name="上级代付";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    share_desc:'',

    order_id: "",
    goodList: [],
    totalNum: 0,
    totalPrice: '',
    buttons: [],

    shareTit: '',
    shareImg: '',
  },

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

    this.getOrderDetail();
    this.getShareInfo();
  },

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

  },


  getOrderDetail() {
    var _url = app.getNetAddresss("order.another-pay-detail");
    _url += "&order_id=" + this.data.order_id;
    app._getNetWork({
      url: _url,
      success: (response) => {
        //var _data = res.data.data;
        if (response.data.result == 1) {
          this.formatGoods(response.data.data);
          wx.setNavigationBarTitle({
            title: response.data.plugin_name || plugin_name,
          });
        } else {
          app.tips(response.data.msg);
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },

  formatGoods(list){

    let numSum = 0;
    let price = '';
    let goods=[];
    list.forEach(val => {
      goods.push(...val.has_many_order_goods);
      price += val.price;
      return (numSum += val.goods_total);
    });
    this.setData({
      totalNum:numSum,
      totalPrice:price,
      goodList:goods
    });
  },

  //获取默认分享数据
  getShareInfo: function() {
    var _url = app.getNetAddresss("plugin.parent-payment.frontend.modules.payment.controllers.share.index");
    _url += "&order_ids=" + this.data.order_id;
    app._getNetWork({
      url: _url,
      success: (response)=> {
        //var _data = res.data.data;
        console.log("ressss::::", response);
        if (response.data.result == 1) {
          this.setData({
            shareTit: response.data.data.title,
            shareImg: response.data.data.image
          });
        } else {
          app.tips(response.data.msg);
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var value = wx.getStorageSync('yz_uid');
    var path = '';
    if (value) {
      path = value;
    }
    console.log('/packageH/superior_payment/superiorPaymentPay/superiorPaymentPay?order_id=' + this.data.order_id + '&mid=' + path +
			'&pid=' + path);
    return {
      title: this.data.shareTit,
      imageUrl: this.data.shareImg,
      path: '/packageH/superior_payment/superiorPaymentPay/superiorPaymentPay?order_id=' + this.data.order_id + '&mid=' + path + '&pid=' +path
    };
  }
});