index.js 12 KB

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