detail-navbar.js 8.1 KB

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