"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_index = require("../../sheep/index.js");
const sheep_api_product_category = require("../../sheep/api/product/category.js");
const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
const sheep_util_index = require("../../sheep/util/index.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/comment.js");
require("../../sheep/api/product/favorite.js");
require("../../sheep/api/product/history.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/brokerage.js");
require("../../sheep/api/trade/config.js");
require("../../sheep/api/trade/delivery.js");
require("../../sheep/config/zIndex.js");
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_easycom_uni_load_more2 + _easycom_s_layout2)();
}
const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  (firstOne + firstTwo + secondOne + _easycom_uni_load_more + _easycom_s_layout)();
}
const secondOne = () => "./components/second-one.js";
const firstOne = () => "./components/first-one.js";
const firstTwo = () => "./components/first-two.js";
const _sfc_main = {
  __name: "category",
  setup(__props) {
    const state = common_vendor.reactive({
      style: "second_one",
      // first_one（一级 - 样式一）, first_two（二级 - 样式二）, second_one（二级）
      categoryList: [],
      // 商品分类树
      activeMenu: 0,
      // 选中的一级菜单，在 categoryList 的下标
      pagination: {
        // 商品分页
        list: [],
        // 商品列表
        total: [],
        // 商品总数
        pageNo: 1,
        pageSize: 6
      },
      loadStatus: ""
    });
    const {
      safeArea
    } = sheep_index.sheep.$platform.device;
    const pageHeight = common_vendor.computed(() => safeArea.height - 44 - 50);
    async function getList() {
      const {
        code,
        data
      } = await sheep_api_product_category.CategoryApi.getCategoryList();
      if (code !== 0) {
        return;
      }
      state.categoryList = sheep_util_index.handleTree(data);
    }
    const onMenu = (val) => {
      state.activeMenu = val;
      if (state.style === "first_one" || state.style === "first_two") {
        state.pagination.pageNo = 1;
        state.pagination.list = [];
        state.pagination.total = 0;
        getGoodsList();
      }
    };
    async function getGoodsList() {
      state.loadStatus = "loading";
      const res = await sheep_api_product_spu.SpuApi.getSpuPage({
        categoryId: state.categoryList[state.activeMenu].id,
        pageNo: state.pagination.pageNo,
        pageSize: state.pagination.pageSize
      });
      if (res.code !== 0) {
        return;
      }
      state.pagination.list = common_vendor._.concat(state.pagination.list, res.data.list);
      state.pagination.total = res.data.total;
      state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
    }
    function loadMore() {
      if (state.loadStatus === "noMore") {
        return;
      }
      state.pagination.pageNo++;
      getGoodsList();
    }
    common_vendor.onLoad(async () => {
      await getList();
      if (state.style === "first_one" || state.style === "first_two") {
        onMenu(0);
      }
    });
    common_vendor.onReachBottom(() => {
      loadMore();
    });
    return (_ctx, _cache) => {
      var _a, _b;
      return common_vendor.e({
        a: common_vendor.f(state.categoryList, (item, index, i0) => {
          return {
            a: common_vendor.t(item.name),
            b: item.id,
            c: common_vendor.n({
              "menu-item-active": index === state.activeMenu
            }),
            d: common_vendor.o(($event) => onMenu(index), item.id)
          };
        }),
        b: common_vendor.s({
          height: pageHeight.value + "px"
        }),
        c: (_a = state.categoryList) == null ? void 0 : _a.length
      }, ((_b = state.categoryList) == null ? void 0 : _b.length) ? common_vendor.e({
        d: state.categoryList[state.activeMenu].picUrl
      }, state.categoryList[state.activeMenu].picUrl ? {
        e: common_vendor.unref(sheep_index.sheep).$url.cdn(state.categoryList[state.activeMenu].picUrl)
      } : {}, {
        f: state.style === "first_one"
      }, state.style === "first_one" ? {
        g: common_vendor.p({
          pagination: state.pagination
        })
      } : {}, {
        h: state.style === "first_two"
      }, state.style === "first_two" ? {
        i: common_vendor.p({
          pagination: state.pagination
        })
      } : {}, {
        j: state.style === "second_one"
      }, state.style === "second_one" ? {
        k: common_vendor.p({
          data: state.categoryList,
          activeMenu: state.activeMenu
        })
      } : {}, {
        l: (state.style === "first_one" || state.style === "first_two") && state.pagination.total > 0
      }, (state.style === "first_one" || state.style === "first_two") && state.pagination.total > 0 ? {
        m: common_vendor.o(loadMore),
        n: common_vendor.p({
          status: state.loadStatus,
          ["content-text"]: {
            contentdown: "点击查看更多"
          }
        })
      } : {}, {
        o: common_vendor.s({
          height: pageHeight.value + "px"
        })
      }) : {}, {
        p: common_vendor.s({
          height: pageHeight.value + "px"
        }),
        q: common_vendor.p({
          title: "分类",
          tabbar: "/pages/index/category",
          bgStyle: {
            color: "#fff"
          }
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1031f1cf"], ["__file", "D:/zx/mall-front-app/pages/index/category.vue"]]);
wx.createPage(MiniProgramPage);
