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

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    mailLanguage: '',
    mailSingleReturnName: '',
    mailReturnDetail: '',
    mailReturnAmount: '',
    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: ''
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  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 mailReturnDetail = app.setMailLanguage('消费赠送', mailLanguage.single_return.return_detail);
          let mailReturnAmount = app.setMailLanguage('赠送', mailLanguage.single_return.return_amount);
          let mailSingleReturnName = app.setMailLanguage('消费队列', mailLanguage.single_return.return_name);
          this.setData({
            mailReturnDetail,
            mailReturnAmount,
            mailSingleReturnName
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  // 获取数据
  getData() {
    let urlStr = app.getNetAddresss('plugin.single-return.api.single-return.get-single-return-queue-detail');
    urlStr += '&queue_id=' + this.options.id;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            order_amount: resData.data.order_amount,
            return_amount: resData.data.return_amount,
            status_name: resData.data.status_name,
            each_return_rate: resData.data.each_return_rate,
            return_mode: resData.data.return_mode,
            not_return: resData.data.not_return,
            id: resData.data.id,
            order_sn: resData.data.order_sn,
            created_at: resData.data.created_at,
            finish_time: resData.data.finish_time
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  goBack() {
    wx.navigateBack({
      delta: 1
    });
  }
});
