// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    language: "",
    mailLanguage: "",
    mailTeamReturnTitle: "",
    mailTeamLevel: "",
    mailTeamReturnName: "",
    mailReturnLog: "",
    team_level: "",
    level_power: 0,
    return_amount: "",
    activeName: "first",
    first_content: [],
    alreadyReturn: 0.0,
    each_return_rate: 0,
    order_return_rate: 0,
    returnAmountTotal: 0.0,
    notReturn: 0.0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.checkrouter();
    this.initMailLanguage();
    this.getData(); //初始化数据
    this.getReturnListInfo();
  },
  checkrouter() {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == "teamlevel_return_center") {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");

          wx.showToast({
            title: "未开启推广权限",
            duration: 1000,
            icon: "none",
            success: function () {
              setTimeout(() => {
                wx.redirectTo({
                  url: basic_info.popularize_page.mini.mini_url,
                });
              }, 1000);
            },
          });
          return;
        }
      }
    } catch (e) {
      console.log(e);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({ language: language.en });
  },

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  initMailLanguage() {
    let mailLanguage;
    let urlStr = app.getNetAddresss("setting.get-lang-setting");
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          mailLanguage = resData.data;
          let mailTeamReturnTitle = app.setMailLanguage(
            "团队赠送",
            mailLanguage.team_return.team_return
          );
          let mailTeamLevel = app.setMailLanguage(
            "经销商等级",
            mailLanguage.team_return.team_level
          );
          let mailTeamReturnName = app.setMailLanguage(
            "赠送",
            mailLanguage.team_return.return_name
          );
          let mailReturnLog = app.setMailLanguage(
            "赠送记录",
            mailLanguage.team_return.return_log
          );
          this.setData({
            mailTeamReturnTitle,
            mailTeamLevel,
            mailTeamReturnName,
            mailReturnLog,
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //初始化数据
  getData() {
    let urlStr = app.getNetAddresss(
      "plugin.team-return.api.team-return.get-team-return-statistic"
    );
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            team_level: resData.data.team_level,
            return_amount: resData.data.return_amount,
            level_power: resData.data.level_power,
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  //返现队列详情
  toReturnInfo(id) {
    let ids = id.target.dataset.id || id.currentTarget.dataset.id;
    wx.navigateTo({
      url:
        "/packageB/member/income/teamlevel_return_list_info/teamlevel_return_list_info" +
        "?id=" +
        ids,
    });

    // this.$router.push(this.fun.getUrl('teamlevel_return_list_info', { "id": id }));
  },

  //获取返现
  getReturnListInfo() {
    let urlStr = app.getNetAddresss(
      "plugin.team-return.api.team-return.get-team-return-log"
    );
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            first_content: resData.data,
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
});
