index.vue 12 KB

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