commodityDetails.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <template>
  2. <view>
  3. <ujp-navbar :title="info.mallProduct.name"></ujp-navbar>
  4. <!--轮播图 -->
  5. <u-swiper :list="albumPics" height="550" img-mode="scaleToFill"></u-swiper>
  6. <!-- 详情 -->
  7. <view class="main">
  8. <!-- 价格 已售 -->
  9. <view class="price-sold" >
  10. <view class="price" v-if="info.mallProductPrice">
  11. <text>¥</text>{{info.mallProductPrice}}<text style="margin-left: 4rpx;">起</text>
  12. </view>
  13. <view class="sold" v-if="info.mallProduct.sale">
  14. 已售 {{info.mallProduct.sale}}
  15. </view>
  16. </view>
  17. <!-- 标题 -->
  18. <view class="title">
  19. <view class="tag" v-if="info.mallProduct.own">
  20. <img src="../../assets/img/commodityTag.png" alt="">
  21. </view>{{info.mallProduct.name}}
  22. </view>
  23. <!-- 详细信息 -->
  24. <view class="infos" @click="show=true">
  25. <view class="item" v-for="(item, i) in mallProductAttributeListShow" :key="i">
  26. <view class="item-title">
  27. {{i}}
  28. </view>
  29. <view class="item-value">
  30. {{item}}
  31. </view>
  32. </view>
  33. <view class="item">
  34. <u-icon name="arrow-right" color="#333333"></u-icon>
  35. </view>
  36. </view>
  37. </view>
  38. <u-divider color="#aaaaaa">商品详情</u-divider>
  39. <!-- 商品详情图片 -->
  40. <view class="details-picture" v-html="info.mallProduct.detailHtml">
  41. </view>
  42. <!-- 底部 -->
  43. <view class="bottom" v-if="personInfo.id" >
  44. <view class="service" @click="gotoUrl('pages/service/service')">
  45. <view class="icon">
  46. <img src="../../assets/img/riLine-customer-service-2-line@3x.png" alt="">
  47. </view>
  48. <view class="text">
  49. 联系客服
  50. </view>
  51. </view>
  52. <view class="order" @click="gotoUrl('pages/store/myOrder')">
  53. <view class="icon">
  54. <img src="../../assets/img/riLine-todo-line@3x.png" alt="">
  55. </view>
  56. <view class="text">
  57. 我的订单
  58. </view>
  59. </view>
  60. <view class="buy-btn" @click="show2=true">
  61. <view class="buy">
  62. 立即购买
  63. </view>
  64. <view class="price">
  65. {{personInfo.memberLevelStr}}价 ¥{{mallProductPrice}}
  66. </view>
  67. </view>
  68. </view>
  69. <view class="bottom" v-else >
  70. <view class="service" @click="gotoUrl('pages/service/service')">
  71. <view class="icon">
  72. <img src="../../assets/img/riLine-customer-service-2-line@3x.png" alt="">
  73. </view>
  74. <view class="text">
  75. 联系客服
  76. </view>
  77. </view>
  78. <view class="buy-btn" @click="gotoUrl('pages/login/login')">
  79. <view class="buy">
  80. 立即登录
  81. </view>
  82. <view class="price">
  83. 登录后购买商品
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 产品参数 -->
  88. <u-popup v-model="show" mode="bottom" height="80%" >
  89. <view class="product-parameter">
  90. <view class="headline">
  91. 产品参数
  92. </view>
  93. <view class="infos">
  94. <view class="item" v-for="(item,i) in info.mallProductAttributeList" :key="i">
  95. <view class="title">
  96. {{i}}
  97. </view>
  98. <view class="value">
  99. {{item}}
  100. </view>
  101. </view>
  102. </view>
  103. <view class="btn" @click="show=false">
  104. <button class="finish">完成</button>
  105. </view>
  106. </view>
  107. </u-popup>
  108. <!-- 选择规格 -->
  109. <u-popup v-model="show2" mode="bottom" :closeable="true" height="80%" >
  110. <view class="product-parameter">
  111. <view class="headline">
  112. <view class="specification-head">
  113. <view class="specification-infos">
  114. <view class="picture">
  115. <img v-if="info.mallProduct.pic" :src="info.mallProduct.pic" alt="">
  116. <img v-else src="@/assets/img/chargesite_default.png" ></img>
  117. </view>
  118. <view class="else-infos">
  119. <view class="name">
  120. {{info.mallProduct.name}}
  121. </view>
  122. <view class="price">
  123. {{info.mallProductPrice}}元 起
  124. </view>
  125. <view class="choose">
  126. 请先选择商品规格
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </view>
  132. <view >
  133. <view class="specification">
  134. <!-- 选项 -->
  135. <view class="optopns-content">
  136. <view class="options" v-for="(item,i) in info.mallProductOptionList"
  137. :key="i" >
  138. <view class="options-name">
  139. <span v-if="item.required" style="color: red;">*</span>{{item.name}}
  140. <span class="tag" v-if="item.selectType==2">多选</span>
  141. </view>
  142. <view class="options-item">
  143. <view class="item "
  144. v-for="(it,index) in item.mallProductOpinionPriceDTOList"
  145. @click="itemChosenBtn(it,item)"
  146. :class="{
  147. 'item-chosen' : (ckMallProductOptionList[item.id]?ckMallProductOptionList[item.id]:[]).indexOf(it.value)>-1
  148. }"
  149. :key="index+'_'+i" >
  150. {{it.name}} <span style="margin-left: 8px;" v-if="it.price">{{it.price}}元</span>
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. <view class="bottom">
  156. <view class="service" @click="gotoUrl('pages/service/service')">
  157. <view class="icon">
  158. <img src="../../assets/img/riLine-customer-service-2-line@3x.png" alt="">
  159. </view>
  160. <view class="text">
  161. 联系客服
  162. </view>
  163. </view>
  164. <view class="order" @click="gotoUrl('pages/store/myOrder')" >
  165. <view class="icon">
  166. <img src="../../assets/img/riLine-todo-line@3x.png" alt="">
  167. </view>
  168. <view class="text">
  169. 我的订单
  170. </view>
  171. </view>
  172. <view class="buy-btn" @click="submit">
  173. <view class="buy">
  174. 立即购买
  175. </view>
  176. <view class="price">
  177. {{personInfo.memberLevelStr}}价 ¥{{mallProductPrice}}
  178. </view>
  179. </view>
  180. </view>
  181. </view>
  182. </view>
  183. </view>
  184. </u-popup>
  185. </view>
  186. </template>
  187. <script>
  188. import * as API from '@/apis/mall.js'
  189. export default {
  190. data() {
  191. return {
  192. show: false,
  193. show2: false,
  194. info:{
  195. mallProduct:{},
  196. mallProductAttributeList:[],
  197. mallProductOptionList:[],
  198. mallProductPrice:0,
  199. },
  200. ckMallProductOptionList:{},
  201. mallProductPrice:0,
  202. personInfo:{},
  203. id:"",
  204. // albumPics: [{
  205. // image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
  206. // },
  207. // {
  208. // image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
  209. // },
  210. // {
  211. // image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
  212. // }
  213. // ],
  214. }
  215. },
  216. computed:{
  217. mallProductAttributeListShow(){
  218. var sz=this.info.mallProductAttributeList;
  219. if(sz){
  220. var obj={}
  221. var k=0
  222. for(var i in sz){
  223. k++;
  224. obj[i]=sz[i]
  225. if(k==5){
  226. break
  227. }
  228. }
  229. return obj;
  230. }else{
  231. return []
  232. }
  233. },
  234. albumPics(){
  235. var list=[]
  236. if(this.info.mallProduct&&this.info.mallProduct.id){
  237. var plist=this.info.mallProduct.albumPics
  238. if(plist){
  239. var sz=plist.split(",").map(item=>{
  240. return {
  241. image:item
  242. }
  243. })
  244. list=sz
  245. }else if(this.info.mallProduct.pic){
  246. list.push({
  247. image:this.info.mallProduct.pic
  248. })
  249. }
  250. }
  251. return list
  252. }
  253. },
  254. onLoad(op) {
  255. this.personInfo = this.carhelp.getPersonInfo()
  256. if (op.id) {
  257. this.id = op.id;
  258. this.getDetail();
  259. }
  260. },
  261. methods: {
  262. submit(){
  263. var opinions="";
  264. for(var i in this.ckMallProductOptionList){
  265. var item=this.ckMallProductOptionList[i]
  266. if(item.length==0){
  267. continue
  268. }
  269. var string=i+":"+item.join()+";"
  270. opinions+=string;
  271. }
  272. uni.navigateTo({
  273. url:"/pages/store/orderConfirm?id="+this.id+"&opinions="+opinions
  274. })
  275. },
  276. itemChosenBtn(it,item){
  277. var sz=this.ckMallProductOptionList[item.id]
  278. var ck=sz.indexOf(it.value)
  279. //debugger
  280. if(ck>-1){
  281. var bl=false
  282. //已选中, 要取消
  283. if(item.required==1||item.selectType==0){
  284. if(sz.length==1){
  285. //不能取消
  286. }else{
  287. //可以取消
  288. bl=true
  289. }
  290. }else{
  291. //可以取消
  292. bl=true
  293. }
  294. if(bl){
  295. sz.splice(ck, 1);
  296. }
  297. }else{
  298. if(item.selectType==2){
  299. sz.push(it.value)
  300. }else{
  301. sz=[it.value]
  302. }
  303. }
  304. this.ckMallProductOptionList[item.id]=sz;
  305. this.setTotalAmount()
  306. },
  307. setTotalAmount(){
  308. this.mallProductPrice=0;
  309. if(this.info.mallProduct.id){
  310. this.mallProductPrice+=this.info.mallProductPrice
  311. for(var i in this.info.mallProductOptionList){
  312. var item=this.info.mallProductOptionList[i];
  313. //obj.selectType 0->唯一;1->单选;2->多选
  314. //obj.required
  315. var sz=this.ckMallProductOptionList[item.id]
  316. for(var j in item.mallProductOpinionPriceDTOList){
  317. var it=item.mallProductOpinionPriceDTOList[j]
  318. if(sz.indexOf(it.value)>-1){
  319. this.mallProductPrice+=it.price
  320. }
  321. }
  322. }
  323. }
  324. if(this.mallProductPrice){
  325. if(Number.isInteger(this.mallProductPrice)){
  326. }else{
  327. this.mallProductPrice=this.mallProductPrice.toFixed(2);
  328. }
  329. }else{
  330. this.mallProductPrice=0
  331. }
  332. },
  333. getDetail(){
  334. uni.showLoading({
  335. title: "加载中",
  336. mask: true,
  337. })
  338. API.mallDetails({
  339. id:this.id
  340. }).then((res) => {
  341. uni.hideLoading();
  342. this.info=res.data
  343. if(this.info.mallProductOptionList){
  344. var obj={}
  345. //this.ckMallProductOptionList;
  346. for(var i in this.info.mallProductOptionList){
  347. var item=this.info.mallProductOptionList[i];
  348. //obj.selectType 0->唯一;1->单选;2->多选
  349. //obj.required
  350. obj[item.id]=[]
  351. if(item.mallProductOpinionPriceDTOList&&item.mallProductOpinionPriceDTOList.length>0){
  352. if(item.required==1||item.selectType==0){
  353. obj[item.id].push(item.mallProductOpinionPriceDTOList[0].value)
  354. }
  355. }
  356. }
  357. this.ckMallProductOptionList=obj
  358. this.setTotalAmount()
  359. }
  360. this.$nextTick(()=>{
  361. var list =document.getElementsByClassName("details-picture")[0].getElementsByTagName("img");
  362. for(var i=0;i<list.length;i++){
  363. list[i].style='width: 100%;height: 100%;'
  364. }
  365. })
  366. }).catch(error => {
  367. uni.showToast({
  368. title: error,
  369. icon: "none"
  370. })
  371. })
  372. }
  373. }
  374. }
  375. </script>
  376. <style lang="scss" scoped>
  377. page {
  378. padding-bottom: 50px;
  379. }
  380. .main {
  381. background-color: #fff;
  382. padding: 32rpx 24rpx;
  383. // 价格 已售
  384. .price-sold {
  385. display: flex;
  386. justify-content: space-between;
  387. align-items: center;
  388. .price {
  389. color: rgba(255, 40, 0, 1);
  390. font-size: 48rpx;
  391. text {
  392. font-size: 24rpx
  393. }
  394. }
  395. .sold {
  396. color: rgba(119, 119, 119, 1);
  397. }
  398. }
  399. // 标题
  400. .title {
  401. color: rgba(16, 16, 16, 1);
  402. margin-top: 40rpx;
  403. font-size: 40rpx;
  404. font-weight: 600;
  405. .tag {
  406. display: inline-block;
  407. margin-right: 8rpx;
  408. img {
  409. width: 118rpx;
  410. height: 36rpx;
  411. }
  412. }
  413. }
  414. // 详细信息
  415. .infos {
  416. margin: 32rpx 0rpx;
  417. padding: 32rpx 16rpx;
  418. border-radius: 8px;
  419. background-color: rgba(244, 246, 248, 1);
  420. display: flex;
  421. align-items: center;
  422. justify-content: space-between;
  423. .item {
  424. // margin-left: 16rpx;
  425. text-align: center;
  426. .item-title {
  427. color: rgba(119, 119, 119, 1);
  428. }
  429. .item-value {
  430. color: rgba(51, 51, 51, 1);
  431. font-size: 32rpx;
  432. margin-top: 16rpx;
  433. }
  434. }
  435. }
  436. }
  437. // 商品详情图片
  438. .details-picture {
  439. background-color: #fff;
  440. padding-bottom: 100px;
  441. img {
  442. width: 100%;
  443. }
  444. }
  445. // 底部
  446. .bottom {
  447. position: fixed;
  448. bottom: 0;
  449. left: 0;
  450. right: 0;
  451. background-color: #fff;
  452. box-shadow: 0px -6px 6px 0px rgba(0, 0, 0, 0.05);
  453. display: flex;
  454. align-items: center;
  455. padding: 30rpx 40rpx;
  456. .service,
  457. .order {
  458. text-align: center;
  459. margin-right: 32rpx;
  460. img {
  461. width: 40rpx;
  462. height: 40rpx;
  463. }
  464. .text {
  465. color: rgba(16, 16, 16, 1);
  466. font-size: 24rpx;
  467. }
  468. }
  469. .buy-btn{
  470. width: 400rpx;
  471. height: 96rpx;
  472. border-radius: 50px;
  473. background-color: rgba(0, 185, 98, 1);
  474. text-align: center;
  475. display: flex;
  476. flex-direction: column;
  477. justify-content: center;
  478. margin-left: auto;
  479. color: #fff;
  480. .buy {
  481. font-size: 32rpx
  482. }
  483. .price {
  484. font-size: 24rpx;
  485. }
  486. }
  487. }
  488. // 产品参数
  489. .product-parameter {
  490. padding:0 32rpx 40rpx 32rpx ;
  491. border-radius: 8px;
  492. .headline {
  493. border-radius: 12px 12px 0 0;
  494. font-size: 32rpx;
  495. color: #111111;
  496. text-align: center;
  497. height: 20px;
  498. position: fixed;
  499. top: 0px;
  500. left: 0;
  501. right: 0;
  502. padding: 12px 0;
  503. background: #fff;
  504. }
  505. }
  506. /deep/.u-drawer-content {
  507. border-radius: 12px 12px 0 0;
  508. .infos {
  509. margin: 44rpx 0;
  510. //height: 800rpx;
  511. overflow: auto;
  512. .item {
  513. display: flex;
  514. align-items: center;
  515. font-size: 32rpx;
  516. padding: 28rpx 0;
  517. border-bottom: 1px solid #e6e6e6;
  518. .title {
  519. color: rgba(51, 51, 51, 1);
  520. width: 128rpx;
  521. text-align: left;
  522. }
  523. .value {
  524. color: rgba(51, 51, 51, 1);
  525. margin-left: 48rpx;
  526. }
  527. }
  528. }
  529. // 按钮
  530. .btn {
  531. padding: 16rpx 32rpx;
  532. position: fixed;
  533. left: 0;
  534. right: 0;
  535. bottom: 0;
  536. background: #fff;
  537. .finish {
  538. width: 100%;
  539. height: 80rpx;
  540. background-color: rgba(0, 185, 98, 1);
  541. color: rgba(255, 255, 255, 1);
  542. font-size: 16px;
  543. }
  544. }
  545. }
  546. // 选择规格
  547. .specification-head{
  548. padding: 54rpx 48rpx ;
  549. background: #fff;
  550. .specification-infos{
  551. display: flex;
  552. justify-content: space-between;
  553. //position: fixed;
  554. top: 104rpx;
  555. left: 48rpx;
  556. right: 48rpx;
  557. height: 120rpx;
  558. z-index: 999;
  559. .picture{
  560. width: 152rpx;
  561. height: 152rpx;
  562. img{
  563. width: 100%;
  564. height: 100%;
  565. }
  566. }
  567. .else-infos{
  568. .name{
  569. color: rgba(51, 51, 51, 1);
  570. font-weight: bold;
  571. font-size: 40rpx;
  572. }
  573. .price{
  574. color: rgba(16, 16, 16, 1);
  575. font-size: 32rpx;
  576. margin-top: 12rpx;
  577. font-weight: bold;
  578. }
  579. .choose{
  580. color: rgba(153, 153, 153, 1);
  581. margin-top: 12rpx;
  582. }
  583. }
  584. }
  585. }
  586. // 选择规格
  587. .specification{
  588. margin-top: 120rpx;
  589. padding: 54rpx 28rpx ;
  590. background: #fff;
  591. // 选项
  592. .optopns-content{
  593. margin: 100rpx 0 40rpx;
  594. height: 800rpx;
  595. overflow: auto;
  596. }
  597. .options{
  598. .options-name{
  599. color: rgba(119, 119, 119, 1);
  600. .tag{
  601. background-color: #8D8072;
  602. color: #fff;
  603. padding: 2px 6px;
  604. border-radius: 15px;
  605. font-size: 10px;
  606. }
  607. }
  608. .options-item{
  609. display: flex;
  610. justify-content: space-between;
  611. flex-wrap: wrap;
  612. margin-top: 24rpx;
  613. margin-bottom: 40rpx;
  614. .item{
  615. min-width: 312rpx;
  616. line-height: 64rpx;
  617. border: 1px solid rgba(221, 221, 221, 1);
  618. text-align: center;
  619. color: rgba(51, 51, 51, 1);
  620. font-size: 32rpx;
  621. border-radius: 50px;
  622. margin-bottom: 24rpx;
  623. padding: 0 20px;
  624. }
  625. // 被选中的
  626. .item-chosen{
  627. border: 1px solid #53b56b;
  628. background-color: #53b56b;
  629. color: #fff;
  630. }
  631. }
  632. }
  633. .bottom{
  634. box-shadow: none;
  635. }
  636. }
  637. </style>