var yz_pay = require('../../../mycomponent/yz_pay/yz_pay');
var app = getApp();
Page({
  behaviors: [yz_pay],
  data: {
    language: '',
    order_id: "",
    goodList: [],
    totalNum: 0,
    totalPrice: '',
    order_sn: '',
    orderData: null,

    balance: 0,
    payParams: '',
    info_form: {},
    money: '',
    buttons: [],
    pay_sn: '订单编号',
    order_pay_id: '',
    mid: '',
    payerImg: '',
    payerName: '',
    pid: '',
  },

  confirm(e) {
    let type = e.currentTarget.dataset.value;
    let btn = e.currentTarget.dataset.btn;
    this.handlePay(btn, type);
  },

  //获取代付会员信息和支付信息
  getPayerInfo: function() {
    var that = this;
    var _url = app.getNetAddresss("order.merge-pay.anotherPayOrder");
    _url += "&order_ids=" + that.data.order_id + '&mid=' + that.data.mid;
    _url += '&pid=' + that.data.pid;
    app._getNetWork({
      url: _url,
      success: function(response) {
        //var _data = res.data.data;
        if (response.data.result == 1) {
          var rs = response.data.data;
          that.setData({
            payerImg: rs.member.avatar,
            payerName: rs.member.nickname,
            order_pay_id: rs.order_pay.id,
            buttons: rs.buttons,
            totalPrice:rs.order_pay.amount
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'none',
            duration: 2000,
            success: function() {
              // wx.reLaunch({
              //   url: '/packageG/index/index'
              // });
            },
            fail: function() {}
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },
  getOrderDetail: function() {
    var that = this;
    var _url = app.getNetAddresss("order.another-pay-detail");
    _url += "&order_id=" + that.data.order_id + '&mid=' + that.data.mid;
    _url += '&pid=' + that.data.pid;
    app._getNetWork({
      url: _url,
      success: function(response) {
        //var _data = res.data.data;
        console.log("ressss::::", response);
        if (response.data.result == 1) {
          // 从另外的接口获取
          // var totalPrice = 0;
          // for (var i in response.data.data) {
          //   for (var j in response.data.data[i].has_many_order_goods) {
          //     totalPrice += parseFloat(response.data.data[i].has_many_order_goods[j].price);
          //   }
          // }

          that.setData({
            goodList: response.data.data,
            //	totalPrice: totalPrice.toFixed(2),
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'none',
            duration: 2000
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },

  onLoad: function(options) {
    var that = this;
    console.log('options:', options);
    // mid: options.mid,
    let _mid = wx.getStorageSync('yz_uid');
    that.setData({
      order_id: options.id,
      mid: _mid,
      pid: options.p
    });

    this.getPayerInfo();
    this.getOrderDetail();

  },

  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
    // 页面渲染完成
  },
});
