JewelryMall/miniprogram/unpackage/dist/dev/mp-weixin/pages/search/index.js
2026-03-02 23:41:58 +08:00

111 lines
4.1 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");
const pageSize = 20;
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
setup(__props) {
const keyword = common_vendor.ref("");
const products = common_vendor.ref([]);
const loading = common_vendor.ref(false);
const total = common_vendor.ref(0);
const page = common_vendor.ref(1);
const noMore = common_vendor.ref(false);
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 goBack() {
common_vendor.index.navigateBack({ delta: 1 });
}
function fullUrl(path) {
if (!path)
return "";
if (path.startsWith("http"))
return path;
return utils_request.BASE_URL + path;
}
function goDetail(id) {
common_vendor.index.navigateTo({ url: `/pages/product/detail?id=${id}` });
}
async function search(reset = false) {
if (reset) {
page.value = 1;
products.value = [];
}
loading.value = true;
try {
const data = await api_product.getProducts({ page: page.value, pageSize, keyword: keyword.value });
if (reset) {
products.value = data.list;
} else {
products.value.push(...data.list);
}
total.value = data.total || data.list.length;
noMore.value = data.list.length < pageSize;
} catch {
common_vendor.index.showToast({ title: "搜索失败", icon: "none" });
} finally {
loading.value = false;
}
}
common_vendor.onMounted(() => {
var _a;
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
keyword.value = decodeURIComponent(((_a = currentPage.options) == null ? void 0 : _a.keyword) || "");
if (keyword.value)
search(true);
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_assets._imports_0$2,
b: common_vendor.o(goBack),
c: common_vendor.t(keyword.value),
d: navBarHeight.value + "px",
e: statusBarHeight.value + "px",
f: statusBarHeight.value + navBarHeight.value + "px",
g: !loading.value && products.value.length > 0
}, !loading.value && products.value.length > 0 ? {
h: common_vendor.t(total.value)
} : {}, {
i: common_vendor.f(products.value, (item, k0, i0) => {
return common_vendor.e({
a: fullUrl(item.thumb || item.bannerImages && item.bannerImages[0] || ""),
b: common_vendor.t(item.name),
c: item.styleNo
}, item.styleNo ? {
d: common_vendor.t(item.styleNo)
} : {}, {
e: item.barcode
}, item.barcode ? {
f: common_vendor.t(item.barcode)
} : {}, {
g: common_vendor.t(item.basePrice),
h: common_vendor.t(item.stock || 1),
i: item.id,
j: common_vendor.o(($event) => goDetail(item.id), item.id)
});
}),
j: loading.value
}, loading.value ? {} : {}, {
k: !loading.value && noMore.value && products.value.length > 0
}, !loading.value && noMore.value && products.value.length > 0 ? {} : {}, {
l: !loading.value && products.value.length === 0
}, !loading.value && products.value.length === 0 ? {
m: common_assets._imports_1$3
} : {});
};
}
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2dab939d"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/search/index.js.map