2024-10-17 05:04:16 +00:00
|
|
|
"use strict";
|
|
|
|
const common_vendor = require("../../../common/vendor.js");
|
2024-11-03 23:34:53 +00:00
|
|
|
const api_request = require("../../../api/request.js");
|
2024-10-17 05:04:16 +00:00
|
|
|
const common_assets = require("../../../common/assets.js");
|
|
|
|
const _sfc_main = {
|
|
|
|
__name: "main",
|
|
|
|
setup(__props) {
|
2024-11-03 23:34:53 +00:00
|
|
|
const currentColor = common_vendor.ref(0);
|
|
|
|
const sort = common_vendor.ref([{}]);
|
|
|
|
const headerList = common_vendor.ref([{}]);
|
|
|
|
const productList = common_vendor.ref([{}]);
|
2024-11-15 06:22:52 +00:00
|
|
|
const cookie = common_vendor.wx$1.getStorageSync("cookie");
|
2024-11-03 23:34:53 +00:00
|
|
|
common_vendor.onMounted(async () => {
|
2024-11-15 06:22:52 +00:00
|
|
|
console.log("cookie--->", cookie);
|
2024-11-03 23:34:53 +00:00
|
|
|
await Getsort();
|
|
|
|
await changeTypes(sort.value[0], 0);
|
2024-10-20 05:16:38 +00:00
|
|
|
});
|
|
|
|
const Getsort = async () => {
|
|
|
|
const res = await common_vendor.index.request({
|
2024-11-05 06:39:58 +00:00
|
|
|
url: api_request.baseUrl + "/category/list",
|
2024-11-15 06:22:52 +00:00
|
|
|
method: "POST",
|
|
|
|
header: {
|
|
|
|
cookie
|
|
|
|
}
|
2024-10-20 05:16:38 +00:00
|
|
|
});
|
2024-11-03 23:34:53 +00:00
|
|
|
if (res.data.code === 1) {
|
2024-10-20 05:16:38 +00:00
|
|
|
for (let key in res.data.data) {
|
|
|
|
sort.value[key] = {
|
2024-11-03 23:34:53 +00:00
|
|
|
//类别列表
|
2024-10-20 05:16:38 +00:00
|
|
|
name: res.data.data[key].typeName,
|
|
|
|
imgurl: res.data.data[key].typeUrl,
|
|
|
|
id: res.data.data[key].id
|
|
|
|
};
|
2024-11-03 23:34:53 +00:00
|
|
|
headerList.value[key] = {
|
|
|
|
name: res.data.data[key].typeName,
|
|
|
|
typeIntro: res.data.data[key].typeIntro
|
|
|
|
};
|
2024-10-20 05:16:38 +00:00
|
|
|
}
|
2024-11-03 23:34:53 +00:00
|
|
|
} else {
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
//提示请求错误
|
|
|
|
title: "请求商品分类错误",
|
|
|
|
icon: "none",
|
|
|
|
duration: 2e3
|
|
|
|
});
|
2024-10-17 05:04:16 +00:00
|
|
|
}
|
2024-11-05 06:39:58 +00:00
|
|
|
console.log("获取商品分类==>", res.data);
|
2024-10-20 05:16:38 +00:00
|
|
|
};
|
2024-11-03 23:34:53 +00:00
|
|
|
const changeTypes = async (item, index) => {
|
|
|
|
currentColor.value = index;
|
|
|
|
const res = await common_vendor.index.request({
|
2024-11-05 06:39:58 +00:00
|
|
|
url: api_request.baseUrl + "/category/list/type",
|
2024-11-03 23:34:53 +00:00
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
id: item.id
|
2024-11-15 06:22:52 +00:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
cookie
|
2024-11-03 23:34:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if (res.data.code === 1) {
|
|
|
|
productList.value = res.data.data[item.id];
|
|
|
|
} else {
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
//商品请求错误
|
|
|
|
title: "更改类别错误",
|
|
|
|
icon: "none",
|
|
|
|
duration: 2e3
|
|
|
|
});
|
2024-10-17 05:04:16 +00:00
|
|
|
}
|
2024-11-03 23:34:53 +00:00
|
|
|
};
|
|
|
|
const getBoxStyle = (index) => ({
|
|
|
|
backgroundColor: currentColor.value === index ? "brown" : "#fffef8"
|
|
|
|
});
|
|
|
|
const goToProduct = (item) => {
|
|
|
|
console.log(item, 123);
|
2024-10-18 05:56:23 +00:00
|
|
|
common_vendor.index.navigateTo({
|
2024-11-03 23:34:53 +00:00
|
|
|
url: "../../../pages/store-home/ProductDetails/ProductDetails?info=" + JSON.stringify(item)
|
2024-10-18 05:56:23 +00:00
|
|
|
});
|
|
|
|
};
|
2024-10-17 05:04:16 +00:00
|
|
|
return (_ctx, _cache) => {
|
|
|
|
return {
|
2024-10-18 16:55:25 +00:00
|
|
|
a: common_vendor.unref(common_assets.sousuokuang),
|
|
|
|
b: common_vendor.f(sort.value, (item, index, i0) => {
|
2024-10-17 05:04:16 +00:00
|
|
|
return {
|
|
|
|
a: item.imgurl,
|
|
|
|
b: common_vendor.t(item.name),
|
2024-11-03 23:34:53 +00:00
|
|
|
c: index,
|
|
|
|
d: common_vendor.s(getBoxStyle(index)),
|
|
|
|
e: common_vendor.o(($event) => changeTypes(item, index), index)
|
2024-10-17 05:04:16 +00:00
|
|
|
};
|
|
|
|
}),
|
2024-11-03 23:34:53 +00:00
|
|
|
c: common_vendor.f(productList.value, (item, index, i0) => {
|
2024-10-17 05:04:16 +00:00
|
|
|
return {
|
2024-11-03 23:34:53 +00:00
|
|
|
a: item.goodImg,
|
|
|
|
b: common_vendor.t(item.name),
|
|
|
|
c: common_vendor.t(item.intro),
|
|
|
|
d: common_vendor.t(item.price),
|
2024-10-18 05:56:23 +00:00
|
|
|
e: index,
|
2024-11-03 23:34:53 +00:00
|
|
|
f: common_vendor.o(($event) => goToProduct(item), index)
|
2024-10-17 05:04:16 +00:00
|
|
|
};
|
2024-10-18 05:56:23 +00:00
|
|
|
}),
|
2024-10-18 16:55:25 +00:00
|
|
|
d: common_vendor.unref(common_assets.add_img)
|
2024-10-17 05:04:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2024-11-06 12:46:53 +00:00
|
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7e3c386d"]]);
|
2024-10-17 05:04:16 +00:00
|
|
|
wx.createPage(MiniProgramPage);
|