ProductDetails.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <template>
  2. <view class="ProductDetails">
  3. <view class="PDswiper">
  4. <u-swiper class="PDswiper"
  5. height="750rpx"
  6. :list="swiperlist"
  7. indicatorMode="line"
  8. keyName="fileUrl"
  9. circular
  10. indicator
  11. radius='0'
  12. ></u-swiper>
  13. </view>
  14. <view class="menus">
  15. <view class="menus_1">
  16. <view class="menus_1_right">
  17. <text class="mr1">¥</text>
  18. <text class="mr2">{{ ProductDetails.price || 0 }}</text>
  19. <!-- <text class="mr1" v-if="ProductDetails.decimal">{{ '.'+ ProductDetails.decimal }}</text> -->
  20. </view>
  21. <view class="menus_1_left">
  22. 销量: {{ProductDetails.salesVolume || 0}}
  23. </view>
  24. </view>
  25. <!-- <view class="menus_2">
  26. 每满200-30
  27. </view> -->
  28. <view class="menus_3">
  29. {{ProductDetails.title}}
  30. </view>
  31. <view class="menus_4">
  32. {{ProductDetails.subTitle}}
  33. </view>
  34. </view>
  35. <view class="ProductType">
  36. <!-- 商品类型 -->
  37. <ProductType ref="getProductType" :info='ProductDetails' />
  38. </view>
  39. <!-- 评论 -->
  40. <view class="comment">
  41. <view class="commentTop">
  42. <view class="commentTop_left">
  43. 评价 <text class="commentTop_left_num">({{reviewsTotal}})</text>
  44. </view>
  45. <view v-if="reviewsTotal!=0" @click="openLink('ProductEvaluate')" class="commentTop_right">
  46. 全部评论
  47. <u--image width="40rpx" height="40rpx" src="/static/myinfo/btn_right.png" ></u--image>
  48. </view>
  49. </view>
  50. <view v-if="reviewsTotal!=0" class="commentTop">
  51. <view @click="checkCommentbtn(item,index)" :class="iscommentbtn==index?'check_commentbtn':'commentbtn'" v-for="(item,index) in commentbtnList" :key="index">
  52. {{item.name}}
  53. </view>
  54. </view>
  55. <view v-if="reviewsTotal!=0" class="commentTop">
  56. <view class="commentUser">
  57. <view class="Userimg">
  58. <u--image width="60rpx" height="60rpx" src="/static/btn_mine.png" ></u--image>
  59. </view>
  60. <view class="Userimg_r">
  61. <view style="font-size: 28rpx;font-weight: 500;color: #666666;margin-left: 8rpx;">
  62. {{showtypetopl.author}}
  63. </view>
  64. <view>
  65. <u-rate readonly active-color="#ffcf00" inactive-color="#b2b2b2" :count="5" v-model="showtypetopl.score"></u-rate>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view v-if="reviewsTotal!=0" class="commentTop">
  71. <view class="commentcontent">
  72. {{showtypetopl.content}}
  73. </view>
  74. </view>
  75. <view style="margin-top:100rpx" v-if="reviewsTotal==0">
  76. 该商品暂无评价
  77. </view>
  78. </view>
  79. <view class="parseBox">
  80. <view class="parseBox_title">详情</view>
  81. <u-parse class="vHtml" :content="ProductDetails.content"></u-parse>
  82. </view>
  83. <view class="parseBox">
  84. <view class="parseBox_title">服务条款</view>
  85. <u-parse class="vHtml" :content="ProductDetails.serviceTerms"></u-parse>
  86. <!-- <view class="parseBox_item" v-for="(item,index) in TermServiceList" :key="index">
  87. {{item}}
  88. </view> -->
  89. </view>
  90. <view class="tuijian">
  91. <view class="tj_title">为您推荐</view>
  92. <rowList :listdata="newsList" ></rowList>
  93. </view>
  94. <view style="height: 150rpx;"></view>
  95. <view class="bottomMeun">
  96. <view class="bm_item">
  97. <u--image width="48rpx" height="48rpx" src="/static/market/btn_kefu.png" ></u--image>
  98. 客服
  99. </view>
  100. <view @click="toCollection()" class="bm_item">
  101. <u--image width="48rpx" height="48rpx" :src="ProductDetails.favorites?'/static/market/iconm_shoucang.png':'/static/market/btn_shoucang.png'" ></u--image>
  102. {{ProductDetails.favorites?'取消':'收藏'}}
  103. </view>
  104. <view @click="openLink('market')" class="bm_item" style="position: relative">
  105. <u--image width="48rpx" height="48rpx" src="/static/market/btn_gouwc.png" ></u--image>
  106. 购物车
  107. <view class="gouwudot" v-if="shoppingCartTotal!=0" >
  108. {{ shoppingCartTotal }}
  109. </view>
  110. </view>
  111. <view class="bm_btn">
  112. <view @click="addShoppingCart()" class="bm_btn1">加入购物车</view>
  113. <view @click="openLink('market')" class="bm_btn2">去结算</view>
  114. </view>
  115. </view>
  116. </view>
  117. </template>
  118. <script>
  119. import {productPage,productdetail,productcollection,reviewsPage,addShoppingCart,cancelCollection} from '@/http/api/common.js'
  120. import rowList from '@/pages/market/base/rowList.vue' //左右布局
  121. import ProductType from './base/ProductType.vue'
  122. import * as util from '@/pages/util/util.js'
  123. export default {
  124. components:{
  125. rowList,
  126. ProductType
  127. },
  128. data() {
  129. return {
  130. newsList:[],
  131. rateValue:5,
  132. reviewsTotal:'0',
  133. swiperlist:[],
  134. TermServiceList:[],
  135. ProductDetails:{
  136. title:'',
  137. DESCRIPTION:'',
  138. serviceTerms:'',
  139. num:'999',
  140. decimal:"99",
  141. xiaoliang:'999',
  142. newsHtml:'',
  143. favorites:false
  144. },
  145. commentbtnList:[
  146. {
  147. name:'全部',
  148. key:''
  149. },
  150. {
  151. name:'好评',
  152. key:'3'
  153. },
  154. {
  155. name:'中评',
  156. key:'2'
  157. },
  158. {
  159. name:'差评',
  160. key:'1'
  161. },
  162. ],
  163. iscommentbtn:0,
  164. showtypetopl:{
  165. author:'',
  166. score:5,
  167. content:''
  168. },
  169. shoppingCartTotal:0,
  170. badgetype:'warning'
  171. }
  172. },
  173. async onLoad(e) {
  174. if (e?.id) {
  175. //获取商品详情
  176. await this.getproductdetail(e?.id)
  177. //获取两条推荐商品
  178. await this.getProductPage()
  179. //获取评论列表
  180. await this.getreviewsPage()
  181. }
  182. this.shoppingCartTotal = uni.getStorageSync('shoppingCartTotal')
  183. },
  184. methods: {
  185. async getProductPage(){
  186. let data = {
  187. priceAsc:false, //价格正序排序
  188. priceDesc:false, //价格倒序排序
  189. salesVolumeDesc:false, //销量倒序排序
  190. keyword:'', //标题,副标题搜索
  191. pageSize:2,
  192. pageNum:1,
  193. categoryId:this.ProductDetails.categoryId //类目id
  194. }
  195. let res = await productPage(data)
  196. if (res.data.code == 200) {
  197. let newrows = res.data.data?.rows || []
  198. this.newsList.push(...newrows)
  199. }
  200. },
  201. async getproductdetail(id){
  202. let res = await productdetail(id)
  203. if (res.data.code == 200) {
  204. this.ProductDetails = res.data.data
  205. if (this.ProductDetails.status == '0') {
  206. //状态为0 表示商品已下架
  207. util.toastFunc('该商品已下架',()=>{
  208. // 返回上一级
  209. uni.navigateBack({
  210. delta: 1
  211. });
  212. })
  213. }
  214. // 商品轮播图
  215. this.swiperlist = res.data.data?.fileList || []
  216. //服务条款
  217. // if (res.data.data?.serviceTerms) {
  218. // this.TermServiceList = res.data.data?.serviceTerms.split(',')
  219. // }
  220. }else{
  221. util.toastFunc('该商品已下架',()=>{
  222. //请求商品详情失败 返回上一页
  223. uni.navigateBack({ delta: 1 })
  224. })
  225. }
  226. },
  227. async toCollection(){
  228. //收藏
  229. let res = null
  230. if (this.ProductDetails.favorites) {
  231. // favorites true 为收藏过了 调用取消收藏接口
  232. res = await cancelCollection(this.ProductDetails.id)
  233. }else{
  234. res = await productcollection(this.ProductDetails.id)
  235. }
  236. if (res.data.code == 200) {
  237. let title = this.ProductDetails.favorites ? '取消收藏成功' :'收藏成功'
  238. uni.showToast({
  239. title: title,
  240. duration: 2000
  241. });
  242. this.ProductDetails.favorites = !this.ProductDetails.favorites
  243. }
  244. },
  245. async getreviewsPage(){
  246. //获取评论列表
  247. // 1=差评;2=中评;3=好评
  248. let res = await reviewsPage({
  249. rating:'',
  250. productId:this.ProductDetails.id
  251. })
  252. if (res.data.code == 200) {
  253. this.plList = res.data.data.rows
  254. this.reviewsTotal = res.data.data.total
  255. //默认选中全部类型
  256. this.checkCommentbtn(this.commentbtnList[0],0)
  257. }
  258. },
  259. checkCommentbtn(item,index){
  260. this.iscommentbtn = index
  261. if (item.key != '') {
  262. this.showtypetopl = this.plList.find(v=>v.rating == item.key)
  263. }else{
  264. this.showtypetopl = this.plList[0]
  265. }
  266. // //去评论列表
  267. // uni.navigateTo({
  268. // url: '/pages/market/ProductEvaluate?checkindex='+index
  269. // });
  270. },
  271. async addShoppingCart(){
  272. //加入购物车
  273. if (this.$refs?.getProductType?.popupShow) {
  274. let refgetData = this.$refs?.getProductType?.getCheckData()
  275. if (refgetData) {
  276. // if (refgetData.num == '') {
  277. // util.toastFunc('请选择商品数量')
  278. // return
  279. // }
  280. // if (refgetData.porList.length>0) {
  281. // console.log('refgetData.porList',refgetData.porList);
  282. // let findQuantity = refgetData.porList.find(v => v.quantity == '')
  283. // console.log(findQuantity);
  284. // if (!findQuantity) {
  285. // util.toastFunc('配方数量不能为空')
  286. // return
  287. // }
  288. // }
  289. let data = {
  290. productId:this.ProductDetails.id , //产品id
  291. specsId:refgetData.specsId, //规格id
  292. num:refgetData.num , //个数
  293. porList:refgetData.porList//配方id列表
  294. }
  295. let res = await addShoppingCart(data)
  296. if (res.data.code == 200) {
  297. this.$refs?.getProductType?.close()
  298. uni.showToast({
  299. title: '添加购物车成功',
  300. duration: 2000
  301. });
  302. }
  303. }
  304. }else{
  305. this.$refs?.getProductType?.openPopup()
  306. }
  307. },
  308. openLink(type){
  309. if (type == 'market') {
  310. //去购物车
  311. uni.switchTab({
  312. url: '/pages/market/market'
  313. });
  314. }else if (type == 'ProductEvaluate') {
  315. //去评论列表
  316. uni.navigateTo({
  317. url: '/pages/market/ProductEvaluate?id='+this.ProductDetails.id
  318. });
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style>
  325. .ProductDetails{
  326. width: 750rpx;
  327. min-height: 100vh;
  328. background: #F1F1F1;
  329. display: flex;
  330. flex-direction: column;
  331. align-items: center;
  332. }
  333. .PDswiper{
  334. width: 750rpx;
  335. height: 750rpx;
  336. }
  337. .menus{
  338. width: 702rpx;
  339. max-height: 348rpx;
  340. background: #FFFFFF;
  341. border-radius: 16rpx 16rpx 16rpx 16rpx;
  342. opacity: 1;
  343. margin-top: 24rpx;
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. }
  348. .menus_1{
  349. width: 654rpx;
  350. display: flex;
  351. justify-content: space-between;
  352. align-items: flex-end;
  353. margin-top: 24rpx;
  354. }
  355. .menus_1_right{
  356. display: flex;
  357. align-items: center;
  358. }
  359. .mr1{
  360. height: 33rpx;
  361. font-size: 28rpx;
  362. font-weight: bold;
  363. color: #F6514F;
  364. line-height: 36rpx;
  365. }
  366. .mr2{
  367. height: 47rpx;
  368. font-size: 40rpx;
  369. font-weight: bold;
  370. color: #F6514F;
  371. line-height: 36rpx;
  372. }
  373. .menus_1_left{
  374. width: 123rpx;
  375. height: 40rpx;
  376. font-size: 28rpx;
  377. font-weight: 500;
  378. color: #999999;
  379. line-height: 36rpx;
  380. }
  381. .menus_2{
  382. width: 654rpx;
  383. height: 64rpx;
  384. background: #FFEDEC;
  385. border-radius: 8rpx 8rpx 8rpx 8rpx;
  386. margin-top: 24rpx;
  387. }
  388. .menus_3{
  389. width: 640rpx;
  390. max-height: 85rpx;
  391. font-size: 32rpx;
  392. font-weight: bold;
  393. color: #333333;
  394. line-height: 40rpx;
  395. margin-top: 24rpx;
  396. display: -webkit-box;
  397. word-break: break-all;
  398. text-overflow: ellipsis;
  399. overflow: hidden;
  400. -webkit-box-orient: vertical;
  401. -webkit-line-clamp:2;
  402. }
  403. .menus_4{
  404. width: 640rpx;
  405. min-height: 40rpx;
  406. font-size: 28rpx;
  407. font-weight: 500;
  408. color: #666666;
  409. line-height: 40rpx;
  410. margin: 24rpx 0;
  411. /* display: -webkit-box;
  412. word-break: break-all;
  413. text-overflow: ellipsis;
  414. overflow: hidden;
  415. -webkit-box-orient: vertical;
  416. -webkit-line-clamp:1; */
  417. }
  418. .ProductType{
  419. margin-top: 24rpx;
  420. }
  421. .comment{
  422. width: 702rpx;
  423. height: 434rpx;
  424. background: #FFFFFF;
  425. border-radius: 16rpx 16rpx 16rpx 16rpx;
  426. display: flex;
  427. flex-direction: column;
  428. align-items: center;
  429. }
  430. .commentTop{
  431. width: 640rpx;
  432. min-height: 45rpx;
  433. margin-top: 24rpx;
  434. display: flex;
  435. justify-content: space-between;
  436. }
  437. .commentTop_left{
  438. width: 220rpx;
  439. height: 45rpx;
  440. font-size: 32rpx;
  441. font-weight: bold;
  442. color: #333333;
  443. line-height: 36rpx;
  444. display: flex;
  445. justify-content: space-between;
  446. }
  447. .commentTop_left_num{
  448. width: 124rpx;
  449. height: 37rpx;
  450. font-size: 28rpx;
  451. font-weight: 500;
  452. color: #999999;
  453. line-height: 36rpx;
  454. }
  455. .commentTop_right{
  456. display: flex;
  457. width: 160rpx;
  458. height: 40rpx;
  459. font-size: 28rpx;
  460. font-weight: 500;
  461. color: #999999;
  462. line-height: 36rpx;
  463. }
  464. .commentbtn{
  465. width: 151rpx;
  466. height: 64rpx;
  467. background: #DDDDDD;
  468. border-radius: 60rpx 60rpx 60rpx 60rpx;
  469. opacity: 1;
  470. font-size: 28rpx;
  471. font-weight: 500;
  472. color: #666666;
  473. line-height: 64rpx;
  474. text-align: center;
  475. }
  476. .check_commentbtn{
  477. width: 151rpx;
  478. height: 64rpx;
  479. background: #46A6FF;
  480. border-radius: 60rpx 60rpx 60rpx 60rpx;
  481. opacity: 1;
  482. font-size: 28rpx;
  483. font-weight: 500;
  484. color: #FFF;
  485. line-height: 64rpx;
  486. text-align: center;
  487. }
  488. .commentcontent{
  489. width: 644rpx;
  490. height: 80rpx;
  491. font-size: 28rpx;
  492. font-weight: 500;
  493. color: #333333;
  494. line-height: 40rpx;
  495. display: -webkit-box;
  496. word-break: break-all;
  497. text-overflow: ellipsis;
  498. overflow: hidden;
  499. -webkit-box-orient: vertical;
  500. -webkit-line-clamp:2;
  501. }
  502. .Userimg{
  503. width: 80rpx;
  504. height: 80rpx;
  505. background: #EEEEEE;
  506. border-radius: 50%;
  507. display: flex;
  508. align-items: center;
  509. justify-content: center;
  510. }
  511. .commentUser{
  512. display: flex;
  513. }
  514. .Userimg_r{
  515. margin-left: 24rpx;
  516. }
  517. .parseBox{
  518. width: 702rpx;
  519. background: #FFFFFF;
  520. border-radius: 16rpx 16rpx 16rpx 16rpx;
  521. margin-top: 24rpx;
  522. display: flex;
  523. flex-direction: column;
  524. align-items: center;
  525. }
  526. .parseBox_title{
  527. width: 654rpx;
  528. height: 45rpx;
  529. font-size: 32rpx;
  530. font-weight: bold;
  531. color: #333333;
  532. line-height: 36rpx;
  533. margin-top: 24rpx;
  534. }
  535. .vHtml{
  536. width: 654rpx;
  537. margin: 24rpx 0;
  538. }
  539. .vHtml >>> img {
  540. vertical-align: middle;
  541. border-style: none;
  542. width: 100%;
  543. height: auto;
  544. }
  545. .TermService{
  546. margin-top: 24rpx;
  547. width: 702rpx;
  548. height: 410rpx;
  549. background: #FFFFFF;
  550. border-radius: 16rpx 16rpx 16rpx 16rpx;
  551. display: flex;
  552. flex-direction: column;
  553. align-items: center;
  554. }
  555. .parseBox_item{
  556. margin-top: 24rpx;
  557. width: 640rpx;
  558. height: 76rpx;
  559. font-size: 28rpx;
  560. font-weight: 500;
  561. color: #333333;
  562. line-height: 36rpx;
  563. }
  564. .tuijian{
  565. margin-top: 24rpx;
  566. /* background: #FFFFFF; */
  567. }
  568. .tj_title{
  569. font-size: 36rpx;
  570. font-weight: bold;
  571. color: #333333;
  572. text-align: center;
  573. margin-top: 24rpx;
  574. }
  575. .bottomMeun{
  576. width: 750rpx;
  577. height: 98rpx;
  578. background: #FFFFFF;
  579. border-radius: 0rpx 0rpx 0rpx 0rpx;
  580. opacity: 1;
  581. position: fixed;
  582. z-index: 10088;
  583. bottom: 0;
  584. display: flex;
  585. flex-direction: row;
  586. align-items: center;
  587. justify-content: space-between;
  588. }
  589. .bm_item{
  590. width: 80rpx;
  591. display: flex;
  592. flex-direction: column;
  593. align-items: center;
  594. font-size: 24rpx;
  595. font-weight: bold;
  596. color: #666666;
  597. line-height: 36rpx;
  598. }
  599. .bm_btn{
  600. display: flex;
  601. flex-direction: row;
  602. align-items: center;
  603. width: 450rpx;
  604. height: 72rpx;
  605. justify-content: space-evenly;
  606. }
  607. .bm_btn1{
  608. width: 200rpx;
  609. height: 72rpx;
  610. background: #FFB048;
  611. border-radius: 60rpx 60rpx 60rpx 60rpx;
  612. opacity: 1;
  613. font-size: 28rpx;
  614. font-weight: 500;
  615. color: #FFFFFF;
  616. line-height: 72rpx;
  617. text-align: center;
  618. }
  619. .bm_btn2{
  620. width: 200rpx;
  621. height: 72rpx;
  622. background: #46A6FF;
  623. border-radius: 60rpx 60rpx 60rpx 60rpx;
  624. opacity: 1;
  625. font-size: 28rpx;
  626. font-weight: 500;
  627. color: #FFFFFF;
  628. line-height: 72rpx;
  629. text-align: center;
  630. }
  631. .gouwudot{
  632. position: absolute;
  633. right: -8rpx;
  634. color: #fff;
  635. width: 32rpx;
  636. height: 32rpx;
  637. background: red;
  638. font-size: 20rpx;
  639. line-height: 32rpx;
  640. border-radius: 50%;
  641. text-align: center;
  642. }
  643. </style>