score.vue 9.7 KB

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