detail-navbar.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const sheep_index = require("../../../../sheep/index.js");
  4. const sheep_helper_throttle = require("../../../../sheep/helper/throttle.js");
  5. const sheep_hooks_useModal = require("../../../../sheep/hooks/useModal.js");
  6. const sheep_api_product_favorite = require("../../../../sheep/api/product/favorite.js");
  7. require("../../../../sheep/api/index.js");
  8. require("../../../../sheep/api/distri/score.js");
  9. require("../../../../sheep/request/index.js");
  10. require("../../../../sheep/config/index.js");
  11. require("../../../../sheep/store/index.js");
  12. require("../../../../sheep/store/app.js");
  13. require("../../../../sheep/api/promotion/diy.js");
  14. require("../../../../sheep/platform/index.js");
  15. require("../../../../sheep/platform/provider/wechat/index.js");
  16. require("../../../../sheep/platform/provider/wechat/miniProgram.js");
  17. require("../../../../sheep/api/member/auth.js");
  18. require("../../../../sheep/api/member/social.js");
  19. require("../../../../sheep/api/member/user.js");
  20. require("../../../../sheep/platform/provider/apple/index.js");
  21. require("../../../../sheep/platform/share.js");
  22. require("../../../../sheep/router/index.js");
  23. require("../../../../sheep/url/index.js");
  24. require("../../../../sheep/platform/pay.js");
  25. require("../../../../sheep/helper/index.js");
  26. require("../../../../sheep/helper/test.js");
  27. require("../../../../sheep/helper/digit.js");
  28. require("../../../../sheep/api/pay/order.js");
  29. require("../../../../sheep/store/user.js");
  30. require("../../../../sheep/store/cart.js");
  31. require("../../../../sheep/api/trade/cart.js");
  32. require("../../../../sheep/api/pay/wallet.js");
  33. require("../../../../sheep/api/trade/order.js");
  34. require("../../../../sheep/api/promotion/coupon.js");
  35. require("../../../../sheep/store/sys.js");
  36. require("../../../../sheep/store/modal.js");
  37. require("../../../../sheep/api/distri/share.js");
  38. require("../../../../sheep/api/distri/team.js");
  39. require("../../../../sheep/api/infra/file.js");
  40. require("../../../../sheep/api/member/address.js");
  41. require("../../../../sheep/api/member/point.js");
  42. require("../../../../sheep/api/member/signin.js");
  43. require("../../../../sheep/api/migration/app.js");
  44. require("../../../../sheep/api/migration/chat.js");
  45. require("../../../../sheep/api/migration/index.js");
  46. require("../../../../sheep/api/migration/third.js");
  47. require("../../../../sheep/api/pay/channel.js");
  48. require("../../../../sheep/api/product/category.js");
  49. require("../../../../sheep/api/product/comment.js");
  50. require("../../../../sheep/api/product/history.js");
  51. require("../../../../sheep/api/product/spu.js");
  52. require("../../../../sheep/api/promotion/activity.js");
  53. require("../../../../sheep/api/promotion/article.js");
  54. require("../../../../sheep/api/promotion/bargain.js");
  55. require("../../../../sheep/api/promotion/combination.js");
  56. require("../../../../sheep/api/promotion/rewardActivity.js");
  57. require("../../../../sheep/api/promotion/seckill.js");
  58. require("../../../../sheep/api/system/area.js");
  59. require("../../../../sheep/api/system/voice.js");
  60. require("../../../../sheep/api/trade/afterSale.js");
  61. require("../../../../sheep/api/trade/brokerage.js");
  62. require("../../../../sheep/api/trade/config.js");
  63. require("../../../../sheep/api/trade/delivery.js");
  64. require("../../../../sheep/config/zIndex.js");
  65. if (!Array) {
  66. const _easycom_su_status_bar2 = common_vendor.resolveComponent("su-status-bar");
  67. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  68. (_easycom_su_status_bar2 + _easycom_su_fixed2)();
  69. }
  70. const _easycom_su_status_bar = () => "../../../../sheep/ui/su-status-bar/su-status-bar.js";
  71. const _easycom_su_fixed = () => "../../../../sheep/ui/su-fixed/su-fixed.js";
  72. if (!Math) {
  73. (_easycom_su_status_bar + _easycom_su_fixed)();
  74. }
  75. const _sfc_main = {
  76. __name: "detail-navbar",
  77. props: {
  78. modelValue: {
  79. type: Object,
  80. default() {
  81. }
  82. },
  83. collectIcon: {
  84. type: Boolean,
  85. default: true
  86. },
  87. shareIcon: {
  88. type: Boolean,
  89. default: true
  90. }
  91. },
  92. emits: ["clickLeft"],
  93. setup(__props, { emit: __emit }) {
  94. const isLogin = common_vendor.computed(() => sheep_index.sheep.$store("user").isLogin);
  95. const sys_statusBar = sheep_index.sheep.$platform.device.statusBarHeight;
  96. const sys_navBar = sheep_index.sheep.$platform.navbar;
  97. const capsuleStyle = {
  98. width: sheep_index.sheep.$platform.capsule.width + "px",
  99. height: sheep_index.sheep.$platform.capsule.height + "px"
  100. };
  101. const state = common_vendor.reactive({
  102. tabOpacityVal: 0,
  103. curTab: "goods",
  104. tabList: [
  105. {
  106. label: "商品",
  107. value: "goods",
  108. to: "detail-swiper-selector"
  109. },
  110. {
  111. label: "评价",
  112. value: "comment",
  113. to: "detail-comment-selector"
  114. },
  115. {
  116. label: "详情",
  117. value: "detail",
  118. to: "detail-content-selector"
  119. }
  120. ]
  121. });
  122. const props = __props;
  123. const emits = __emit;
  124. const hasHistory = sheep_index.sheep.$router.hasHistory();
  125. function onClickLeft() {
  126. if (hasHistory) {
  127. sheep_index.sheep.$router.back();
  128. } else {
  129. sheep_index.sheep.$router.go("/pages/index/index");
  130. }
  131. emits("clickLeft");
  132. }
  133. function onClickRight() {
  134. sheep_hooks_useModal.showMenuTools();
  135. }
  136. let commentCard = {
  137. top: 0,
  138. bottom: 0
  139. };
  140. function getCommentCardNode() {
  141. return new Promise((res, rej) => {
  142. common_vendor.index.createSelectorQuery().select(".detail-comment-selector").boundingClientRect((data) => {
  143. if (data) {
  144. commentCard.top = data.top;
  145. commentCard.bottom = data.top + data.height;
  146. res(data);
  147. } else {
  148. res(null);
  149. }
  150. }).exec();
  151. });
  152. }
  153. function onTab(tab) {
  154. let scrollTop = 0;
  155. if (tab.value === "comment") {
  156. scrollTop = commentCard.top - sys_navBar + 1;
  157. } else if (tab.value === "detail") {
  158. scrollTop = commentCard.bottom - sys_navBar + 1;
  159. }
  160. common_vendor.index.pageScrollTo({
  161. scrollTop,
  162. duration: 200
  163. });
  164. }
  165. async function onFavorite() {
  166. if (!isLogin.value) {
  167. sheep_hooks_useModal.showAuthModal();
  168. return;
  169. }
  170. if (props.modelValue.favorite) {
  171. const {
  172. code
  173. } = await sheep_api_product_favorite.FavoriteApi.deleteFavorite(props.modelValue.id);
  174. if (code !== 0) {
  175. return;
  176. }
  177. sheep_index.sheep.$helper.toast("取消收藏");
  178. props.modelValue.favorite = false;
  179. } else {
  180. const {
  181. code
  182. } = await sheep_api_product_favorite.FavoriteApi.createFavorite(props.modelValue.id);
  183. await sheep_api_product_favorite.FavoriteApi.createCollectBefore(props.modelValue.id);
  184. if (code !== 0) {
  185. return;
  186. }
  187. sheep_index.sheep.$helper.toast("收藏成功");
  188. props.modelValue.favorite = true;
  189. }
  190. }
  191. common_vendor.onPageScroll((e) => {
  192. state.tabOpacityVal = e.scrollTop > sheep_index.sheep.$platform.navbar ? 1 : e.scrollTop * 0.01;
  193. if (commentCard.top === 0) {
  194. sheep_helper_throttle.throttle(() => {
  195. getCommentCardNode();
  196. }, 50);
  197. }
  198. if (e.scrollTop < commentCard.top - sys_navBar) {
  199. state.curTab = "goods";
  200. } else if (e.scrollTop >= commentCard.top - sys_navBar && e.scrollTop <= commentCard.bottom - sys_navBar) {
  201. state.curTab = "comment";
  202. } else {
  203. state.curTab = "detail";
  204. }
  205. });
  206. return (_ctx, _cache) => {
  207. return common_vendor.e({
  208. a: common_vendor.unref(hasHistory)
  209. }, common_vendor.unref(hasHistory) ? {} : {}, {
  210. b: common_vendor.o(onClickLeft),
  211. c: common_vendor.o(onClickRight),
  212. d: common_vendor.f(state.tabList, (item, k0, i0) => {
  213. return {
  214. a: common_vendor.t(item.label),
  215. b: common_vendor.n(state.curTab === item.value ? "cur-tab-title" : ""),
  216. c: state.curTab === item.value,
  217. d: item.value,
  218. e: common_vendor.o(($event) => onTab(item), item.value)
  219. };
  220. }),
  221. e: common_vendor.s({
  222. opacity: state.tabOpacityVal
  223. }),
  224. f: __props.collectIcon
  225. }, __props.collectIcon ? common_vendor.e({
  226. g: __props.modelValue.favorite
  227. }, __props.modelValue.favorite ? {
  228. h: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/collect_1.gif")
  229. } : {
  230. i: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/collect_0.png")
  231. }, {
  232. j: common_vendor.o(onFavorite)
  233. }) : {}, {
  234. k: __props.shareIcon
  235. }, __props.shareIcon ? {
  236. l: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/share.png"),
  237. m: common_vendor.o(($event) => common_vendor.unref(sheep_hooks_useModal.showShareModal)(__props.modelValue.id))
  238. } : {}, {
  239. n: common_vendor.s({
  240. opacity: state.tabOpacityVal
  241. }),
  242. o: common_vendor.s(capsuleStyle),
  243. p: common_vendor.s({
  244. height: common_vendor.unref(sys_navBar) - common_vendor.unref(sys_statusBar) + "px"
  245. }),
  246. q: common_vendor.p({
  247. alway: true,
  248. bgStyles: {
  249. background: "#fff"
  250. },
  251. val: 0,
  252. noNav: true,
  253. opacity: true,
  254. placeholder: false
  255. })
  256. });
  257. };
  258. }
  259. };
  260. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3e9ea950"], ["__file", "D:/zx/mall-front-app/pages/goods/components/detail/detail-navbar.vue"]]);
  261. wx.createComponent(Component);