index.vue 13 KB

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