index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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" :key="promos.id" @tap="onActivity">
  36. {{ promos.title }}
  37. </view>
  38. </view>
  39. </div>
  40. <!-- 优惠劵 -->
  41. <view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="state.showModel = true"
  42. v-if="state.couponInfo.length">
  43. <view class="discounts-title ss-m-r-8">领券</view>
  44. <text class="cicon-forward"></text>
  45. </view>
  46. </view>
  47. <view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name }}</view>
  48. <view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
  49. </view>
  50. <!-- 功能卡片 -->
  51. <view class="detail-cell-card detail-card ss-flex-col">
  52. <detail-cell-sku v-model="state.selectedSku.goods_sku_text" :sku="state.selectedSku"
  53. @tap="state.showSelectSku = true" />
  54. <!-- TODO 芋艿:可能暂时不考虑使用 -->
  55. <detail-cell-service v-if="state.goodsInfo.service" v-model="state.goodsInfo.service" />
  56. <detail-cell-params v-if="state.goodsInfo.params" v-model="state.goodsInfo.params" />
  57. </view>
  58. <!-- 规格与数量弹框 -->
  59. <s-select-sku :goodsInfo="state.goodsInfo" :show="state.showSelectSku" @addCart="onAddCart"
  60. @buy="onBuy" @change="onSkuChange" @close="state.showSelectSku = false" />
  61. </view>
  62. <!-- 评价 -->
  63. <detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
  64. <!-- 详情 -->
  65. <detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
  66. <!-- 活动跳转:拼团/秒杀/砍价活动 -->
  67. <detail-activity-tip v-if="state.activityList.length > 0" :activity-list="state.activityList" />
  68. <!-- 详情 tabbar -->
  69. <detail-tabbar v-model="state.goodsInfo">
  70. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-if="state.goodsInfo.stock > 0">
  71. <button class="ss-reset-button add-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
  72. 加入购物车
  73. </button>
  74. <button class="ss-reset-button buy-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
  75. 立即购买
  76. </button>
  77. </view>
  78. <view class="buy-box ss-flex ss-col-center ss-p-r-20" v-else>
  79. <button class="ss-reset-button disabled-btn" disabled> 已售罄 </button>
  80. </view>
  81. </detail-tabbar>
  82. <!-- 优惠劵弹窗 -->
  83. <s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false"
  84. @get="onGet" />
  85. <!-- 满减送/限时折扣活动弹窗 -->
  86. <s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel"
  87. @close="state.showActivityModel = false" />
  88. </block>
  89. </s-layout>
  90. </view>
  91. </template>
  92. <script setup>
  93. import { reactive, computed } from 'vue';
  94. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  95. import sheep from '@/sheep';
  96. import CouponApi from '@/sheep/api/promotion/coupon';
  97. import ActivityApi from '@/sheep/api/promotion/activity';
  98. import { formatSales, formatGoodsSwiper, fen2yuan, } from '@/sheep/hooks/useGoods';
  99. import detailNavbar from './components/detail/detail-navbar.vue';
  100. import detailCellSku from './components/detail/detail-cell-sku.vue';
  101. import detailCellService from './components/detail/detail-cell-service.vue';
  102. import detailCellParams from './components/detail/detail-cell-params.vue';
  103. import detailTabbar from './components/detail/detail-tabbar.vue';
  104. import detailSkeleton from './components/detail/detail-skeleton.vue';
  105. import detailCommentCard from './components/detail/detail-comment-card.vue';
  106. import detailContentCard from './components/detail/detail-content-card.vue';
  107. import detailActivityTip from './components/detail/detail-activity-tip.vue';
  108. import { isEmpty } from 'lodash';
  109. onPageScroll(() => {});
  110. const state = reactive({
  111. goodsId: 0,
  112. skeletonLoading: true, // SPU 加载中
  113. goodsInfo: {}, // SPU 信息
  114. showSelectSku: false, // 是否展示 SKU 选择弹窗
  115. selectedSku: {}, // 选中的 SKU
  116. showModel: false, // 是否展示 Coupon 优惠劵的弹窗
  117. couponInfo: [], // 可领取的 Coupon 优惠劵的列表
  118. showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  119. activityInfo: [], // 【满减送/限时折扣】可参与的 Activity 营销活动的列表
  120. activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  121. });
  122. // 规格变更
  123. function onSkuChange(e) {
  124. state.selectedSku = e;
  125. }
  126. // 添加购物车 TODO 芋艿:待测试
  127. function onAddCart(e) {
  128. sheep.$store('cart').add(e);
  129. }
  130. // 立即购买 TODO 芋艿:待测试
  131. function onBuy(e) {
  132. sheep.$router.go('/pages/order/confirm', {
  133. data: JSON.stringify({
  134. order_type: 'goods',
  135. goods_list: [{
  136. goods_id: e.goods_id,
  137. goods_num: e.goods_num,
  138. goods_sku_price_id: e.id,
  139. }, ],
  140. }),
  141. });
  142. }
  143. // 营销活动 TODO 芋艿:待测试
  144. function onActivity() {
  145. state.activityInfo = state.goodsInfo.promos;
  146. state.showActivityModel = true;
  147. }
  148. // 立即领取 TODO 芋艿:待测试
  149. async function onGet(id) {
  150. const {
  151. error,
  152. msg
  153. } = await sheep.$api.coupon.get(id);
  154. if (error === 0) {
  155. uni.showToast({
  156. title: msg,
  157. });
  158. setTimeout(() => {
  159. getCoupon();
  160. }, 1000);
  161. }
  162. }
  163. // TODO 芋艿:待测试
  164. const shareInfo = computed(() => {
  165. if (isEmpty(state.goodsInfo)) return {};
  166. return sheep.$platform.share.getShareInfo({
  167. title: state.goodsInfo.name,
  168. image: sheep.$url.cdn(state.goodsInfo.image),
  169. desc: state.goodsInfo.subtitle,
  170. params: {
  171. page: '2',
  172. query: state.goodsInfo.id,
  173. },
  174. }, {
  175. type: 'goods', // 商品海报
  176. title: state.goodsInfo.name, // 商品标题
  177. image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  178. price: state.goodsInfo.price[0], // 商品价格
  179. original_price: state.goodsInfo.original_price, // 商品原价
  180. }, );
  181. });
  182. onLoad(async (options) => {
  183. // 非法参数
  184. if (!options.id) {
  185. state.goodsInfo = null;
  186. return;
  187. }
  188. state.goodsId = options.id;
  189. // 1. 加载商品信息
  190. sheep.$api.goods.detail(state.goodsId).then((res) => {
  191. // 未找到商品
  192. if (res.code !== 0 || !res.data) {
  193. state.goodsInfo = null;
  194. return;
  195. }
  196. // 加载到商品
  197. state.skeletonLoading = false;
  198. state.goodsInfo = res.data;
  199. });
  200. // 2. 加载优惠劵信息
  201. CouponApi.getCouponTemplateList(state.goodsId,2, 10).then((res) => {
  202. if (res.code !== 0) {
  203. return;
  204. }
  205. state.couponInfo = res.data;
  206. });
  207. // 3. 加载营销活动信息
  208. ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
  209. if (res.code !== 0) {
  210. return;
  211. }
  212. state.activityList = res.data;
  213. });
  214. });
  215. </script>
  216. <style lang="scss" scoped>
  217. .detail-card {
  218. background-color: #ffff;
  219. margin: 14rpx 20rpx;
  220. border-radius: 10rpx;
  221. overflow: hidden;
  222. }
  223. // 价格标题卡片
  224. .title-card {
  225. .price-box {
  226. .price-text {
  227. font-size: 42rpx;
  228. font-weight: 500;
  229. color: #ff3000;
  230. line-height: 30rpx;
  231. font-family: OPPOSANS;
  232. &::before {
  233. content: '¥';
  234. font-size: 30rpx;
  235. }
  236. }
  237. .origin-price-text {
  238. font-size: 26rpx;
  239. font-weight: 400;
  240. text-decoration: line-through;
  241. color: $gray-c;
  242. font-family: OPPOSANS;
  243. &::before {
  244. content: '¥';
  245. }
  246. }
  247. }
  248. .sales-text {
  249. font-size: 26rpx;
  250. font-weight: 500;
  251. color: $gray-c;
  252. }
  253. .discounts-box {
  254. .tag-content {
  255. flex: 1;
  256. min-width: 0;
  257. white-space: nowrap;
  258. }
  259. .tag-box {
  260. overflow: hidden;
  261. text-overflow: ellipsis;
  262. }
  263. .tag {
  264. flex-shrink: 0;
  265. padding: 4rpx 10rpx;
  266. font-size: 24rpx;
  267. font-weight: 500;
  268. border-radius: 4rpx;
  269. color: var(--ui-BG-Main);
  270. background: var(--ui-BG-Main-tag);
  271. }
  272. .discounts-title {
  273. font-size: 24rpx;
  274. font-weight: 500;
  275. color: var(--ui-BG-Main);
  276. line-height: normal;
  277. }
  278. .cicon-forward {
  279. color: var(--ui-BG-Main);
  280. font-size: 24rpx;
  281. line-height: normal;
  282. margin-top: 4rpx;
  283. }
  284. }
  285. .title-text {
  286. font-size: 30rpx;
  287. font-weight: bold;
  288. line-height: 42rpx;
  289. }
  290. .subtitle-text {
  291. font-size: 26rpx;
  292. font-weight: 400;
  293. color: $dark-9;
  294. line-height: 42rpx;
  295. }
  296. }
  297. // 购买
  298. .buy-box {
  299. .add-btn {
  300. width: 214rpx;
  301. height: 72rpx;
  302. font-weight: 500;
  303. font-size: 28rpx;
  304. border-radius: 40rpx 0 0 40rpx;
  305. background-color: var(--ui-BG-Main-light);
  306. color: var(--ui-BG-Main);
  307. }
  308. .buy-btn {
  309. width: 214rpx;
  310. height: 72rpx;
  311. font-weight: 500;
  312. font-size: 28rpx;
  313. border-radius: 0 40rpx 40rpx 0;
  314. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  315. color: $white;
  316. }
  317. .disabled-btn {
  318. width: 428rpx;
  319. height: 72rpx;
  320. border-radius: 40rpx;
  321. background: #999999;
  322. color: $white;
  323. }
  324. }
  325. .model-box {
  326. height: 60vh;
  327. .model-content {
  328. height: 56vh;
  329. }
  330. .title {
  331. font-size: 36rpx;
  332. font-weight: bold;
  333. color: #333333;
  334. }
  335. .subtitle {
  336. font-size: 26rpx;
  337. font-weight: 500;
  338. color: #333333;
  339. }
  340. }
  341. </style>