// packageH/shopRanking/shopRanking/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    page: 1,
    showcarrfootBol: false,
    showcarrfoot_ipxBol: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata();
  },
  toBd(e) {
    console.log(e);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/packageH/shopRanking/shopRankingList/shopRankingList?id=" + id,
    });
  },
  goDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/packageA/detail_v2/detail_v2?id=" + id,
    });
  },
  tapBtn() {
    this.setData({
      show: true,
    });
  },
  onClickLeft() {
    this.setData({
      show: false,
    });
  },
  showcarrfoot_ipx(e) {
    let bol = e.detail;
    this.setData({
      showcarrfoot_ipxBol: bol,
    });
  },
  showcarrfoot(e) {
    let bol = e.detail;
    this.setData({
      showcarrfootBol: bol,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

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

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.current_page >= this.data.last_page) {
      return;
    } else {
      let pages = this.data.page + 1;
      this.setData({
        page: pages,
      });
      this.getMoreData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // let share_desc = this.data.setting.share_desc;
    let share_logo = this.data.setting.share_logo;
    let share_title = this.data.setting.share_title;
    let title = this.data.setting.title;
    return {
      title: share_title ? share_title : title,
      path: "/packageH/shopRanking/shopRanking/index",
      imageUrl: share_logo ? share_logo : "",
    };
  },
  getdata() {
    wx.showLoading({
      title: "加载中",
    });
    let that = this;
    let urlStr = app.getNetAddresss("plugin.goods-ranking.api.index.rank-list");
    app._postNetWork({
      url: urlStr,
      data: {
        page: this.data.page,
      },
      success: (resdata) => {
        let res = resdata.data;
        wx.hideLoading({
          success: (res) => {},
        });
        if (res.result == 1) {
          that.setData({
            rank_list: res.data.data.rank_list,
            setting: res.data.data.setting,
            current_page: res.data.current_page,
            last_page: res.data.last_page,
          });
          wx.setNavigationBarTitle({
            title: res.data.data.setting.title,
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
  getMoreData() {
    wx.showLoading({
      title: "加载中",
    });
    let that = this;
    let urlStr = app.getNetAddresss("plugin.goods-ranking.api.index.rank-list");
    app._postNetWork({
      url: urlStr,
      data: {
        page: this.data.page,
      },
      success: (resdata) => {
        let res = resdata.data;
        wx.hideLoading({
          success: (res) => {},
        });
        if (res.result == 1) {
          let nextData = res.data.data.rank_list;
          that.data.rank_list = that.data.rank_list.concat(nextData);
          that.setData({
            rank_list: that.data.rank_list,
            current_page: res.data.current_page,
            last_page: res.data.last_page,
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
});
