"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_index = require("../../sheep/index.js");
const sheep_api_trade_brokerage = require("../../sheep/api/trade/brokerage.js");
const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
require("../../sheep/api/index.js");
require("../../sheep/api/distri/score.js");
require("../../sheep/request/index.js");
require("../../sheep/config/index.js");
require("../../sheep/store/index.js");
require("../../sheep/store/app.js");
require("../../sheep/api/promotion/diy.js");
require("../../sheep/platform/index.js");
require("../../sheep/platform/provider/wechat/index.js");
require("../../sheep/platform/provider/wechat/miniProgram.js");
require("../../sheep/api/member/auth.js");
require("../../sheep/api/member/social.js");
require("../../sheep/api/member/user.js");
require("../../sheep/platform/provider/apple/index.js");
require("../../sheep/platform/share.js");
require("../../sheep/router/index.js");
require("../../sheep/hooks/useModal.js");
require("../../sheep/helper/index.js");
require("../../sheep/helper/test.js");
require("../../sheep/helper/digit.js");
require("../../sheep/api/member/signin.js");
require("../../sheep/helper/throttle.js");
require("../../sheep/url/index.js");
require("../../sheep/platform/pay.js");
require("../../sheep/api/pay/order.js");
require("../../sheep/store/user.js");
require("../../sheep/store/cart.js");
require("../../sheep/api/trade/cart.js");
require("../../sheep/api/pay/wallet.js");
require("../../sheep/api/trade/order.js");
require("../../sheep/api/promotion/coupon.js");
require("../../sheep/store/sys.js");
require("../../sheep/store/modal.js");
require("../../sheep/api/distri/share.js");
require("../../sheep/api/distri/team.js");
require("../../sheep/api/infra/file.js");
require("../../sheep/api/member/address.js");
require("../../sheep/api/member/point.js");
require("../../sheep/api/migration/app.js");
require("../../sheep/api/migration/chat.js");
require("../../sheep/api/migration/index.js");
require("../../sheep/api/migration/third.js");
require("../../sheep/api/pay/channel.js");
require("../../sheep/api/product/category.js");
require("../../sheep/api/product/comment.js");
require("../../sheep/api/product/favorite.js");
require("../../sheep/api/product/history.js");
require("../../sheep/api/product/spu.js");
require("../../sheep/api/promotion/activity.js");
require("../../sheep/api/promotion/article.js");
require("../../sheep/api/promotion/bargain.js");
require("../../sheep/api/promotion/combination.js");
require("../../sheep/api/promotion/rewardActivity.js");
require("../../sheep/api/promotion/seckill.js");
require("../../sheep/api/system/area.js");
require("../../sheep/api/system/voice.js");
require("../../sheep/api/trade/afterSale.js");
require("../../sheep/api/trade/config.js");
require("../../sheep/api/trade/delivery.js");
require("../../sheep/config/zIndex.js");
require("../../sheep/util/index.js");
if (!Array) {
  const _component_emptyPage = common_vendor.resolveComponent("emptyPage");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_component_emptyPage + _easycom_s_layout2)();
}
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  _easycom_s_layout();
}
const _sfc_main = {
  __name: "commission-ranking",
  setup(__props) {
    const tabMaps = ["周排行", "月排行"];
    const state = common_vendor.reactive({
      currentTab: 0,
      position: 0,
      // 排名
      rankList: []
    });
    async function switchTap(index) {
      state.currentTab = index;
      state.rankList = [];
      calculateTimes();
      getBrokerageRankList();
      getBrokerageRankNumber();
    }
    async function getBrokerageRankList() {
      const {
        code,
        data
      } = await sheep_api_trade_brokerage.BrokerageApi.getBrokerageUserChildSummaryPageByPrice({
        pageNo: 1,
        pageSize: 10,
        "times[0]": state.times[0],
        "times[1]": state.times[1]
      });
      if (code !== 0) {
        return;
      }
      state.rankList = data.list;
    }
    async function getBrokerageRankNumber() {
      const {
        code,
        data
      } = await sheep_api_trade_brokerage.BrokerageApi.getRankByPrice({
        times: state.times
      });
      if (code !== 0) {
        return;
      }
      state.position = data;
    }
    function formatDate(date) {
      return sheep_index.sheep.$helper.timeFormat(date, "yyyy-mm-dd hh:MM:ss");
    }
    function calculateTimes() {
      let times;
      if (state.currentTab === 0) {
        times = getWeekTimes();
      } else {
        times = getMonthTimes();
      }
      state.times = [formatDate(times[0]), formatDate(times[1])];
    }
    common_vendor.onLoad(function() {
      calculateTimes();
      getBrokerageRankList();
      getBrokerageRankNumber();
    });
    function getWeekTimes() {
      const today = /* @__PURE__ */ new Date();
      const dayOfWeek = today.getDay();
      return [
        new Date(today.getFullYear(), today.getMonth(), today.getDate() - dayOfWeek, 0, 0, 0),
        new Date(
          today.getFullYear(),
          today.getMonth(),
          today.getDate() + (6 - dayOfWeek),
          23,
          59,
          59
        )
      ];
    }
    function getMonthTimes() {
      const today = /* @__PURE__ */ new Date();
      const year = today.getFullYear();
      const month = today.getMonth();
      const startDate = new Date(year, month, 1, 0, 0, 0);
      const nextMonth = new Date(year, month + 1, 1);
      const endDate = new Date(nextMonth.getTime() - 1);
      return [startDate, endDate];
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: state.position
      }, state.position ? {
        b: common_vendor.t(state.position)
      } : {}, {
        c: common_vendor.f(tabMaps, (item, index, i0) => {
          return {
            a: common_vendor.t(item),
            b: common_vendor.n(state.currentTab === index ? "font-color" : ""),
            c: index,
            d: common_vendor.o(($event) => switchTap(index), index)
          };
        }),
        d: common_vendor.f(state.rankList, (item, index, i0) => {
          return common_vendor.e({
            a: index <= 2
          }, index <= 2 ? {
            b: "/static/images/medal0" + (index + 1) + ".png"
          } : {
            c: common_vendor.t(index + 1)
          }, {
            d: item.avatar,
            e: common_vendor.t(item.nickname),
            f: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(item.brokeragePrice)),
            g: index
          });
        }),
        e: state.rankList.length === 0 && (state.page !== 1 || state.active === 0)
      }, state.rankList.length === 0 && (state.page !== 1 || state.active === 0) ? {
        f: common_vendor.p({
          title: "暂无排行～"
        })
      } : {}, {
        g: common_vendor.p({
          title: "佣金排行榜"
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4b4e4229"], ["__file", "D:/zx/mall-front-app/pages/commission/commission-ranking.vue"]]);
wx.createPage(MiniProgramPage);
