product.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <view class="container">
  3. <!-- 商品轮播图 -->
  4. <u-swiper :list="spu.picUrls" @change="e => (currentNum = e.current)" :autoplay="false"
  5. height="750rpx" radius="0" indicatorStyle="right: 20px">
  6. <view slot="indicator" class="indicator-num">
  7. <text class="indicator-num__text">{{ currentNum + 1 }}/{{ spu.picUrls.length }}</text>
  8. </view>
  9. </u-swiper>
  10. <view class="product-box">
  11. <!-- TODO @Sfmind:样式讨论,要不要改成类似 likeshop 的样子?第一栏:价格 + 分享;第二栏:商品名;第三栏:库存、销量、浏览量 -->
  12. <view class="prod-info">
  13. <view class="info-text">
  14. <u--text :lines="2" size="14px" color="#333333" :text="spu.name"></u--text>
  15. </view>
  16. <view class="price-and-cart">
  17. <!-- TODO @Sfmind:custom-text-price 会报错 -->
  18. <custom-text-price color="red" size="16" intSize="26" :price="spu.minPrice"></custom-text-price>
  19. </view>
  20. </view>
  21. <view class="prod-favor">
  22. <u-icon name="star" color="#2979ff" size="28"></u-icon>
  23. </view>
  24. </view>
  25. <u-gap height="8" bgColor="#f3f3f3"></u-gap>
  26. <view class="row-box">
  27. <view class="row-left">规格</view>
  28. <view class="row-right" @click="skuPopup = true">
  29. <view class="row-content">
  30. <view class="sku-box">
  31. <view v-if="spu.skus.length > 0" class="sku-item">
  32. <view class="sku-desc">{{ spu.skus[currentSkuIndex].desc }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="row-more">
  37. <u-icon name="more-dot-fill" color="#939393" size="14"></u-icon>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 商品 SKU 选择弹窗 -->
  42. <u-popup :show="skuPopup" :round="10" :closeable="true" :closeOnClickOverlay="false" @close="skuPopup = false">
  43. <view class="sku-popup-slot">
  44. <view class="current-sku-info">
  45. <u--image class="current-sku-img" :showLoading="true" :src="spu.skus[currentSkuIndex].picUrl"
  46. width="120rpx" height="120rpx"></u--image>
  47. <view class="current-sku-desc">
  48. <!-- TODO @Sfmind:name 这里的选择规格值的拼接 -->
  49. <view class="name">{{ spu.skus[currentSkuIndex].desc }}</view>
  50. <custom-text-price color="red" size="12" intSize="18" :price="spu.skus[currentSkuIndex].price"></custom-text-price>
  51. <view class="current-sku-stock">库存: {{ 1 }}</view>
  52. </view>
  53. </view>
  54. <view class="sku-selection">
  55. <!-- TODO @Sfmind:name 这里是规格的具体选项 -->
  56. <view class="sku-item" :class="{ active: currentSkuIndex === index }" v-for="(item, index) in spu.skus"
  57. :key="item.id" @click="handleSkuItemClick(index)">{{ item.desc }}</view>
  58. </view>
  59. <view class="sku-num-box">
  60. <view class="text">选择数量</view>
  61. <u-number-box integer></u-number-box>
  62. </view>
  63. <view class="sku-btn-group">
  64. <view class="btn-item-main">
  65. <u-button type="warning" shape="circle" size="small" text="加入购物车"></u-button>
  66. </view>
  67. <view class="btn-item-main">
  68. <u-button type="error" shape="circle" size="small" text="立即购买"></u-button>
  69. </view>
  70. </view>
  71. </view>
  72. </u-popup>
  73. <u-gap height="8" bgColor="#f3f3f3"></u-gap>
  74. <view class="row-box">
  75. <view class="row-left">促销</view>
  76. <view class="row-right" v-if="promotionList.length > 0" @click="promotionPopup = true">
  77. <view class="row-content">
  78. <view class="prom-box">
  79. <view class="prom-item">
  80. <view class="prom-title">{{ promotionList[0].title }}</view>
  81. <text class="prom-desc">{{ promotionList[0].desc }}</text>
  82. </view>
  83. </view>
  84. </view>
  85. <view class="row-more">
  86. <u-icon name="more-dot-fill" color="#939393" size="14"></u-icon>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 促销信息弹窗 -->
  91. <u-popup :show="promotionPopup" :round="10" :closeable="true" :closeOnClickOverlay="false" @close="promotionPopup = false">
  92. <view class="prom-popup-slot">
  93. <view class="prom-info">促销信息</view>
  94. <view class="prom-list">
  95. <view v-for="(item, index) in promotionList" :key="index.id" class="prom-item">
  96. <view class="prom-title">{{ item.title }}</view>
  97. <text class="prom-desc">{{ item.desc }}</text>
  98. </view>
  99. </view>
  100. </view>
  101. </u-popup>
  102. <u-gap height="8" bgColor="#f3f3f3"></u-gap>
  103. <view class="row-box">
  104. <view class="row-left">领券</view>
  105. <view class="row-right" @click="handleCouponClick">
  106. <view class="row-content">
  107. <view class="coupon-box">
  108. <view v-if="couponList.length > 0" class="coupon-list">
  109. <view v-for="(item, index) in couponList" :key="item.id" class="coupon-item">
  110. <view v-if="index < 2" class="coupon-desc">{{ item.desc }}</view>
  111. </view>
  112. </view>
  113. <view class="coupon-total">共 {{ couponList.length }} 张</view>
  114. </view>
  115. </view>
  116. <view class="row-more">
  117. <u-icon name="more-dot-fill" color="#939393" size="14"></u-icon>
  118. </view>
  119. </view>
  120. </view>
  121. <u-gap height="8" bgColor="#f3f3f3"></u-gap>
  122. <view class="evaluation-box-wrap">
  123. <view class="evaluation-box">
  124. <view class="evaluation-title">评价</view>
  125. <view class="evaluation-info">
  126. <view class="evan-type-list">
  127. <view class="evan-type-item" :class="{ active: currentEvanIndex === index }" v-for="(item, index) in evanTypeList" :key="item.id" @click="handleEvanTypeClick(index)"> {{ item.name }}({{ item.count }}) </view>
  128. </view>
  129. <view class="comment-empty" v-if="true">
  130. <u-empty mode="comment" width="350rpx" height="350rpx" icon="/static/images/empty/comment.png"></u-empty>
  131. </view>
  132. <view v-else class="comment-list" style="min-height: 50px"> </view>
  133. </view>
  134. </view>
  135. </view>
  136. <!-- TODO @Sfmind:缺个商品详情 -->
  137. <view class="fixed-btn-box">
  138. <view class="btn-group">
  139. <navigator class="btn-item" url="/pages/index/index" open-type="switchTab" hover-class="none">
  140. <u-icon name="home" :size="24"></u-icon>
  141. <view class="btn-text">首页</view>
  142. </navigator>
  143. <navigator class="btn-item" url="/pages/xxx/xxx" open-type="navigate" hover-class="none">
  144. <u-icon name="server-man" :size="24"></u-icon>
  145. <view class="btn-text">客服</view>
  146. </navigator>
  147. <!-- TODO @Sfmind:改成收藏 -->
  148. <navigator class="btn-item" url="/pages/cart/cart" open-type="switchTab" hover-class="none">
  149. <u-icon name="star" :size="24"></u-icon>
  150. <view class="btn-text">收藏</view>
  151. </navigator>
  152. <view class="btn-item-main">
  153. <u-button type="warning" shape="circle" size="small" text="加入购物车"></u-button>
  154. </view>
  155. <view class="btn-item-main">
  156. <u-button type="error" color="#ea322b" shape="circle" size="small" text="立即购买"></u-button>
  157. </view>
  158. </view>
  159. <u-safe-bottom customStyle="background: #ffffff"></u-safe-bottom>
  160. </view>
  161. </view>
  162. </template>
  163. <script>
  164. import { getSpuDetail } from '../../api/product';
  165. export default {
  166. data() {
  167. return {
  168. current: 0,
  169. currentNum: 0,
  170. currentSkuIndex: 0,
  171. skuPopup: false,
  172. spu: {
  173. id: '',
  174. picUrls: [],
  175. minPrice: '13.00',
  176. sku: [
  177. {
  178. id: 0,
  179. picUrl: 'https://cdn.uviewui.com/uview/album/1.jpg',
  180. price: 13.0,
  181. desc: '山不在高,有仙则名。'
  182. },
  183. {
  184. id: 1,
  185. picUrl: 'https://cdn.uviewui.com/uview/album/2.jpg',
  186. price: 11.0,
  187. desc: '水不在深,有龙则灵。'
  188. },
  189. {
  190. id: 2,
  191. picUrl: 'https://cdn.uviewui.com/uview/album/3.jpg',
  192. price: 10.0,
  193. desc: '斯是陋室,惟吾德馨。'
  194. }
  195. ]
  196. },
  197. promotionPopup: false,
  198. promotionList: [
  199. {
  200. id: 0,
  201. title: '满额减',
  202. desc: '全场满500减100'
  203. },
  204. {
  205. id: 1,
  206. title: '满额减',
  207. desc: '全场满300减50'
  208. },
  209. {
  210. id: 2,
  211. title: '满额减',
  212. desc: '全场满200减20'
  213. },
  214. {
  215. id: 3,
  216. title: '满额减',
  217. desc: '全场满100减5'
  218. }
  219. ],
  220. couponList: [
  221. {
  222. id: 0,
  223. title: '优惠券',
  224. desc: '满50减10'
  225. },
  226. {
  227. id: 1,
  228. title: '优惠券',
  229. desc: '满30减5'
  230. },
  231. {
  232. id: 2,
  233. title: '优惠券',
  234. desc: '满20减2'
  235. }
  236. ],
  237. currentEvanIndex: 0,
  238. evanTypeList: [
  239. {
  240. id: '0',
  241. name: '全部',
  242. count: 0
  243. },
  244. {
  245. id: '1',
  246. name: '好评',
  247. count: 0
  248. },
  249. {
  250. id: '2',
  251. name: '中评',
  252. count: 0
  253. },
  254. {
  255. id: '3',
  256. name: '差评',
  257. count: 0
  258. },
  259. {
  260. id: '4',
  261. name: '有图',
  262. count: 0
  263. }
  264. ]
  265. }
  266. },
  267. onLoad(e) {
  268. if (!e.id) {
  269. uni.$u.toast('请求参数错误')
  270. return;
  271. }
  272. // 加载商品详情
  273. this.spu.id = e.id
  274. this.loadProductData()
  275. },
  276. methods: {
  277. loadProductData() {
  278. getSpuDetail(this.spu.id).then(res => {
  279. // this.spu.desc = res.data.description.replace(/<[^>]*>/g,'');
  280. // console.log(res)
  281. this.spu = res.data;
  282. })
  283. },
  284. handleSkuItemClick(index) {
  285. this.currentSkuIndex = index
  286. },
  287. handleCouponClick() {
  288. // TODO 未登录去登录,登录则跳转优惠券页面
  289. },
  290. handleEvanTypeClick(index) {
  291. this.currentEvanIndex = index
  292. // TODO 展示评论
  293. }
  294. },
  295. computed: {
  296. hasLogin() {
  297. return this.$store.getters.hasLogin
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. .indicator-num {
  304. @include flex-center;
  305. padding: 2px 0;
  306. background-color: rgba(0, 0, 0, 0.35);
  307. border-radius: 100px;
  308. width: 35px;
  309. &__text {
  310. color: #ffffff;
  311. font-size: 12px;
  312. }
  313. }
  314. .product-box {
  315. padding: 40rpx 40rpx 10rpx 40rpx;
  316. @include flex;
  317. border-bottom: $custom-border-style;
  318. .prod-info {
  319. padding-right: 30rpx;
  320. .info-text {
  321. padding-bottom: 10rpx;
  322. }
  323. .price-and-cart {
  324. @include flex-space-between;
  325. }
  326. }
  327. .prod-favor {
  328. margin-top: 15rpx;
  329. }
  330. }
  331. .row-box {
  332. @include flex-left;
  333. padding: 0 30rpx;
  334. height: 70rpx;
  335. .row-left {
  336. width: 70rpx;
  337. font-size: 24rpx;
  338. color: #939393;
  339. }
  340. .row-right {
  341. @include flex-space-between;
  342. flex: 1;
  343. .row-content {
  344. flex: 1;
  345. .prom-box {
  346. @include flex-left;
  347. .prom-item {
  348. @include flex-left;
  349. font-size: 22rpx;
  350. .prom-title {
  351. padding: 1rpx 10rpx;
  352. border: 1rpx solid red;
  353. border-radius: 5rpx;
  354. color: red;
  355. transform: scale(0.9);
  356. }
  357. .prom-desc {
  358. margin-left: 15rpx;
  359. }
  360. }
  361. }
  362. .coupon-box {
  363. @include flex-space-between;
  364. .coupon-list {
  365. @include flex-left;
  366. .coupon-item {
  367. @include flex-left;
  368. font-size: 22rpx;
  369. .coupon-desc {
  370. padding: 2rpx 15rpx;
  371. margin-right: 15rpx;
  372. background: red;
  373. color: #ffffff;
  374. }
  375. }
  376. }
  377. .coupon-total {
  378. color: #939393;
  379. font-size: 12rpx;
  380. padding: 0 15rpx;
  381. }
  382. }
  383. .sku-box {
  384. @include flex-space-between;
  385. .sku-item {
  386. @include flex-left;
  387. font-size: 22rpx;
  388. .sku-desc {
  389. margin-left: 15rpx;
  390. font-weight: 700;
  391. }
  392. }
  393. }
  394. }
  395. .row-more {
  396. @include flex-right;
  397. width: 30rpx;
  398. }
  399. }
  400. }
  401. .sku-popup-slot {
  402. width: 750rpx;
  403. .current-sku-info {
  404. @include flex;
  405. padding: 30rpx 100rpx 0 30rpx;
  406. .current-sku-img {
  407. border-radius: 10rpx;
  408. /deep/ * {
  409. border-radius: 10rpx;
  410. }
  411. }
  412. .current-sku-desc {
  413. padding: 0 30rpx;
  414. font-size: 28rpx;
  415. .current-sku-stock {
  416. height: 40rpx;
  417. line-height: 40rpx;
  418. color: #666666;
  419. font-size: 24rpx;
  420. }
  421. }
  422. }
  423. .sku-selection {
  424. margin: 30rpx;
  425. font-size: 26rpx;
  426. color: #939393;
  427. .sku-item {
  428. margin-bottom: 20rpx;
  429. border-radius: 6rpx;
  430. padding: 5rpx 15rpx;
  431. border: 1rpx solid #e3e3e3;
  432. width: fit-content !important;
  433. &.active {
  434. color: #666666;
  435. border: 1rpx solid #666666;
  436. }
  437. }
  438. }
  439. .sku-num-box {
  440. @include flex-space-between padding: 30rpx;
  441. .text {
  442. font-size: 30rpx;
  443. }
  444. }
  445. .sku-btn-group {
  446. @include flex-space-around;
  447. height: 100rpx;
  448. .btn-item-main {
  449. width: 350rpx;
  450. }
  451. }
  452. }
  453. .prom-popup-slot {
  454. width: 750rpx;
  455. min-height: 500rpx;
  456. .prom-info {
  457. background: #f3f3f3;
  458. line-height: 90rpx;
  459. padding-left: 30rpx;
  460. font-size: 36rpx;
  461. border-radius: 10px 10px 0 0;
  462. }
  463. .prom-list {
  464. padding: 30rpx;
  465. .prom-item {
  466. @include flex-left;
  467. font-size: 22rpx;
  468. margin-bottom: 15rpx;
  469. .prom-title {
  470. padding: 1rpx 10rpx;
  471. border: 1rpx solid red;
  472. border-radius: 5rpx;
  473. color: red;
  474. transform: scale(0.9);
  475. }
  476. .prom-desc {
  477. margin-left: 15rpx;
  478. }
  479. }
  480. }
  481. }
  482. .evaluation-box-wrap {
  483. background: #f3f3f3;
  484. .evaluation-box {
  485. border-radius: 20rpx 20rpx 0 0;
  486. background: $custom-bg-color;
  487. padding-bottom: 120rpx;
  488. .evaluation-title {
  489. border-radius: 20rpx 20rpx 0 0;
  490. padding: 20rpx 30rpx;
  491. border-bottom: $custom-border-style;
  492. font-size: 30rpx;
  493. }
  494. .evaluation-info {
  495. }
  496. .evan-type-list {
  497. padding: 20rpx;
  498. @include flex-space-around;
  499. .evan-type-item {
  500. border-radius: 8rpx;
  501. padding: 7rpx 12rpx;
  502. background: #f3f3f3;
  503. font-size: 22rpx;
  504. text-align: center;
  505. &.active {
  506. background: #ffffff;
  507. border: 1rpx solid red;
  508. padding: 5rpx 10rpx;
  509. color: red;
  510. }
  511. }
  512. }
  513. .comment-empty {
  514. margin-bottom: 100rpx;
  515. }
  516. }
  517. }
  518. .fixed-btn-box {
  519. position: fixed;
  520. bottom: 0;
  521. left: 0;
  522. .btn-group {
  523. background: $custom-bg-color;
  524. border-top: $custom-border-style;
  525. width: 750rpx;
  526. @include flex-space-around;
  527. height: 100rpx;
  528. .btn-item {
  529. width: 80rpx;
  530. @include flex-center(column);
  531. .btn-text {
  532. font-size: 18rpx;
  533. color: #666666;
  534. }
  535. }
  536. .btn-item-main {
  537. width: 200rpx;
  538. }
  539. }
  540. }
  541. </style>