score.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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>
  88. 已兑完
  89. </button>
  90. </view>
  91. </detail-tabbar>
  92. </block>
  93. </s-layout>
  94. </view>
  95. </template>
  96. <script setup>
  97. import { reactive, computed } from 'vue';
  98. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  99. import sheep from '@/sheep';
  100. import { isEmpty } from 'lodash';
  101. import { formatExchange, formatGoodsSwiper } from '@/sheep/hooks/useGoods';
  102. import detailNavbar from './components/detail/detail-navbar.vue';
  103. import detailCellSku from './components/detail/detail-cell-sku.vue';
  104. import detailCellService from './components/detail/detail-cell-service.vue';
  105. import detailCellParams from './components/detail/detail-cell-params.vue';
  106. import detailTabbar from './components/detail/detail-tabbar.vue';
  107. import detailSkeleton from './components/detail/detail-skeleton.vue';
  108. import detailCommentCard from './components/detail/detail-comment-card.vue';
  109. import detailContentCard from './components/detail/detail-content-card.vue';
  110. onPageScroll(() => {});
  111. const state = reactive({
  112. goodsId: 0,
  113. skeletonLoading: true,
  114. goodsInfo: {},
  115. showSelectSku: false,
  116. goodsSwiper: [],
  117. selectedSkuPrice: {},
  118. shareInfo: {},
  119. showModel: false,
  120. total: 0,
  121. couponInfo: [],
  122. });
  123. const goodsPrice = computed(() => {
  124. let price, score;
  125. if (isEmpty(state.selectedSkuPrice)) {
  126. price = state.goodsInfo.price[0];
  127. score = state.goodsInfo.score || 0;
  128. } else {
  129. price = state.selectedSkuPrice.price;
  130. score = state.selectedSkuPrice.score || 0;
  131. }
  132. return { price, score };
  133. });
  134. // 规格变更
  135. function onSkuChange(e) {
  136. state.selectedSkuPrice = e;
  137. }
  138. // 格式化价格
  139. function formatPrice(e) {
  140. if (Number(e[0]) > 0) {
  141. return e.length === 1 ? e[0] : e.join('~');
  142. } else {
  143. return '';
  144. }
  145. }
  146. // 添加购物车
  147. function onAddCart(e) {
  148. sheep.$store('cart').add(e);
  149. }
  150. // 立即购买
  151. function onBuy(e) {
  152. sheep.$router.go('/pages/order/confirm', {
  153. data: JSON.stringify({
  154. order_type: 'score',
  155. goods_list: [
  156. {
  157. goods_id: e.goods_id,
  158. goods_num: e.goods_num,
  159. goods_sku_price_id: e.id,
  160. },
  161. ],
  162. }),
  163. });
  164. }
  165. onLoad((options) => {
  166. // 非法参数
  167. if (!options.id) {
  168. state.goodsInfo = null;
  169. return;
  170. }
  171. state.goodsId = options.id;
  172. // 加载商品信息
  173. sheep.$api.app.scoreShopDetail(state.goodsId).then((res) => {
  174. state.skeletonLoading = false;
  175. if (res.error === 0) {
  176. state.goodsInfo = res.data;
  177. state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.images);
  178. } else {
  179. // 未找到商品
  180. state.goodsInfo = null;
  181. }
  182. });
  183. });
  184. </script>
  185. <style lang="scss" scoped>
  186. .detail-card {
  187. background-color: #ffff;
  188. margin: 14rpx 20rpx;
  189. border-radius: 10rpx;
  190. overflow: hidden;
  191. }
  192. // 价格标题卡片
  193. .title-card {
  194. width: 710rpx;
  195. box-sizing: border-box;
  196. background-size: 100% 100%;
  197. border-radius: 10rpx;
  198. background-image: v-bind("sheep.$url.css('/static/img/shop/goods/score-bg.png')");
  199. background-repeat: no-repeat;
  200. .price-box {
  201. .score-img {
  202. width: 36rpx;
  203. height: 36rpx;
  204. margin: 0 4rpx;
  205. }
  206. .score-text {
  207. font-size: 42rpx;
  208. font-weight: 500;
  209. color: #ff3000;
  210. line-height: 36rpx;
  211. font-family: OPPOSANS;
  212. }
  213. .price-text {
  214. font-size: 42rpx;
  215. font-weight: 500;
  216. color: #ff3000;
  217. line-height: 36rpx;
  218. font-family: OPPOSANS;
  219. }
  220. }
  221. .origin-price-text {
  222. font-size: 26rpx;
  223. font-weight: 400;
  224. text-decoration: line-through;
  225. color: $gray-c;
  226. font-family: OPPOSANS;
  227. }
  228. .sales-text {
  229. font-size: 26rpx;
  230. font-weight: 500;
  231. color: $gray-c;
  232. }
  233. .discounts-box {
  234. .discounts-tag {
  235. padding: 4rpx 10rpx;
  236. font-size: 24rpx;
  237. font-weight: 500;
  238. border-radius: 4rpx;
  239. color: var(--ui-BG-Main);
  240. // background: rgba(#2aae67, 0.05);
  241. background: var(--ui-BG-Main-tag);
  242. }
  243. .discounts-title {
  244. font-size: 24rpx;
  245. font-weight: 500;
  246. color: var(--ui-BG-Main);
  247. line-height: normal;
  248. }
  249. .cicon-forward {
  250. color: var(--ui-BG-Main);
  251. font-size: 24rpx;
  252. line-height: normal;
  253. margin-top: 4rpx;
  254. }
  255. }
  256. .title-text {
  257. font-size: 30rpx;
  258. font-weight: bold;
  259. line-height: 42rpx;
  260. }
  261. .subtitle-text {
  262. font-size: 26rpx;
  263. font-weight: 400;
  264. color: $dark-9;
  265. line-height: 42rpx;
  266. }
  267. }
  268. // 购买
  269. .buy-box {
  270. .buy-btn {
  271. width: 630rpx;
  272. height: 80rpx;
  273. border-radius: 40rpx;
  274. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  275. color: $white;
  276. }
  277. .disabled-btn {
  278. width: 630rpx;
  279. height: 80rpx;
  280. border-radius: 40rpx;
  281. background: #999999;
  282. color: $white;
  283. }
  284. }
  285. //秒杀卡片
  286. .seckill-box {
  287. background: v-bind("sheep.$url.css('/static/img/shop/goods/seckill-tip-bg.png')") no-repeat;
  288. background-size: 100% 100%;
  289. }
  290. .groupon-box {
  291. background: v-bind("sheep.$url.css('/static/img/shop/goods/groupon-tip-bg.png')") no-repeat;
  292. background-size: 100% 100%;
  293. }
  294. //活动卡片
  295. .activity-box {
  296. width: 100%;
  297. height: 80rpx;
  298. box-sizing: border-box;
  299. margin-bottom: 10rpx;
  300. .activity-title {
  301. font-size: 26rpx;
  302. font-weight: 500;
  303. color: #ffffff;
  304. line-height: 42rpx;
  305. .activity-icon {
  306. width: 38rpx;
  307. height: 38rpx;
  308. }
  309. }
  310. .activity-go {
  311. width: 70rpx;
  312. height: 32rpx;
  313. background: #ffffff;
  314. border-radius: 16rpx;
  315. font-weight: 500;
  316. color: #ff6000;
  317. font-size: 24rpx;
  318. line-height: normal;
  319. }
  320. }
  321. .model-box {
  322. height: 60vh;
  323. .model-content {
  324. height: 56vh;
  325. }
  326. .title {
  327. font-size: 36rpx;
  328. font-weight: bold;
  329. color: #333333;
  330. }
  331. .subtitle {
  332. font-size: 26rpx;
  333. font-weight: 500;
  334. color: #333333;
  335. }
  336. }
  337. </style>