index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const sheep_index = require("../../sheep/index.js");
  5. require("../../sheep/request/index.js");
  6. const sheep_api_promotion_activity = require("../../sheep/api/promotion/activity.js");
  7. const sheep_api_product_favorite = require("../../sheep/api/product/favorite.js");
  8. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  9. const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
  10. const sheep_api_distri_share = require("../../sheep/api/distri/share.js");
  11. const sheep_hooks_useModal = require("../../sheep/hooks/useModal.js");
  12. require("../../sheep/url/index.js");
  13. require("../../sheep/store/index.js");
  14. require("../../sheep/store/app.js");
  15. require("../../sheep/api/promotion/diy.js");
  16. require("../../sheep/platform/index.js");
  17. require("../../sheep/platform/provider/wechat/index.js");
  18. require("../../sheep/platform/provider/wechat/miniProgram.js");
  19. require("../../sheep/api/member/auth.js");
  20. require("../../sheep/api/member/social.js");
  21. require("../../sheep/api/member/user.js");
  22. require("../../sheep/platform/provider/apple/index.js");
  23. require("../../sheep/platform/share.js");
  24. require("../../sheep/router/index.js");
  25. require("../../sheep/helper/throttle.js");
  26. require("../../sheep/platform/pay.js");
  27. require("../../sheep/helper/index.js");
  28. require("../../sheep/helper/test.js");
  29. require("../../sheep/helper/digit.js");
  30. require("../../sheep/api/pay/order.js");
  31. require("../../sheep/store/user.js");
  32. require("../../sheep/store/cart.js");
  33. require("../../sheep/api/trade/cart.js");
  34. require("../../sheep/api/pay/wallet.js");
  35. require("../../sheep/api/trade/order.js");
  36. require("../../sheep/api/promotion/coupon.js");
  37. require("../../sheep/store/sys.js");
  38. require("../../sheep/store/modal.js");
  39. require("../../sheep/config/index.js");
  40. require("../../sheep/config/zIndex.js");
  41. require("../../sheep/util/index.js");
  42. require("../../sheep/api/member/signin.js");
  43. if (!Array) {
  44. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  45. const _easycom_su_swiper2 = common_vendor.resolveComponent("su-swiper");
  46. const _easycom_s_select_sku2 = common_vendor.resolveComponent("s-select-sku");
  47. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  48. (_easycom_s_empty2 + _easycom_su_swiper2 + _easycom_s_select_sku2 + _easycom_s_layout2)();
  49. }
  50. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  51. const _easycom_su_swiper = () => "../../sheep/ui/su-swiper/su-swiper.js";
  52. const _easycom_s_select_sku = () => "../../sheep/components/s-select-sku/s-select-sku.js";
  53. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  54. if (!Math) {
  55. (detailNavbar + detailSkeleton + _easycom_s_empty + _easycom_su_swiper + detailCellSku + _easycom_s_select_sku + detailCommentCard + detailContentCard + detailTabbar + _easycom_s_layout)();
  56. }
  57. const detailNavbar = () => "./components/detail/detail-navbar.js";
  58. const detailCellSku = () => "./components/detail/detail-cell-sku.js";
  59. const detailTabbar = () => "./components/detail/detail-tabbar.js";
  60. const detailSkeleton = () => "./components/detail/detail-skeleton.js";
  61. const detailCommentCard = () => "./components/detail/detail-comment-card.js";
  62. const detailContentCard = () => "./components/detail/detail-content-card.js";
  63. const _sfc_main = {
  64. __name: "index",
  65. setup(__props) {
  66. common_vendor.onPageScroll(() => {
  67. });
  68. const state = common_vendor.reactive({
  69. goodsId: 0,
  70. skeletonLoading: true,
  71. // SPU 加载中
  72. goodsInfo: {},
  73. // SPU 信息
  74. showSelectSku: false,
  75. // 是否展示 SKU 选择弹窗
  76. selectedSku: {},
  77. // 选中的 SKU
  78. showModel: false,
  79. // 是否展示 Coupon 优惠劵的弹窗
  80. couponInfo: [],
  81. // 可领取的 Coupon 优惠劵的列表
  82. showActivityModel: false,
  83. // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  84. activityInfo: [],
  85. // 【满减送/限时折扣】可参与的 Activity 营销活动的列表
  86. activityList: [],
  87. // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  88. linkId: 0
  89. // 分享时的id
  90. });
  91. function onSkuChange(e) {
  92. state.selectedSku = e;
  93. }
  94. function onAddCart(e) {
  95. if (!e.id) {
  96. sheep_index.sheep.$helper.toast("请选择商品规格");
  97. return;
  98. }
  99. if (!isLogin.value) {
  100. sheep_hooks_useModal.showAuthModal();
  101. return;
  102. }
  103. sheep_index.sheep.$store("cart").add(e);
  104. }
  105. function onBuy(e) {
  106. if (!state.selectedSku.id) {
  107. sheep_index.sheep.$helper.toast("请选择商品规格");
  108. return;
  109. }
  110. sheep_index.sheep.$router.go("/pages/order/confirm", {
  111. data: JSON.stringify({
  112. items: [{
  113. skuId: e.id,
  114. count: e.goods_num
  115. }],
  116. spuType: state.goodsInfo.spuType,
  117. spuPayType: state.goodsInfo.spuPayType,
  118. highPrecision: state.goodsInfo.highPrecision,
  119. // TODO 芋艿:后续清理掉这 2 参数
  120. deliveryType: 1,
  121. pointStatus: false
  122. })
  123. });
  124. }
  125. function onActivity() {
  126. state.showActivityModel = true;
  127. }
  128. const shareInfo = common_vendor.computed(() => {
  129. if (common_vendor.lodashExports.isEmpty(state.goodsInfo))
  130. return {};
  131. return sheep_index.sheep.$platform.share.getShareInfo({
  132. title: state.goodsInfo.name,
  133. image: sheep_index.sheep.$url.cdn(state.goodsInfo.image),
  134. desc: state.goodsInfo.subtitle,
  135. params: {
  136. page: "2"
  137. // query: state.linkId,
  138. }
  139. }, {
  140. type: "goods",
  141. // 商品海报
  142. title: state.goodsInfo.name,
  143. // 商品标题
  144. introduction: state.goodsInfo.introduction,
  145. // image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  146. image: sheep_index.sheep.$url.cdn(state.goodsInfo.picUrl),
  147. // 商品主图
  148. price: sheep_hooks_useGoods.fen2yuan(state.goodsInfo.price),
  149. // 商品价格
  150. original_price: sheep_hooks_useGoods.fen2yuan(state.goodsInfo.maretPrice)
  151. // 商品原价
  152. });
  153. });
  154. async function getSpuDetail(id) {
  155. sheep_api_product_spu.SpuApi.getSpuDetail(id).then((res) => {
  156. if (res.code !== 0 || !res.data) {
  157. state.goodsInfo = null;
  158. return;
  159. }
  160. state.skeletonLoading = false;
  161. state.goodsInfo = res.data;
  162. console.log(state.goodsInfo);
  163. if (!isLogin.value) {
  164. return;
  165. }
  166. sheep_api_product_favorite.FavoriteApi.isFavoriteExists(state.goodsId, "goods").then((res2) => {
  167. if (res2.code !== 0) {
  168. return;
  169. }
  170. state.goodsInfo.favorite = res2.data;
  171. });
  172. });
  173. }
  174. async function getLink() {
  175. sheep_api_distri_share.ShareApi.getLinkId(3, state.goodsId).then((res) => {
  176. if (res.code !== 0) {
  177. return;
  178. }
  179. state.linkId = res.data.linkId;
  180. });
  181. }
  182. const isLogin = common_vendor.computed(() => sheep_index.sheep.$store("user").isLogin);
  183. common_vendor.watch(() => isLogin.value, (newVal) => {
  184. if (newVal) {
  185. getSpuDetail(state.goodsId);
  186. }
  187. });
  188. common_vendor.onLoad((options) => {
  189. if (!options.id && !options.linkId) {
  190. state.goodsInfo = null;
  191. return;
  192. }
  193. state.goodsId = options.id || 0;
  194. if (!options.id && options.linkId) {
  195. console.log("如果只是没有spuId有linkId的话 要去linkId对应的spuId");
  196. const linkId = options.linkId.toString();
  197. sheep_api_distri_share.ShareApi.getObjectIdByLinkId(linkId).then((res) => {
  198. if (res.code !== 0) {
  199. return;
  200. }
  201. state.goodsId = res.data;
  202. getSpuDetail(state.goodsId);
  203. getLink();
  204. });
  205. common_vendor.index.setStorageSync("linkId", options.linkId);
  206. } else {
  207. getSpuDetail(state.goodsId);
  208. }
  209. sheep_api_promotion_activity.ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  210. if (res.code !== 0) {
  211. return;
  212. }
  213. res.data.forEach((activity) => {
  214. if ([1, 2, 3].includes(activity.type)) {
  215. state.activityList.push(activity);
  216. } else if (activity.type === 5) {
  217. state.activityInfo.push(activity);
  218. } else {
  219. console.log("待实现!优先级不高");
  220. }
  221. });
  222. });
  223. });
  224. return (_ctx, _cache) => {
  225. return common_vendor.e({
  226. a: common_vendor.o(($event) => state.goodsInfo = $event),
  227. b: common_vendor.p({
  228. modelValue: state.goodsInfo
  229. }),
  230. c: state.skeletonLoading
  231. }, state.skeletonLoading ? {} : state.goodsInfo === null ? {
  232. e: common_vendor.p({
  233. text: "商品不存在或已下架",
  234. icon: "/static/soldout-empty.png",
  235. showAction: true,
  236. actionText: "再逛逛",
  237. actionUrl: "/pages/goods/list"
  238. })
  239. } : common_vendor.e({
  240. f: common_vendor.p({
  241. isPreview: true,
  242. list: common_vendor.unref(sheep_hooks_useGoods.formatGoodsSwiper)(state.goodsInfo.sliderPicUrls),
  243. otStyle: "tag",
  244. imageMode: "widthFix",
  245. dotCur: "bg-mask-40",
  246. seizeHeight: 750
  247. }),
  248. g: state.goodsInfo.spuPayType == 2
  249. }, state.goodsInfo.spuPayType == 2 ? {
  250. h: common_assets._imports_0
  251. } : {}, {
  252. i: state.goodsInfo.highPrecision
  253. }, state.goodsInfo.highPrecision ? {
  254. j: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan6)(state.selectedSku.highPrecisionPrice || state.goodsInfo.highPrecisionPrice))
  255. } : {
  256. k: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.price || state.goodsInfo.price))
  257. }, {
  258. l: state.goodsInfo.promotionFee >= 0
  259. }, state.goodsInfo.promotionFee >= 0 ? {
  260. m: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.promotionFee || state.goodsInfo.promotionFee))
  261. } : {}, {
  262. n: common_vendor.f(state.activityInfo, (promos, k0, i0) => {
  263. return {
  264. a: common_vendor.t(promos.name),
  265. b: promos.id,
  266. c: common_vendor.o(onActivity, promos.id)
  267. };
  268. }),
  269. o: state.couponInfo.length
  270. }, state.couponInfo.length ? {
  271. p: common_vendor.o(($event) => state.showModel = true)
  272. } : {}, {
  273. q: common_vendor.t(state.goodsInfo.name),
  274. r: common_vendor.t(state.goodsInfo.introduction),
  275. s: common_vendor.o(($event) => state.showSelectSku = true),
  276. t: common_vendor.o(($event) => state.selectedSku.goods_sku_text = $event),
  277. v: common_vendor.p({
  278. sku: state.selectedSku,
  279. modelValue: state.selectedSku.goods_sku_text
  280. }),
  281. w: common_vendor.o(onAddCart),
  282. x: common_vendor.o(onBuy),
  283. y: common_vendor.o(onSkuChange),
  284. z: common_vendor.o(($event) => state.showSelectSku = false),
  285. A: common_vendor.p({
  286. goodsInfo: state.goodsInfo,
  287. show: state.showSelectSku
  288. }),
  289. B: common_vendor.p({
  290. goodsId: state.goodsId
  291. }),
  292. C: common_vendor.p({
  293. content: state.goodsInfo.description
  294. }),
  295. D: state.goodsInfo.stock > 0 && state.goodsInfo.spuType && state.goodsInfo.spuPayType == 1
  296. }, state.goodsInfo.stock > 0 && state.goodsInfo.spuType && state.goodsInfo.spuPayType == 1 ? {
  297. E: common_vendor.o(($event) => state.showSelectSku = true),
  298. F: common_vendor.o(($event) => state.showSelectSku = true)
  299. } : state.goodsInfo.stock > 0 && state.goodsInfo.spuPayType != 1 || !state.goodsInfo.spuType ? common_vendor.e({
  300. H: state.goodsInfo.spuPayType != 1 && !state.goodsInfo.spuType
  301. }, state.goodsInfo.spuPayType != 1 && !state.goodsInfo.spuType ? {} : !state.goodsInfo.spuType ? {} : {}, {
  302. I: !state.goodsInfo.spuType,
  303. J: common_vendor.o(($event) => state.showSelectSku = true)
  304. }) : {}, {
  305. G: state.goodsInfo.stock > 0 && state.goodsInfo.spuPayType != 1 || !state.goodsInfo.spuType,
  306. K: common_vendor.o(($event) => state.goodsInfo = $event),
  307. L: common_vendor.p({
  308. modelValue: state.goodsInfo
  309. })
  310. }), {
  311. d: state.goodsInfo === null,
  312. M: common_vendor.p({
  313. onShareAppMessage: shareInfo.value,
  314. navbar: "goods"
  315. })
  316. });
  317. };
  318. }
  319. };
  320. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-24a31e85"], ["__file", "D:/zx/mall-front-app/pages/goods/index.vue"]]);
  321. _sfc_main.__runtimeHooks = 3;
  322. wx.createPage(MiniProgramPage);