"use strict"; const common_vendor = require("../../../common/vendor.js"); const api_request = require("../../../api/request.js"); const common_assets = require("../../../common/assets.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([{}]); common_vendor.onMounted(async () => { 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" }); 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 } }); 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) => { console.log(item, 123); common_vendor.index.navigateTo({ url: "../../../pages/store-home/ProductDetails/ProductDetails?info=" + JSON.stringify(item) }); }; return (_ctx, _cache) => { return { a: common_vendor.unref(common_assets.sousuokuang), b: 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) }; }), c: common_vendor.f(productList.value, (item, index, i0) => { return { a: item.goodImg, b: common_vendor.t(item.name), c: common_vendor.t(item.intro), d: common_vendor.t(item.price), e: index, f: common_vendor.o(($event) => goToProduct(item), index) }; }), d: common_vendor.unref(common_assets.add_img) }; }; } }; 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);