// packageH/shopRanking/shopRankingList/list.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    status: false,
    calsst: "z",
    id: "",
    share: [],
    setting: [],
    language: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        id: options.id,
      });
      this.getData();
    }
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
    });
  },
  tapClass(e) {
    let ind = e.currentTarget.dataset.ind;
    console.log(ind);
    if (ind == "z") {
      this.setData({
        calsst: ind,
        topBanner: this.data.info.banner,
      });
    } else {
      this.data.navinfo = [];
      this.setData({
        navinfo: this.data.info.other_rank_list[ind],
        calsst: ind,
        topBanner: this.data.info.other_rank_list[ind].banner,
      });
    }
  },
  goDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/packageA/detail_v2/detail_v2?id=" + id,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  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?id=" + this.data.id,
      imageUrl: share_logo ? share_logo : "",
    };
  },
  getData() {
    wx.showLoading({
      title: "加载中",
    });
    let that = this;
    let urlStr = app.getNetAddresss("plugin.goods-ranking.api.index.rank-info");
    app._postNetWork({
      url: urlStr,
      data: {
        id: that.data.id,
      },
      success: (resdata) => {
        let res = resdata.data;
        wx.hideLoading({
          success: (res) => {},
        });
        if (res.result == 1) {
          that.setData({
            info: res.data,
            status: res.data.has_category,
            setting: res.data.setting,
            topBanner: res.data.banner,
          });
          console.log(that.data.status);
          if (res.data.has_category == "1") {
            this.setData({
              calsst: "z",
              navinfo: res.data.other_rank_list[0],
            });
          }
          wx.setNavigationBarTitle({
            title: res.data.name,
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      },
    });
  },
});
