score.vue 9.3 KB

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