index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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.description" />
  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. console.log('页面被访问')
  229. // 非法参数
  230. if (!options.id) {
  231. state.goodsInfo = null;
  232. return;
  233. }
  234. state.goodsId = options.id;
  235. // 加载商品信息
  236. sheep.$api.goods.detail(state.goodsId).then((res) => {
  237. console.log(res)
  238. state.skeletonLoading = false;
  239. if (res.code === 0) {
  240. // 在此处对数据做出转换
  241. res.data.sales=res.data.salesCount
  242. res.data.original_price=res.data.marketPrice/100
  243. res.data.subtitle=res.data.introduction
  244. res.data.title=res.data.name
  245. res.data.price=[res.data.price/100]
  246. state.goodsInfo = res.data;
  247. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
  248. } else {
  249. // 未找到商品
  250. state.goodsInfo = null;
  251. }
  252. });
  253. const { error, data } = await sheep.$api.coupon.listByGoods(state.goodsId);
  254. if (error === 0) {
  255. state.couponInfo = data;
  256. }
  257. });
  258. </script>
  259. <style lang="scss" scoped>
  260. .detail-card {
  261. background-color: #ffff;
  262. margin: 14rpx 20rpx;
  263. border-radius: 10rpx;
  264. overflow: hidden;
  265. }
  266. // 价格标题卡片
  267. .title-card {
  268. .price-box {
  269. .price-text {
  270. font-size: 42rpx;
  271. font-weight: 500;
  272. color: #ff3000;
  273. line-height: 30rpx;
  274. font-family: OPPOSANS;
  275. &::before {
  276. content: '¥';
  277. font-size: 30rpx;
  278. }
  279. }
  280. .origin-price-text {
  281. font-size: 26rpx;
  282. font-weight: 400;
  283. text-decoration: line-through;
  284. color: $gray-c;
  285. font-family: OPPOSANS;
  286. &::before {
  287. content: '¥';
  288. }
  289. }
  290. }
  291. .sales-text {
  292. font-size: 26rpx;
  293. font-weight: 500;
  294. color: $gray-c;
  295. }
  296. .discounts-box {
  297. .tag-content {
  298. flex: 1;
  299. min-width: 0;
  300. white-space: nowrap;
  301. }
  302. .tag-box {
  303. overflow: hidden;
  304. text-overflow: ellipsis;
  305. }
  306. .tag {
  307. flex-shrink: 0;
  308. padding: 4rpx 10rpx;
  309. font-size: 24rpx;
  310. font-weight: 500;
  311. border-radius: 4rpx;
  312. color: var(--ui-BG-Main);
  313. background: var(--ui-BG-Main-tag);
  314. }
  315. .discounts-title {
  316. font-size: 24rpx;
  317. font-weight: 500;
  318. color: var(--ui-BG-Main);
  319. line-height: normal;
  320. }
  321. .cicon-forward {
  322. color: var(--ui-BG-Main);
  323. font-size: 24rpx;
  324. line-height: normal;
  325. margin-top: 4rpx;
  326. }
  327. }
  328. .title-text {
  329. font-size: 30rpx;
  330. font-weight: bold;
  331. line-height: 42rpx;
  332. }
  333. .subtitle-text {
  334. font-size: 26rpx;
  335. font-weight: 400;
  336. color: $dark-9;
  337. line-height: 42rpx;
  338. }
  339. }
  340. // 购买
  341. .buy-box {
  342. .add-btn {
  343. width: 214rpx;
  344. height: 72rpx;
  345. font-weight: 500;
  346. font-size: 28rpx;
  347. border-radius: 40rpx 0 0 40rpx;
  348. background-color: var(--ui-BG-Main-light);
  349. color: var(--ui-BG-Main);
  350. }
  351. .buy-btn {
  352. width: 214rpx;
  353. height: 72rpx;
  354. font-weight: 500;
  355. font-size: 28rpx;
  356. border-radius: 0 40rpx 40rpx 0;
  357. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  358. color: $white;
  359. }
  360. .disabled-btn {
  361. width: 428rpx;
  362. height: 72rpx;
  363. border-radius: 40rpx;
  364. background: #999999;
  365. color: $white;
  366. }
  367. }
  368. .model-box {
  369. height: 60vh;
  370. .model-content {
  371. height: 56vh;
  372. }
  373. .title {
  374. font-size: 36rpx;
  375. font-weight: bold;
  376. color: #333333;
  377. }
  378. .subtitle {
  379. font-size: 26rpx;
  380. font-weight: 500;
  381. color: #333333;
  382. }
  383. }
  384. </style>