index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view>
  3. <s-layout :onShareAppMessage="shareInfo" navbar="goods">
  4. <!-- 标题栏 -->
  5. <detailNavbar />
  6. <!-- 骨架屏 -->
  7. <detailSkeleton v-if="state.skeletonLoading" />
  8. <!-- 下架/售罄提醒 -->
  9. <s-empty v-else-if="state.goodsInfo === null" text="商品不存在或已下架" icon="/static/soldout-empty.png" showAction
  10. actionText="再逛逛" actionUrl="/pages/goods/list" />
  11. <block v-else>
  12. <view class="detail-swiper-selector">
  13. <!-- 商品轮播图 -->
  14. <su-swiper class="ss-m-b-14" isPreview :list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)"
  15. dotStyle="tag" imageMode="widthFix" dotCur="bg-mask-40" :seizeHeight="750" />
  16. <!-- 价格+标题 -->
  17. <view class="title-card detail-card ss-p-y-40 ss-p-x-20">
  18. <view class="ss-flex ss-row-between ss-col-center ss-m-b-26">
  19. <view class="price-box ss-flex ss-col-bottom">
  20. <view class="price-text ss-m-r-16">
  21. {{ fen2yuan(state.selectedSku.price || state.goodsInfo.price) }}
  22. </view>
  23. <view class="origin-price-text" v-if="state.goodsInfo.marketPrice > 0">
  24. {{ fen2yuan(state.selectedSku.marketPrice || state.goodsInfo.marketPrice) }}
  25. </view>
  26. </view>
  27. <view class="sales-text">
  28. {{ formatSales('exact', state.goodsInfo.salesCount) }}
  29. </view>
  30. </view>
  31. <view class="discounts-box ss-flex ss-row-between ss-m-b-28">
  32. <!-- 满减送/限时折扣活动的提示 TODO 芋艿:promos 未写 -->
  33. <div class="tag-content">
  34. <view class="tag-box ss-flex">
  35. <view class="tag ss-m-r-10" v-for="promos in state.goodsInfo.promos"
  36. :key="promos.id" @tap="onActivity">
  37. {{ promos.title }}
  38. </view>
  39. </view>
  40. </div>
  41. <!-- 优惠劵 -->
  42. <view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="state.showModel = true"
  43. v-if="state.couponInfo.length">
  44. <view class="discounts-title ss-m-r-8">领券</view>
  45. <text class="cicon-forward"></text>
  46. </view>
  47. </view>
  48. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name }}</view>
  49. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  50. </view>
  51. <!-- 功能卡片 -->
  52. <view class="detail-cell-card detail-card ss-flex-col">
  53. <detail-cell-sku v-model="state.selectedSku.goods_sku_text" :sku="state.selectedSku"
  54. @tap="state.showSelectSku = true" />
  55. <!-- TODO 芋艿:可能暂时不考虑使用 -->
  56. <detail-cell-service v-if="state.goodsInfo.service" v-model="state.goodsInfo.service" />
  57. <detail-cell-params v-if="state.goodsInfo.params" v-model="state.goodsInfo.params" />
  58. </view>
  59. <!-- 规格与数量弹框 -->
  60. <s-select-sku :goodsInfo="state.goodsInfo" :show="state.showSelectSku" @addCart="onAddCart"
  61. @buy="onBuy" @change="onSkuChange" @close="state.showSelectSku = false" />
  62. </view>
  63. <!-- 评价 -->
  64. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
  65. <!-- 详情 -->
  66. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  67. <!-- 活动跳转:拼团/秒杀/砍价活动 -->
  68. <detail-activity-tip v-if="state.activityList.length > 0" :activity-list="state.activityList" />
  69. <!-- 详情 tabbar -->
  70. <detail-tabbar v-model="state.goodsInfo">
  71. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-if="state.goodsInfo.stock > 0">
  72. <button class="ss-reset-button add-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
  73. 加入购物车
  74. </button>
  75. <button class="ss-reset-button buy-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
  76. 立即购买
  77. </button>
  78. </view>
  79. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-else>
  80. <button class="ss-reset-button disabled-btn" disabled> 已售罄 </button>
  81. </view>
  82. </detail-tabbar>
  83. <!-- 优惠劵弹窗 -->
  84. <s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false"
  85. @get="onGet" />
  86. <!-- 满减送/限时折扣活动弹窗 -->
  87. <s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel"
  88. @close="state.showActivityModel = false" />
  89. </block>
  90. </s-layout>
  91. </view>
  92. </template>
  93. <script setup>
  94. import {
  95. reactive,
  96. computed
  97. } from 'vue';
  98. import {
  99. onLoad,
  100. onPageScroll
  101. } from '@dcloudio/uni-app';
  102. import sheep from '@/sheep';
  103. import CouponApi from '@/sheep/api/promotion/coupon';
  104. import ActivityApi from '@/sheep/api/promotion/activity';
  105. import {
  106. formatSales,
  107. formatGoodsSwiper,
  108. fen2yuan,
  109. } from '@/sheep/hooks/useGoods';
  110. import detailNavbar from './components/detail/detail-navbar.vue';
  111. import detailCellSku from './components/detail/detail-cell-sku.vue';
  112. import detailCellService from './components/detail/detail-cell-service.vue';
  113. import detailCellParams from './components/detail/detail-cell-params.vue';
  114. import detailTabbar from './components/detail/detail-tabbar.vue';
  115. import detailSkeleton from './components/detail/detail-skeleton.vue';
  116. import detailCommentCard from './components/detail/detail-comment-card.vue';
  117. import detailContentCard from './components/detail/detail-content-card.vue';
  118. import detailActivityTip from './components/detail/detail-activity-tip.vue';
  119. import {
  120. isEmpty
  121. } from 'lodash';
  122. onPageScroll(() => {});
  123. const state = reactive({
  124. goodsId: 0,
  125. skeletonLoading: true, // SPU 加载中
  126. goodsInfo: {}, // SPU 信息
  127. showSelectSku: false, // 是否展示 SKU 选择弹窗
  128. selectedSku: {}, // 选中的 SKU
  129. showModel: false, // 是否展示 Coupon 优惠劵的弹窗
  130. couponInfo: [], // 可领取的 Coupon 优惠劵的列表
  131. showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  132. activityInfo: [], // 【满减送/限时折扣】可参与的 Activity 营销活动的列表
  133. activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  134. });
  135. // 规格变更
  136. function onSkuChange(e) {
  137. state.selectedSku = e;
  138. }
  139. // 添加购物车 TODO 芋艿:待测试
  140. function onAddCart(e) {
  141. console.log(e, '加入购物车');
  142. sheep.$store('cart').add(e);
  143. }
  144. // 立即购买 TODO 芋艿:待测试
  145. function onBuy(e) {
  146. sheep.$router.go('/pages/order/confirm', {
  147. data: JSON.stringify({
  148. order_type: 'goods',
  149. goods_list: [{
  150. goods_id: e.goods_id,
  151. goods_num: e.goods_num,
  152. goods_sku_price_id: e.id,
  153. }, ],
  154. }),
  155. });
  156. }
  157. // 营销活动 TODO 芋艿:待测试
  158. function onActivity() {
  159. state.activityInfo = state.goodsInfo.promos;
  160. state.showActivityModel = true;
  161. }
  162. // 立即领取 TODO 芋艿:待测试
  163. async function onGet(id) {
  164. const {
  165. code,
  166. msg
  167. } = await sheep.$api.coupon.get(id);
  168. if (code === 0) {
  169. uni.showToast({
  170. title: msg,
  171. });
  172. setTimeout(() => {
  173. getCoupon();
  174. }, 1000);
  175. }
  176. }
  177. // TODO 芋艿:待测试
  178. const shareInfo = computed(() => {
  179. if (isEmpty(state.goodsInfo)) return {};
  180. return sheep.$platform.share.getShareInfo({
  181. title: state.goodsInfo.name,
  182. image: sheep.$url.cdn(state.goodsInfo.image),
  183. desc: state.goodsInfo.subtitle,
  184. params: {
  185. page: '2',
  186. query: state.goodsInfo.id,
  187. },
  188. }, {
  189. type: 'goods', // 商品海报
  190. title: state.goodsInfo.name, // 商品标题
  191. image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  192. price: state.goodsInfo.price[0], // 商品价格
  193. original_price: state.goodsInfo.original_price, // 商品原价
  194. }, );
  195. });
  196. onLoad(async (options) => {
  197. // 非法参数
  198. if (!options.id) {
  199. state.goodsInfo = null;
  200. return;
  201. }
  202. state.goodsId = options.id;
  203. // 1. 加载商品信息
  204. sheep.$api.goods.detail(state.goodsId).then(async (res) => {
  205. // 未找到商品
  206. if (res.code !== 0 || !res.data) {
  207. state.goodsInfo = null;
  208. return;
  209. }
  210. // 加载到商品
  211. state.skeletonLoading = false;
  212. // 获取收藏信息
  213. let dasa = await sheep.$api.goods.exits(options.id);
  214. res.data.favorite = dasa.data;
  215. state.goodsInfo = res.data;
  216. console.log(state.goodsInfo, '商品信息');
  217. // 此处调试默认弹出可以修改为点击弹出
  218. // 2. 加载优惠劵信息
  219. CouponApi.getCouponTemplateList({
  220. price: state.goodsInfo.price,
  221. spuIds: [state.goodsInfo.id],
  222. skuIds: state.goodsInfo.skus.map(item => item.id),
  223. // 先写死
  224. categoryIds: [52]
  225. }).then((res) => {
  226. console.log(res, '优惠券信息进行对接')
  227. if (res.code !== 0) {
  228. return;
  229. }
  230. // 拦截修改数据
  231. let obj2 = {
  232. 2: '折扣',
  233. 1: '满减'
  234. }
  235. let obj = {
  236. 1: '可用',
  237. 2: '已用',
  238. 3: '过期'
  239. }
  240. let obj3 = {
  241. 1: '已领取',
  242. 2: '已使用',
  243. 3: '已过期'
  244. }
  245. res.data = res.data.map(item => {
  246. return {
  247. ...item,
  248. enough: (item.usePrice / 100).toFixed(2),
  249. amount: (item.discountPrice / 100).toFixed(2),
  250. use_start_time: sheep.$helper.timeFormat(item
  251. .validStartTime,
  252. 'yyyy-mm-dd hh:MM:ss'),
  253. use_end_time: sheep.$helper.timeFormat(item.validEndTime,
  254. 'yyyy-mm-dd hh:MM:ss'),
  255. status_text: obj[item.status],
  256. type_text: obj2[item.discountType],
  257. get_status_text: obj3[item.status],
  258. type_text: obj2[item.discountType]
  259. }
  260. });
  261. state.couponInfo = res.data;
  262. });
  263. });
  264. // return;
  265. // 3. 加载营销活动信息
  266. ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  267. if (res.code !== 0) {
  268. return;
  269. }
  270. state.activityList = res.data;
  271. });
  272. });
  273. </script>
  274. <style lang="scss" scoped>
  275. .detail-card {
  276. background-color: #ffff;
  277. margin: 14rpx 20rpx;
  278. border-radius: 10rpx;
  279. overflow: hidden;
  280. }
  281. // 价格标题卡片
  282. .title-card {
  283. .price-box {
  284. .price-text {
  285. font-size: 42rpx;
  286. font-weight: 500;
  287. color: #ff3000;
  288. line-height: 30rpx;
  289. font-family: OPPOSANS;
  290. &::before {
  291. content: '¥';
  292. font-size: 30rpx;
  293. }
  294. }
  295. .origin-price-text {
  296. font-size: 26rpx;
  297. font-weight: 400;
  298. text-decoration: line-through;
  299. color: $gray-c;
  300. font-family: OPPOSANS;
  301. &::before {
  302. content: '¥';
  303. }
  304. }
  305. }
  306. .sales-text {
  307. font-size: 26rpx;
  308. font-weight: 500;
  309. color: $gray-c;
  310. }
  311. .discounts-box {
  312. .tag-content {
  313. flex: 1;
  314. min-width: 0;
  315. white-space: nowrap;
  316. }
  317. .tag-box {
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. }
  321. .tag {
  322. flex-shrink: 0;
  323. padding: 4rpx 10rpx;
  324. font-size: 24rpx;
  325. font-weight: 500;
  326. border-radius: 4rpx;
  327. color: var(--ui-BG-Main);
  328. background: var(--ui-BG-Main-tag);
  329. }
  330. .discounts-title {
  331. font-size: 24rpx;
  332. font-weight: 500;
  333. color: var(--ui-BG-Main);
  334. line-height: normal;
  335. }
  336. .cicon-forward {
  337. color: var(--ui-BG-Main);
  338. font-size: 24rpx;
  339. line-height: normal;
  340. margin-top: 4rpx;
  341. }
  342. }
  343. .title-text {
  344. font-size: 30rpx;
  345. font-weight: bold;
  346. line-height: 42rpx;
  347. }
  348. .subtitle-text {
  349. font-size: 26rpx;
  350. font-weight: 400;
  351. color: $dark-9;
  352. line-height: 42rpx;
  353. }
  354. }
  355. // 购买
  356. .buy-box {
  357. .add-btn {
  358. width: 214rpx;
  359. height: 72rpx;
  360. font-weight: 500;
  361. font-size: 28rpx;
  362. border-radius: 40rpx 0 0 40rpx;
  363. background-color: var(--ui-BG-Main-light);
  364. color: var(--ui-BG-Main);
  365. }
  366. .buy-btn {
  367. width: 214rpx;
  368. height: 72rpx;
  369. font-weight: 500;
  370. font-size: 28rpx;
  371. border-radius: 0 40rpx 40rpx 0;
  372. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  373. color: $white;
  374. }
  375. .disabled-btn {
  376. width: 428rpx;
  377. height: 72rpx;
  378. border-radius: 40rpx;
  379. background: #999999;
  380. color: $white;
  381. }
  382. }
  383. .model-box {
  384. height: 60vh;
  385. .model-content {
  386. height: 56vh;
  387. }
  388. .title {
  389. font-size: 36rpx;
  390. font-weight: bold;
  391. color: #333333;
  392. }
  393. .subtitle {
  394. font-size: 26rpx;
  395. font-weight: 500;
  396. color: #333333;
  397. }
  398. }
  399. </style>