index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. sheep.$store('cart').add(e);
  142. }
  143. // 立即购买 TODO 芋艿:待测试
  144. function onBuy(e) {
  145. sheep.$router.go('/pages/order/confirm', {
  146. data: JSON.stringify({
  147. order_type: 'goods',
  148. goods_list: [{
  149. goods_id: e.goods_id,
  150. goods_num: e.goods_num,
  151. goods_sku_price_id: e.id,
  152. }, ],
  153. }),
  154. });
  155. }
  156. // 营销活动 TODO 芋艿:待测试
  157. function onActivity() {
  158. state.activityInfo = state.goodsInfo.promos;
  159. state.showActivityModel = true;
  160. }
  161. // 立即领取 TODO 芋艿:待测试
  162. async function onGet(id) {
  163. const {
  164. error,
  165. msg
  166. } = await sheep.$api.coupon.get(id);
  167. if (error === 0) {
  168. uni.showToast({
  169. title: msg,
  170. });
  171. setTimeout(() => {
  172. getCoupon();
  173. }, 1000);
  174. }
  175. }
  176. // TODO 芋艿:待测试
  177. const shareInfo = computed(() => {
  178. if (isEmpty(state.goodsInfo)) return {};
  179. return sheep.$platform.share.getShareInfo({
  180. title: state.goodsInfo.name,
  181. image: sheep.$url.cdn(state.goodsInfo.image),
  182. desc: state.goodsInfo.subtitle,
  183. params: {
  184. page: '2',
  185. query: state.goodsInfo.id,
  186. },
  187. }, {
  188. type: 'goods', // 商品海报
  189. title: state.goodsInfo.name, // 商品标题
  190. // image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  191. image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
  192. price: state.goodsInfo.price, // 商品价格
  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((res) => {
  205. // 未找到商品
  206. if (res.code !== 0 || !res.data) {
  207. state.goodsInfo = null;
  208. return;
  209. }
  210. // 加载到商品
  211. state.skeletonLoading = false;
  212. state.goodsInfo = res.data;
  213. });
  214. // 2. 加载优惠劵信息
  215. CouponApi.getCouponTemplateList(state.goodsId, 2, 10).then((res) => {
  216. if (res.code !== 0) {
  217. return;
  218. }
  219. state.couponInfo = res.data;
  220. });
  221. // 3. 加载营销活动信息
  222. ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  223. if (res.code !== 0) {
  224. return;
  225. }
  226. state.activityList = res.data;
  227. });
  228. });
  229. </script>
  230. <style lang="scss" scoped>
  231. .detail-card {
  232. background-color: #ffff;
  233. margin: 14rpx 20rpx;
  234. border-radius: 10rpx;
  235. overflow: hidden;
  236. }
  237. // 价格标题卡片
  238. .title-card {
  239. .price-box {
  240. .price-text {
  241. font-size: 42rpx;
  242. font-weight: 500;
  243. color: #ff3000;
  244. line-height: 30rpx;
  245. font-family: OPPOSANS;
  246. &::before {
  247. content: '¥';
  248. font-size: 30rpx;
  249. }
  250. }
  251. .origin-price-text {
  252. font-size: 26rpx;
  253. font-weight: 400;
  254. text-decoration: line-through;
  255. color: $gray-c;
  256. font-family: OPPOSANS;
  257. &::before {
  258. content: '¥';
  259. }
  260. }
  261. }
  262. .sales-text {
  263. font-size: 26rpx;
  264. font-weight: 500;
  265. color: $gray-c;
  266. }
  267. .discounts-box {
  268. .tag-content {
  269. flex: 1;
  270. min-width: 0;
  271. white-space: nowrap;
  272. }
  273. .tag-box {
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. }
  277. .tag {
  278. flex-shrink: 0;
  279. padding: 4rpx 10rpx;
  280. font-size: 24rpx;
  281. font-weight: 500;
  282. border-radius: 4rpx;
  283. color: var(--ui-BG-Main);
  284. background: var(--ui-BG-Main-tag);
  285. }
  286. .discounts-title {
  287. font-size: 24rpx;
  288. font-weight: 500;
  289. color: var(--ui-BG-Main);
  290. line-height: normal;
  291. }
  292. .cicon-forward {
  293. color: var(--ui-BG-Main);
  294. font-size: 24rpx;
  295. line-height: normal;
  296. margin-top: 4rpx;
  297. }
  298. }
  299. .title-text {
  300. font-size: 30rpx;
  301. font-weight: bold;
  302. line-height: 42rpx;
  303. }
  304. .subtitle-text {
  305. font-size: 26rpx;
  306. font-weight: 400;
  307. color: $dark-9;
  308. line-height: 42rpx;
  309. }
  310. }
  311. // 购买
  312. .buy-box {
  313. .add-btn {
  314. width: 214rpx;
  315. height: 72rpx;
  316. font-weight: 500;
  317. font-size: 28rpx;
  318. border-radius: 40rpx 0 0 40rpx;
  319. background-color: var(--ui-BG-Main-light);
  320. color: var(--ui-BG-Main);
  321. }
  322. .buy-btn {
  323. width: 214rpx;
  324. height: 72rpx;
  325. font-weight: 500;
  326. font-size: 28rpx;
  327. border-radius: 0 40rpx 40rpx 0;
  328. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  329. color: $white;
  330. }
  331. .disabled-btn {
  332. width: 428rpx;
  333. height: 72rpx;
  334. border-radius: 40rpx;
  335. background: #999999;
  336. color: $white;
  337. }
  338. }
  339. .model-box {
  340. height: 60vh;
  341. .model-content {
  342. height: 56vh;
  343. }
  344. .title {
  345. font-size: 36rpx;
  346. font-weight: bold;
  347. color: #333333;
  348. }
  349. .subtitle {
  350. font-size: 26rpx;
  351. font-weight: 500;
  352. color: #333333;
  353. }
  354. }
  355. </style>