"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_request = require("../../../api/request.js");
const _sfc_main = {
  __name: "main",
  setup(__props) {
    const currentColor = common_vendor.ref(0);
    const sort = common_vendor.ref([{}]);
    const headerList = common_vendor.ref([{}]);
    const productList = common_vendor.ref([{}]);
    const cookie = common_vendor.wx$1.getStorageSync("cookie");
    common_vendor.onMounted(async () => {
      console.log("cookie--->", cookie);
      await Getsort();
      await changeTypes(sort.value[0], 0);
    });
    const Getsort = async () => {
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/category/list",
        method: "POST",
        header: {
          cookie
        }
      });
      if (res.data.code === 1) {
        for (let key in res.data.data) {
          sort.value[key] = {
            //类别列表
            name: res.data.data[key].typeName,
            imgurl: res.data.data[key].typeUrl,
            id: res.data.data[key].id
          };
          headerList.value[key] = {
            name: res.data.data[key].typeName,
            typeIntro: res.data.data[key].typeIntro
          };
        }
      } else {
        common_vendor.index.showToast({
          //提示请求错误
          title: "请求商品分类错误",
          icon: "none",
          duration: 2e3
        });
      }
      console.log("获取商品分类==>", res.data);
    };
    const changeTypes = async (item, index) => {
      currentColor.value = index;
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/category/list/type",
        method: "POST",
        data: {
          id: item.id
        },
        header: {
          cookie
        }
      });
      console.log("类别下的商品--->", res.data.data);
      if (res.data.code === 1) {
        productList.value = res.data.data[item.id];
      } else {
        common_vendor.index.showToast({
          //商品请求错误
          title: "更改类别错误",
          icon: "none",
          duration: 2e3
        });
      }
    };
    const getBoxStyle = (index) => ({
      backgroundColor: currentColor.value === index ? "brown" : "#fffef8"
    });
    const goToProduct = (item) => {
      common_vendor.index.navigateTo({
        url: "../../../pages/store-home/ProductDetails/ProductDetails?gid=" + JSON.stringify(item.id)
      });
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(sort.value, (item, index, i0) => {
          return {
            a: item.imgurl,
            b: common_vendor.t(item.name),
            c: index,
            d: common_vendor.s(getBoxStyle(index)),
            e: common_vendor.o(($event) => changeTypes(item, index), index)
          };
        }),
        b: common_vendor.f(productList.value, (item, index, i0) => {
          return {
            a: item.goodImg.split(";")[0],
            b: common_vendor.t(item.name),
            c: common_vendor.t(item.intro),
            d: common_vendor.t(item.price),
            e: common_vendor.o(() => {
            }, index),
            f: index,
            g: common_vendor.o(($event) => goToProduct(item), index)
          };
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7e3c386d"], ["__file", "D:/微信小程序/课设整合/匠承非遗小程序端/jiangchengfeiyi-xiaochengxu/pages/store-home/main/main.vue"]]);
wx.createPage(MiniProgramPage);
