136 lines
4.7 KiB
JavaScript
136 lines
4.7 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const api_product = require("../../api/product.js");
|
|
const utils_request = require("../../utils/request.js");
|
|
if (!Math) {
|
|
(ProductCard + CustomerServiceBtn)();
|
|
}
|
|
const ProductCard = () => "../../components/ProductCard.js";
|
|
const CustomerServiceBtn = () => "../../components/CustomerServiceBtn.js";
|
|
const pageSize = 20;
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "index",
|
|
setup(__props) {
|
|
const products = common_vendor.ref([]);
|
|
const categories = common_vendor.ref([]);
|
|
const activeCategoryId = common_vendor.ref(void 0);
|
|
const loading = common_vendor.ref(false);
|
|
const showQrcode = common_vendor.ref(false);
|
|
const page = common_vendor.ref(1);
|
|
const keyword = common_vendor.ref("");
|
|
const statusBarHeight = common_vendor.ref(20);
|
|
const navBarHeight = common_vendor.ref(44);
|
|
try {
|
|
const sysInfo = common_vendor.index.getSystemInfoSync();
|
|
statusBarHeight.value = sysInfo.statusBarHeight || 20;
|
|
const menuBtn = common_vendor.index.getMenuButtonBoundingClientRect();
|
|
navBarHeight.value = (menuBtn.top - (sysInfo.statusBarHeight || 20)) * 2 + menuBtn.height;
|
|
} catch {
|
|
}
|
|
function fullUrl(path) {
|
|
if (!path)
|
|
return "";
|
|
if (path.startsWith("http"))
|
|
return path;
|
|
return utils_request.BASE_URL + path;
|
|
}
|
|
async function loadCategories() {
|
|
try {
|
|
const data = await api_product.getCategories();
|
|
categories.value = data;
|
|
} catch {
|
|
}
|
|
}
|
|
async function loadProducts(reset = false) {
|
|
if (reset) {
|
|
page.value = 1;
|
|
products.value = [];
|
|
}
|
|
loading.value = true;
|
|
try {
|
|
const params = { page: page.value, pageSize };
|
|
if (activeCategoryId.value)
|
|
params.categoryId = activeCategoryId.value;
|
|
if (keyword.value)
|
|
params.keyword = keyword.value;
|
|
const data = await api_product.getProducts(params);
|
|
if (reset) {
|
|
products.value = data.list;
|
|
} else {
|
|
products.value.push(...data.list);
|
|
}
|
|
} catch {
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
function selectCategory(id) {
|
|
const cat = categories.value.find((c) => c.id === id);
|
|
const name = cat ? encodeURIComponent(cat.name) : "";
|
|
common_vendor.index.navigateTo({ url: `/pages/category/index?id=${id}&name=${name}` });
|
|
}
|
|
function goSearch() {
|
|
if (!keyword.value.trim())
|
|
return;
|
|
common_vendor.index.navigateTo({ url: `/pages/search/index?keyword=${encodeURIComponent(keyword.value.trim())}` });
|
|
}
|
|
function goCalculator() {
|
|
common_vendor.index.navigateTo({ url: "/pages/calculator/index" });
|
|
}
|
|
common_vendor.onMounted(() => {
|
|
loadCategories();
|
|
loadProducts(true);
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: navBarHeight.value + "px",
|
|
b: statusBarHeight.value + "px",
|
|
c: common_assets._imports_0,
|
|
d: keyword.value,
|
|
e: common_vendor.o((e) => keyword.value = e.detail.value),
|
|
f: common_vendor.o(goSearch),
|
|
g: common_vendor.o(goSearch),
|
|
h: common_vendor.f(categories.value, (cat, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: cat.icon
|
|
}, cat.icon ? {
|
|
b: fullUrl(cat.icon)
|
|
} : {}, {
|
|
c: common_vendor.t(cat.name),
|
|
d: cat.id,
|
|
e: activeCategoryId.value === cat.id ? 1 : "",
|
|
f: common_vendor.o(($event) => selectCategory(cat.id), cat.id)
|
|
});
|
|
}),
|
|
i: common_assets._imports_1,
|
|
j: common_vendor.o(goCalculator),
|
|
k: common_assets._imports_2,
|
|
l: common_vendor.o(($event) => showQrcode.value = true),
|
|
m: common_vendor.f(products.value, (product, k0, i0) => {
|
|
return {
|
|
a: "1cf27b2a-0-" + i0,
|
|
b: common_vendor.p({
|
|
product
|
|
}),
|
|
c: product.id
|
|
};
|
|
}),
|
|
n: !loading.value && products.value.length === 0
|
|
}, !loading.value && products.value.length === 0 ? {} : {}, {
|
|
o: loading.value
|
|
}, loading.value ? {} : {}, {
|
|
p: showQrcode.value
|
|
}, showQrcode.value ? {
|
|
q: common_vendor.o(($event) => showQrcode.value = false),
|
|
r: common_vendor.p({
|
|
mode: "qrcode"
|
|
})
|
|
} : {});
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map
|