index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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-model="state.goodsInfo.service" />
  77. <detail-cell-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. </detail-tabbar>
  116. <s-coupon-get
  117. v-model="state.couponInfo"
  118. :show="state.showModel"
  119. @close="state.showModel = false"
  120. @get="onGet"
  121. />
  122. <s-activity-pop
  123. v-model="state.activityInfo"
  124. :show="state.showActivityModel"
  125. @close="state.showActivityModel = false"
  126. />
  127. </block>
  128. </s-layout>
  129. </view>
  130. </template>
  131. <script setup>
  132. import { reactive, computed } from 'vue';
  133. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  134. import sheep from '@/sheep';
  135. import { formatSales, formatGoodsSwiper, formatPrice } from '@/sheep/hooks/useGoods';
  136. import detailNavbar from './components/detail/detail-navbar.vue';
  137. import detailCellSku from './components/detail/detail-cell-sku.vue';
  138. import detailCellService from './components/detail/detail-cell-service.vue';
  139. import detailCellParams from './components/detail/detail-cell-params.vue';
  140. import detailTabbar from './components/detail/detail-tabbar.vue';
  141. import detailSkeleton from './components/detail/detail-skeleton.vue';
  142. import detailCommentCard from './components/detail/detail-comment-card.vue';
  143. import detailContentCard from './components/detail/detail-content-card.vue';
  144. import detailActivityTip from './components/detail/detail-activity-tip.vue';
  145. import { isEmpty } from 'lodash';
  146. // import detailActivityTip from './components/detail/detail-activity-tip.vue';
  147. // import detailTab from './components/detail/detail-tab.vue';
  148. // import detailCoupon from './components/detail/detail-coupon.vue';
  149. onPageScroll(() => {});
  150. const state = reactive({
  151. goodsId: 0,
  152. skeletonLoading: true,
  153. goodsInfo: {},
  154. showSelectSku: false,
  155. goodsSwiper: [],
  156. selectedSkuPrice: {},
  157. showModel: false,
  158. total: 0,
  159. couponInfo: [],
  160. showActivityModel: false,
  161. activityInfo: [],
  162. });
  163. // 规格变更
  164. function onSkuChange(e) {
  165. state.selectedSkuPrice = e;
  166. }
  167. // 添加购物车
  168. function onAddCart(e) {
  169. sheep.$store('cart').add(e);
  170. }
  171. // 立即购买
  172. function onBuy(e) {
  173. sheep.$router.go('/pages/order/confirm', {
  174. data: JSON.stringify({
  175. order_type: 'goods',
  176. goods_list: [
  177. {
  178. goods_id: e.goods_id,
  179. goods_num: e.goods_num,
  180. goods_sku_price_id: e.id,
  181. },
  182. ],
  183. }),
  184. });
  185. }
  186. //营销活动
  187. function onActivity() {
  188. state.activityInfo = state.goodsInfo.promos;
  189. state.showActivityModel = true;
  190. }
  191. //立即领取
  192. async function onGet(id) {
  193. const { error, msg } = await sheep.$api.coupon.get(id);
  194. if (error === 0) {
  195. uni.showToast({
  196. title: msg,
  197. });
  198. setTimeout(() => {
  199. getCoupon();
  200. }, 1000);
  201. }
  202. }
  203. const shareInfo = computed(() => {
  204. if (isEmpty(state.goodsInfo)) return {};
  205. return sheep.$platform.share.getShareInfo(
  206. {
  207. title: state.goodsInfo.title,
  208. image: sheep.$url.cdn(state.goodsInfo.image),
  209. desc: state.goodsInfo.subtitle,
  210. params: {
  211. page: '2',
  212. query: state.goodsInfo.id,
  213. },
  214. },
  215. {
  216. type: 'goods', // 商品海报
  217. title: state.goodsInfo.title, // 商品标题
  218. image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
  219. price: state.goodsInfo.price[0], // 商品价格
  220. original_price: state.goodsInfo.original_price, // 商品原价
  221. },
  222. );
  223. });
  224. onLoad(async (options) => {
  225. // 非法参数
  226. if (!options.id) {
  227. state.goodsInfo = null;
  228. return;
  229. }
  230. state.goodsId = options.id;
  231. // 加载商品信息
  232. sheep.$api.goods.detail(state.goodsId).then((res) => {
  233. state.skeletonLoading = false;
  234. if (res.error === 0) {
  235. state.goodsInfo = res.data;
  236. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.images);
  237. } else {
  238. // 未找到商品
  239. state.goodsInfo = null;
  240. }
  241. });
  242. const { error, data } = await sheep.$api.coupon.listByGoods(state.goodsId);
  243. if (error === 0) {
  244. state.couponInfo = data;
  245. }
  246. });
  247. </script>
  248. <style lang="scss" scoped>
  249. .detail-card {
  250. background-color: #ffff;
  251. margin: 14rpx 20rpx;
  252. border-radius: 10rpx;
  253. overflow: hidden;
  254. }
  255. // 价格标题卡片
  256. .title-card {
  257. .price-box {
  258. .price-text {
  259. font-size: 42rpx;
  260. font-weight: 500;
  261. color: #ff3000;
  262. line-height: 30rpx;
  263. font-family: OPPOSANS;
  264. &::before {
  265. content: '¥';
  266. font-size: 30rpx;
  267. }
  268. }
  269. .origin-price-text {
  270. font-size: 26rpx;
  271. font-weight: 400;
  272. text-decoration: line-through;
  273. color: $gray-c;
  274. font-family: OPPOSANS;
  275. &::before {
  276. content: '¥';
  277. }
  278. }
  279. }
  280. .sales-text {
  281. font-size: 26rpx;
  282. font-weight: 500;
  283. color: $gray-c;
  284. }
  285. .discounts-box {
  286. .tag-content {
  287. flex: 1;
  288. min-width: 0;
  289. white-space: nowrap;
  290. }
  291. .tag-box {
  292. overflow: hidden;
  293. text-overflow: ellipsis;
  294. }
  295. .tag {
  296. flex-shrink: 0;
  297. padding: 4rpx 10rpx;
  298. font-size: 24rpx;
  299. font-weight: 500;
  300. border-radius: 4rpx;
  301. color: var(--ui-BG-Main);
  302. background: var(--ui-BG-Main-tag);
  303. }
  304. .discounts-title {
  305. font-size: 24rpx;
  306. font-weight: 500;
  307. color: var(--ui-BG-Main);
  308. line-height: normal;
  309. }
  310. .cicon-forward {
  311. color: var(--ui-BG-Main);
  312. font-size: 24rpx;
  313. line-height: normal;
  314. margin-top: 4rpx;
  315. }
  316. }
  317. .title-text {
  318. font-size: 30rpx;
  319. font-weight: bold;
  320. line-height: 42rpx;
  321. }
  322. .subtitle-text {
  323. font-size: 26rpx;
  324. font-weight: 400;
  325. color: $dark-9;
  326. line-height: 42rpx;
  327. }
  328. }
  329. // 购买
  330. .buy-box {
  331. .add-btn {
  332. width: 214rpx;
  333. height: 72rpx;
  334. font-weight: 500;
  335. font-size: 28rpx;
  336. border-radius: 40rpx 0 0 40rpx;
  337. background-color: var(--ui-BG-Main-light);
  338. color: var(--ui-BG-Main);
  339. }
  340. .buy-btn {
  341. width: 214rpx;
  342. height: 72rpx;
  343. font-weight: 500;
  344. font-size: 28rpx;
  345. border-radius: 0 40rpx 40rpx 0;
  346. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  347. color: $white;
  348. }
  349. }
  350. .model-box {
  351. height: 60vh;
  352. .model-content {
  353. height: 56vh;
  354. }
  355. .title {
  356. font-size: 36rpx;
  357. font-weight: bold;
  358. color: #333333;
  359. }
  360. .subtitle {
  361. font-size: 26rpx;
  362. font-weight: 500;
  363. color: #333333;
  364. }
  365. }
  366. </style>