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

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    mailLanguage: '',
    mailFullReturnTitle: '',
    mailFullReturnAmount: '',
    mailFullReturnName: '',
    order_amount: 0.00,
    return_amount: 0.00,
    status_name: '',
    each_return_rate: 0,
    return_mode: '',
    not_return: 0.00,
    order_sn: '',
    created_at: '',
    finish_time: '',
    id: ''
  },

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

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  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 mailFullReturnTitle = app.setMailLanguage('赠送详情', mailLanguage.full_return.return_detail);
          let mailFullReturnAmount = app.setMailLanguage('已赠送金额', mailLanguage.full_return.return_amount);
          let mailFullReturnName = app.setMailLanguage('赠送', mailLanguage.full_return.return_name);
          this.setData({
            mailLanguage,
            mailFullReturnTitle,
            mailFullReturnAmount,
            mailFullReturnName
          });
          wx.setNavigationBarTitle({
            title: mailFullReturnTitle ? mailFullReturnTitle : ''
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 获取数据
  getData() {
    let urlStr = app.getNetAddresss('plugin.full-return.frontend.detail.index');
    urlStr += "&log_id=" + this.options.id;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            amount: resdata.data.item.amount,
            ratio: resdata.data.item.info.ratio,
            info: resdata.data.item.info,
            turnover: resdata.data.item.info.turnover,
            unit_price: resdata.data.item.info.unit_price,
            amount_total: resdata.data.item.info.amount_total,
            amount_surplus: resdata.data.item.info.amount_surplus,
            created_at: resdata.data.item.created_at,
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
});
