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

  /**
	 * 页面的初始数据
	 */
  data: {
    _id: '',
    info: {},
    order: {},
    goods: {},
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    if (options.id) {
      this.setData({
        _id: options.id
      });
    }
    //获取数据
    this._getData();
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  //获取数据
  _getData() {
    let that = this;
    let urlStr = app.getNetAddresss("finance.income.get-detail");
    urlStr += '&id=' + this.data._id;
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that._setData(res.data);
        } else {
          console.log(res.msg);
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  _setData(data) {
    let that=this;
    if (data == null || data == '' || data == undefined) {
      wx.showModal({
        title: '提示',
        content: '无详情显示',
        success(res) {
          if (res.confirm) {
            wx.navigateBack({
              delta: 1
            });
          } else if (res.cancel) {
            wx.navigateBack({
              delta: 1
            });
          }
        }
      });
      return;
    }

    if (!app._isTextEmpty(data.commission)) {
      that.setData({
        info: data.commission,
        order: data.order,
        goods: data.goods
      });
      return;
    }

    if (!app._isTextEmpty(data.area_dividend)) {
      that.setData({
        info: data.area_dividend,
        order: data.order,
        goods: data.goods
      });
      return;
    }
  },

});
