commodityDetails.vue 16 KB

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