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

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    inputs: "",
    uids: [],
    memberInfo: {}
  },

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

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

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  initData() {
    this.setData({
      uids: []
    });
  },
  upToTop() {
    this.setData({
      inputs: ""
    });
    this.initData();
    this.gotoSearch();
  },
  gotoSearch(flag) {
    let that = this;
    if (!flag && this.data.inputs && !this.data.uids.includes(this.data.inputs)) {
      let uids = this.data.uids;
      uids.push(this.data.inputs);
      this.setData({
        uids: uids
      });
    }
    let urlStr = app.getNetAddresss("plugin.distribution-order.api.controller.get-member-children");
    app._getNetWork({
      url: urlStr,
      data: {
        uid: this.data.inputs
      },
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            memberInfo: res.data
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  goback() {
    if (this.data.uids.length > 0) {
      let uids = this.data.uids;
      uids.pop();
      this.setData({
        uids: uids
      });
      if (this.data.uids.length > 0) {
        this.setData({
          inputs: this.data.uids[this.data.uids.length - 1]
        });
      } else {
        this.setData({
          inputs: ""
        });
      }
      if (!this.data.inputs) {
        this.setData({
          inputs: ""
        });
      }
      this.gotoSearch("no");
    }
  },
  inpbtn(e) {
    let val = e.detail.value;
    this.setData({
      inputs: val
    });
  },
  inpbtnclear() {
    this.setData({
      inputs: ''
    });
  },
  toNext(e) {
    let id = e.currentTarget.dataset.uid;
    this.setData({
      inputs: id
    });
    this.gotoSearch();
  },
});
