product.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. productSpu(this.product.id).then(res => {
  298. this.product.images = res.data.picUrls;
  299. this.product.sku = res.data.skus;
  300. this.product.desc = res.data.description.replace(/<[^>]*>/g,'');
  301. this.product.price = res.data.price;
  302. this.product.title = res.data.name;
  303. console.log(res)
  304. })
  305. },
  306. handleSkuItemClick(index) {
  307. this.currentSkuIndex = index
  308. },
  309. handleCouponClick() {
  310. // TODO 未登录去登录,登录则跳转优惠券页面
  311. },
  312. handleEvanTypeClick(index) {
  313. this.currentEvanIndex = index
  314. // TODO 展示评论
  315. }
  316. },
  317. computed: {
  318. hasLogin() {
  319. return this.$store.getters.hasLogin
  320. }
  321. }
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. .indicator-num {
  326. @include flex-center;
  327. padding: 2px 0;
  328. background-color: rgba(0, 0, 0, 0.35);
  329. border-radius: 100px;
  330. width: 35px;
  331. &__text {
  332. color: #ffffff;
  333. font-size: 12px;
  334. }
  335. }
  336. .product-box {
  337. padding: 40rpx 40rpx 10rpx 40rpx;
  338. @include flex;
  339. border-bottom: $custom-border-style;
  340. .prod-info {
  341. padding-right: 30rpx;
  342. .info-text {
  343. padding-bottom: 10rpx;
  344. }
  345. .price-and-cart {
  346. @include flex-space-between;
  347. }
  348. }
  349. .prod-favor {
  350. margin-top: 15rpx;
  351. }
  352. }
  353. .row-box {
  354. @include flex-left;
  355. padding: 0 30rpx;
  356. height: 70rpx;
  357. .row-left {
  358. width: 70rpx;
  359. font-size: 24rpx;
  360. color: #939393;
  361. }
  362. .row-right {
  363. @include flex-space-between;
  364. flex: 1;
  365. .row-content {
  366. flex: 1;
  367. .delivery-box {
  368. @include flex-left;
  369. .delivery-item {
  370. margin-right: 20rpx;
  371. @include flex-left;
  372. font-size: 22rpx;
  373. .delivery-name {
  374. margin-left: 5rpx;
  375. }
  376. }
  377. }
  378. .prom-box {
  379. @include flex-left;
  380. .prom-item {
  381. @include flex-left;
  382. font-size: 22rpx;
  383. .prom-title {
  384. padding: 1rpx 10rpx;
  385. border: 1rpx solid red;
  386. border-radius: 5rpx;
  387. color: red;
  388. transform: scale(0.9);
  389. }
  390. .prom-desc {
  391. margin-left: 15rpx;
  392. }
  393. }
  394. }
  395. .coupon-box {
  396. @include flex-space-between;
  397. .coupon-list {
  398. @include flex-left;
  399. .coupon-item {
  400. @include flex-left;
  401. font-size: 22rpx;
  402. .coupon-desc {
  403. padding: 2rpx 15rpx;
  404. margin-right: 15rpx;
  405. background: red;
  406. color: #ffffff;
  407. }
  408. }
  409. }
  410. .coupon-total {
  411. color: #939393;
  412. font-size: 12rpx;
  413. padding: 0 15rpx;
  414. }
  415. }
  416. .sku-box {
  417. @include flex-space-between;
  418. .sku-item {
  419. @include flex-left;
  420. font-size: 22rpx;
  421. .sku-desc {
  422. margin-left: 15rpx;
  423. font-weight: 700;
  424. }
  425. }
  426. }
  427. }
  428. .row-more {
  429. @include flex-right;
  430. width: 30rpx;
  431. }
  432. }
  433. }
  434. .sku-popup-slot {
  435. width: 750rpx;
  436. .current-sku-info {
  437. @include flex;
  438. padding: 30rpx 100rpx 0 30rpx;
  439. .current-sku-img {
  440. border-radius: 10rpx;
  441. /deep/ * {
  442. border-radius: 10rpx;
  443. }
  444. }
  445. .current-sku-desc {
  446. padding: 0 30rpx;
  447. font-size: 28rpx;
  448. .current-sku-stock {
  449. height: 40rpx;
  450. line-height: 40rpx;
  451. color: #666666;
  452. font-size: 24rpx;
  453. }
  454. }
  455. }
  456. .sku-selection {
  457. margin: 30rpx;
  458. font-size: 26rpx;
  459. color: #939393;
  460. .sku-item {
  461. margin-bottom: 20rpx;
  462. border-radius: 6rpx;
  463. padding: 5rpx 15rpx;
  464. border: 1rpx solid #e3e3e3;
  465. width: fit-content !important;
  466. &.active {
  467. color: #666666;
  468. border: 1rpx solid #666666;
  469. }
  470. }
  471. }
  472. .sku-num-box {
  473. @include flex-space-between padding: 30rpx;
  474. .text {
  475. font-size: 30rpx;
  476. }
  477. }
  478. .sku-btn-group {
  479. @include flex-space-around;
  480. height: 100rpx;
  481. .btn-item-main {
  482. width: 350rpx;
  483. }
  484. }
  485. }
  486. .prom-popup-slot {
  487. width: 750rpx;
  488. min-height: 500rpx;
  489. .prom-info {
  490. background: #f3f3f3;
  491. line-height: 90rpx;
  492. padding-left: 30rpx;
  493. font-size: 36rpx;
  494. border-radius: 10px 10px 0 0;
  495. }
  496. .prom-list {
  497. padding: 30rpx;
  498. .prom-item {
  499. @include flex-left;
  500. font-size: 22rpx;
  501. margin-bottom: 15rpx;
  502. .prom-title {
  503. padding: 1rpx 10rpx;
  504. border: 1rpx solid red;
  505. border-radius: 5rpx;
  506. color: red;
  507. transform: scale(0.9);
  508. }
  509. .prom-desc {
  510. margin-left: 15rpx;
  511. }
  512. }
  513. }
  514. }
  515. .evaluation-box-wrap {
  516. background: #f3f3f3;
  517. .evaluation-box {
  518. border-radius: 20rpx 20rpx 0 0;
  519. background: $custom-bg-color;
  520. padding-bottom: 120rpx;
  521. .evaluation-title {
  522. border-radius: 20rpx 20rpx 0 0;
  523. padding: 20rpx 30rpx;
  524. border-bottom: $custom-border-style;
  525. font-size: 30rpx;
  526. }
  527. .evaluation-info {
  528. }
  529. .evan-type-list {
  530. padding: 20rpx;
  531. @include flex-space-around;
  532. .evan-type-item {
  533. border-radius: 8rpx;
  534. padding: 7rpx 12rpx;
  535. background: #f3f3f3;
  536. font-size: 22rpx;
  537. text-align: center;
  538. &.active {
  539. background: #ffffff;
  540. border: 1rpx solid red;
  541. padding: 5rpx 10rpx;
  542. color: red;
  543. }
  544. }
  545. }
  546. .comment-empty {
  547. margin-bottom: 100rpx;
  548. }
  549. }
  550. }
  551. .fixed-btn-box {
  552. position: fixed;
  553. bottom: 0;
  554. left: 0;
  555. .btn-group {
  556. background: $custom-bg-color;
  557. border-top: $custom-border-style;
  558. width: 750rpx;
  559. @include flex-space-around;
  560. height: 100rpx;
  561. .btn-item {
  562. width: 80rpx;
  563. @include flex-center(column);
  564. .btn-text {
  565. font-size: 18rpx;
  566. color: #666666;
  567. }
  568. }
  569. .btn-item-main {
  570. width: 200rpx;
  571. }
  572. }
  573. }
  574. </style>