index.vue 11 KB

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