// packageD/member/myMarket/myMarket.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    marketid: 0,
    amounts: 0,
    num: 0,
    titleName: "我的市场",
  },

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

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

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

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

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

  getData(marketid) {
    let json = {};
    if (marketid && marketid != 0) {
      this.setData({
        titleName: "下级市场",
      });
      wx.setNavigationBarTitle({
        title: "下级市场",
      });
      json.member_id = marketid;
    }
    let urlStr = app.getNetAddresss(
      "plugin.regional-reward.Frontend.controllers.achievement.index"
    );
    app._getNetWork({
      url: urlStr,
      data: json,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result != 1) {
          wx.showToast({
            title: res.msg,
            icon: "none",
          });
          setTimeout(() => {
            wx.navigateBack();
          }, 1000);

          return;
        }
        this.setData({
          listData: res.data.childs,
          amounts: res.data.amounts,
          num: res.data.num,
        });
      },
    });
  },

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

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

  getMoreData() {
    console.log("触发加载更多");
    let data = this.data.listData;
    this.setData({
      listData: data.concat(new Array(10)),
    });
  },

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