index.js 14 KB

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