product.vue 16 KB

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