// subpages/helpList/helpList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mCateList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCateList();

  },
  onClickLeft() {
    wx.navigateBack();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  toDetails(e) {
    // "helpDetails/helpDetails"
    console.log(e.currentTarget.dataset.item);
    wx.navigateTo({
      url: `/subpages/helpDetails/helpDetails?id=` + e.currentTarget.dataset.item.arcid
    })
  },
  getCateList() {
    const that = this;
    wx.request({
      url: 'https://aipush.aidsleep.cn/allhelcatelist',
      method: 'POST',
      data: {
        tokens: "aa9ebf8360ec36bd0f6cc950b9e2f45e282ae1f93f5d3c56f2ffa6984cd22c66" || wx.getStorageSync('token'),
        udi: wx.getStorageSync('unionid')
      },
      success: async (res) => {

        console.log(res.data);
        // ""
        if (res.data) {
          var tempList = res.data || [];
          // for (let i = 0; i < tempList.length; i++) {
          //   const element = tempList[i];
          //   element.icon = `https://aipush.aidsleep.cn/assets/helpics/${element.icon}`;
          //   that.getList(tempList, i, element.cid)
          // }
          // [{"cid":11,"name":"房间控制","icon":"all_67362a14b131f.png","subList":"[]"}]
          // console.log("tempList=>", JSON.stringify(tempList));
          // console.log("tempList=>", tempList);
          // setTimeout(() => {
            that.setData({
              mCateList: tempList
            })
          // }, 250 * tempList.length);

        }

      },
      fail: () => {
      }
    });
  },
  getList(mList = [], index = 0, helcid) {
    const that = this;
    wx.request({
      url: 'https://aipush.aidsleep.cn/allhelarclist',
      method: 'POST',
      data: {
        tokens: "aa9ebf8360ec36bd0f6cc950b9e2f45e282ae1f93f5d3c56f2ffa6984cd22c66" || wx.getStorageSync('token'),
        udi: wx.getStorageSync('unionid'),
        helcid
      },
      success: (res) => {
        // console.log(res.data);
        mList[index]['subList'] = res.data || [];
      },
      fail: () => {
      }
    });
  },
})