index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. <!-- TODO 芋艿:promos 未写 -->
  32. <view class="discounts-box ss-flex ss-row-between ss-m-b-28">
  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. <!-- TODO 芋艿:couponInfo 优惠劵 -->
  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. <!-- TODO 芋艿:活动跳转 -->
  67. <detail-activity-tip v-if="state.goodsInfo.activities" :data="state.goodsInfo" />
  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. <s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false"
  83. @get="onGet" />
  84. <s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel"
  85. @close="state.showActivityModel = false" />
  86. </block>
  87. </s-layout>
  88. </view>
  89. </template>
  90. <script setup>
  91. import { reactive, computed } from 'vue';
  92. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  93. import sheep from '@/sheep';
  94. import { formatSales, formatGoodsSwiper, fen2yuan, } from '@/sheep/hooks/useGoods';
  95. import detailNavbar from './components/detail/detail-navbar.vue';
  96. import detailCellSku from './components/detail/detail-cell-sku.vue';
  97. import detailCellService from './components/detail/detail-cell-service.vue';
  98. import detailCellParams from './components/detail/detail-cell-params.vue';
  99. import detailTabbar from './components/detail/detail-tabbar.vue';
  100. import detailSkeleton from './components/detail/detail-skeleton.vue';
  101. import detailCommentCard from './components/detail/detail-comment-card.vue';
  102. import detailContentCard from './components/detail/detail-content-card.vue';
  103. import detailActivityTip from './components/detail/detail-activity-tip.vue';
  104. import {
  105. isEmpty
  106. } from 'lodash';
  107. // import detailActivityTip from './components/detail/detail-activity-tip.vue';
  108. // import detailTab from './components/detail/detail-tab.vue';
  109. // import detailCoupon from './components/detail/detail-coupon.vue';
  110. onPageScroll(() => {});
  111. const state = reactive({
  112. goodsId: 0,
  113. skeletonLoading: true, // SPU 加载中
  114. goodsInfo: {}, // SPU 信息
  115. showSelectSku: false, // 是否展示 SKU 选择弹窗
  116. selectedSku: {}, // 选中的 SKU
  117. showModel: false,
  118. couponInfo: [],
  119. showActivityModel: false,
  120. activityInfo: [],
  121. });
  122. // 规格变更 TODO 芋艿:待测试
  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. // TODO 芋艿:下面接口的调整
  201. if (true) {
  202. return
  203. }
  204. // 2. 加载优惠劵信息
  205. const {
  206. error,
  207. data
  208. } = await sheep.$api.coupon.listByGoods(state.goodsId);
  209. if (error === 0) {
  210. state.couponInfo = data;
  211. }
  212. });
  213. </script>
  214. <style lang="scss" scoped>
  215. .detail-card {
  216. background-color: #ffff;
  217. margin: 14rpx 20rpx;
  218. border-radius: 10rpx;
  219. overflow: hidden;
  220. }
  221. // 价格标题卡片
  222. .title-card {
  223. .price-box {
  224. .price-text {
  225. font-size: 42rpx;
  226. font-weight: 500;
  227. color: #ff3000;
  228. line-height: 30rpx;
  229. font-family: OPPOSANS;
  230. &::before {
  231. content: '¥';
  232. font-size: 30rpx;
  233. }
  234. }
  235. .origin-price-text {
  236. font-size: 26rpx;
  237. font-weight: 400;
  238. text-decoration: line-through;
  239. color: $gray-c;
  240. font-family: OPPOSANS;
  241. &::before {
  242. content: '¥';
  243. }
  244. }
  245. }
  246. .sales-text {
  247. font-size: 26rpx;
  248. font-weight: 500;
  249. color: $gray-c;
  250. }
  251. .discounts-box {
  252. .tag-content {
  253. flex: 1;
  254. min-width: 0;
  255. white-space: nowrap;
  256. }
  257. .tag-box {
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. }
  261. .tag {
  262. flex-shrink: 0;
  263. padding: 4rpx 10rpx;
  264. font-size: 24rpx;
  265. font-weight: 500;
  266. border-radius: 4rpx;
  267. color: var(--ui-BG-Main);
  268. background: var(--ui-BG-Main-tag);
  269. }
  270. .discounts-title {
  271. font-size: 24rpx;
  272. font-weight: 500;
  273. color: var(--ui-BG-Main);
  274. line-height: normal;
  275. }
  276. .cicon-forward {
  277. color: var(--ui-BG-Main);
  278. font-size: 24rpx;
  279. line-height: normal;
  280. margin-top: 4rpx;
  281. }
  282. }
  283. .title-text {
  284. font-size: 30rpx;
  285. font-weight: bold;
  286. line-height: 42rpx;
  287. }
  288. .subtitle-text {
  289. font-size: 26rpx;
  290. font-weight: 400;
  291. color: $dark-9;
  292. line-height: 42rpx;
  293. }
  294. }
  295. // 购买
  296. .buy-box {
  297. .add-btn {
  298. width: 214rpx;
  299. height: 72rpx;
  300. font-weight: 500;
  301. font-size: 28rpx;
  302. border-radius: 40rpx 0 0 40rpx;
  303. background-color: var(--ui-BG-Main-light);
  304. color: var(--ui-BG-Main);
  305. }
  306. .buy-btn {
  307. width: 214rpx;
  308. height: 72rpx;
  309. font-weight: 500;
  310. font-size: 28rpx;
  311. border-radius: 0 40rpx 40rpx 0;
  312. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  313. color: $white;
  314. }
  315. .disabled-btn {
  316. width: 428rpx;
  317. height: 72rpx;
  318. border-radius: 40rpx;
  319. background: #999999;
  320. color: $white;
  321. }
  322. }
  323. .model-box {
  324. height: 60vh;
  325. .model-content {
  326. height: 56vh;
  327. }
  328. .title {
  329. font-size: 36rpx;
  330. font-weight: bold;
  331. color: #333333;
  332. }
  333. .subtitle {
  334. font-size: 26rpx;
  335. font-weight: 500;
  336. color: #333333;
  337. }
  338. }
  339. </style>