acdr-ui/dist/dev/mp-weixin/modules/mall/goods/components/detail/detail-navbar.js

142 lines
4.7 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
const common_vendor = require("../../../../../common/vendor.js");
2024-10-01 09:15:35 +08:00
const modules_mall_sheep_index = require("../../../sheep/index.js");
const modules_mall_sheep_helper_throttle = require("../../../sheep/helper/throttle.js");
const modules_mall_sheep_hooks_useModal = require("../../../sheep/hooks/useModal.js");
2024-09-19 07:20:14 +08:00
if (!Array) {
const _easycom_su_status_bar2 = common_vendor.resolveComponent("su-status-bar");
const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
(_easycom_su_status_bar2 + _easycom_su_fixed2)();
}
2024-10-01 09:15:35 +08:00
const _easycom_su_status_bar = () => "../../../sheep/ui/su-status-bar/su-status-bar.js";
const _easycom_su_fixed = () => "../../../sheep/ui/su-fixed/su-fixed.js";
2024-09-19 07:20:14 +08:00
if (!Math) {
(_easycom_su_status_bar + _easycom_su_fixed)();
}
const _sfc_main = {
__name: "detail-navbar",
emits: ["clickLeft"],
setup(__props, { emit: __emit }) {
2024-10-01 09:15:35 +08:00
const sys_statusBar = modules_mall_sheep_index.sheep.$platform.device.statusBarHeight;
const sys_navBar = modules_mall_sheep_index.sheep.$platform.navbar;
2024-09-19 07:20:14 +08:00
const capsuleStyle = {
2024-10-01 09:15:35 +08:00
width: modules_mall_sheep_index.sheep.$platform.capsule.width + "px",
height: modules_mall_sheep_index.sheep.$platform.capsule.height + "px"
2024-09-19 07:20:14 +08:00
};
const state = common_vendor.reactive({
tabOpacityVal: 0,
curTab: "goods",
tabList: [
{
label: "商品",
value: "goods",
to: "detail-swiper-selector"
},
{
label: "评价",
value: "comment",
to: "detail-comment-selector"
},
{
label: "详情",
value: "detail",
to: "detail-content-selector"
}
]
});
const emits = __emit;
2024-10-01 09:15:35 +08:00
const hasHistory = modules_mall_sheep_index.sheep.$router.hasHistory();
2024-09-19 07:20:14 +08:00
function onClickLeft() {
if (hasHistory) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$router.back();
2024-09-19 07:20:14 +08:00
} else {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$router.go("/modules/mall/index/index");
2024-09-19 07:20:14 +08:00
}
emits("clickLeft");
}
function onClickRight() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_hooks_useModal.showMenuTools();
2024-09-19 07:20:14 +08:00
}
const commentCard = {
top: 0,
bottom: 0
};
function getCommentCardNode() {
return new Promise((res, rej) => {
common_vendor.index.createSelectorQuery().select(".detail-comment-selector").boundingClientRect((data) => {
if (data) {
commentCard.top = data.top;
commentCard.bottom = data.top + data.height;
res(data);
} else {
res(null);
}
}).exec();
});
}
function onTab(tab) {
let scrollTop = 0;
if (tab.value === "comment") {
scrollTop = commentCard.top - sys_navBar + 1;
} else if (tab.value === "detail") {
scrollTop = commentCard.bottom - sys_navBar + 1;
}
common_vendor.index.pageScrollTo({
scrollTop,
duration: 200
});
}
common_vendor.onPageScroll((e) => {
2024-10-01 09:15:35 +08:00
state.tabOpacityVal = e.scrollTop > modules_mall_sheep_index.sheep.$platform.navbar ? 1 : e.scrollTop * 0.01;
2024-09-19 07:20:14 +08:00
if (commentCard.top === 0) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_helper_throttle.throttle(() => {
2024-09-19 07:20:14 +08:00
getCommentCardNode();
}, 50);
}
if (e.scrollTop < commentCard.top - sys_navBar) {
state.curTab = "goods";
} else if (e.scrollTop >= commentCard.top - sys_navBar && e.scrollTop <= commentCard.bottom - sys_navBar) {
state.curTab = "comment";
} else {
state.curTab = "detail";
}
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(hasHistory)
}, common_vendor.unref(hasHistory) ? {} : {}, {
b: common_vendor.o(onClickLeft),
c: common_vendor.o(onClickRight),
d: common_vendor.f(state.tabList, (item, k0, i0) => {
return {
a: common_vendor.t(item.label),
b: common_vendor.n(state.curTab === item.value ? "cur-tab-title" : ""),
c: state.curTab === item.value,
d: item.value,
e: common_vendor.o(($event) => onTab(item), item.value)
};
}),
e: common_vendor.s({
opacity: state.tabOpacityVal
}),
f: common_vendor.s(capsuleStyle),
g: common_vendor.s({
height: common_vendor.unref(sys_navBar) - common_vendor.unref(sys_statusBar) + "px"
}),
h: common_vendor.p({
alway: true,
bgStyles: {
background: "#fff"
},
val: 0,
noNav: true,
opacity: true,
placeholder: false
})
});
};
}
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4fad1276"]]);
wx.createComponent(Component);