// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    mailLanguage: "",
    mailTeamReturnTitle: "",
    mailTeamAmount: "",
    mailTeamReturnRate: "",
    mailTeamName: "",
    mailTeamReturnName: "",
    order_amount: 0.00,
    return_amount: 0.00,
    status_name: "",
    each_return_rate: 0,
    return_mode: "",
    not_return: 0.00,
    id: "",
    order_sn: "",
    created_at: "",
    finish_time: "",
    mall_amount: "",
    rate: "",
    power_data: "",
    power_total: "",
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.initMailLanguage();
    this.getData(); //初始化数据
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

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

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

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

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

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

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  initMailLanguage() {
    let mailLanguage;
    let urlStr = app.getNetAddresss('setting.get-lang-setting');
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          mailLanguage = resData.data;
          let mailTeamReturnTitle = app.setMailLanguage("赠送详情", mailLanguage.team_return.return_detail);
          let mailTeamAmount = app.setMailLanguage("赠送金额", mailLanguage.team_return.return_amount);
          let mailTeamReturnRate = app.setMailLanguage("赠送比例", mailLanguage.team_return.return_rate);
          let mailTeamName = app.setMailLanguage("经销商", mailLanguage.team_return.mailTeamName);
          let mailTeamReturnName = app.setMailLanguage("赠送", mailLanguage.team_return.return_name);

          this.setData({
            mailTeamReturnTitle,
            mailTeamAmount,
            mailTeamReturnRate,
            mailTeamReturnName,
            mailTeamName
          });
          wx.setNavigationBarTitle({
            title: mailTeamReturnTitle ? mailTeamReturnTitle : ''
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  //获取数据
  getData() {
    let urlStr = app.getNetAddresss('plugin.team-return.api.team-return.get-team-return-detail');
    urlStr += "&logid=" + this.options.id;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            return_amount: resData.data.amount,
            power_total: resData.data.power_total,
            power_data: resData.data.power_data,
            mall_amount: resData.data.mall_amount,
            id: resData.data.id,
            rate: resData.data.rate,
            created_at: resData.data.created_at
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });

  },
});
