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. //debugger
  303. if(ck>-1){
  304. var bl=false
  305. //已选中, 要取消
  306. if(item.required==1||item.selectType==0){
  307. if(sz.length==1){
  308. //不能取消
  309. }else{
  310. //可以取消
  311. bl=true
  312. }
  313. }else{
  314. //可以取消
  315. bl=true
  316. }
  317. if(bl){
  318. sz.splice(ck, 1);
  319. }
  320. }else{
  321. if(item.selectType==2){
  322. sz.push(it.value)
  323. }else{
  324. sz=[it.value]
  325. }
  326. }
  327. this.ckMallProductOptionList[item.id]=sz;
  328. this.setTotalAmount()
  329. },
  330. setTotalAmount(){
  331. this.mallProductPrice=0;
  332. if(this.info.mallProduct.id){
  333. this.mallProductPrice+=this.info.mallProductPrice
  334. for(var i in this.info.mallProductOptionList){
  335. var item=this.info.mallProductOptionList[i];
  336. //obj.selectType 0->唯一;1->单选;2->多选
  337. //obj.required
  338. var sz=this.ckMallProductOptionList[item.id]
  339. for(var j in item.mallProductOpinionPriceDTOList){
  340. var it=item.mallProductOpinionPriceDTOList[j]
  341. if(sz.indexOf(it.value)>-1){
  342. this.mallProductPrice+=it.price
  343. }
  344. }
  345. }
  346. }
  347. if(this.mallProductPrice){
  348. if(Number.isInteger(this.mallProductPrice)){
  349. }else{
  350. this.mallProductPrice=this.mallProductPrice.toFixed(2);
  351. }
  352. }else{
  353. this.mallProductPrice=0
  354. }
  355. },
  356. getDetail(){
  357. uni.showLoading({
  358. title: "加载中",
  359. mask: true,
  360. })
  361. API.mallDetails({
  362. id:this.id
  363. }).then((res) => {
  364. uni.hideLoading();
  365. this.info=res.data
  366. if(this.info.mallProductOptionList){
  367. var obj={}
  368. //this.ckMallProductOptionList;
  369. for(var i in this.info.mallProductOptionList){
  370. var item=this.info.mallProductOptionList[i];
  371. //obj.selectType 0->唯一;1->单选;2->多选
  372. //obj.required
  373. obj[item.id]=[]
  374. if(item.mallProductOpinionPriceDTOList&&item.mallProductOpinionPriceDTOList.length>0){
  375. if(item.required==1||item.selectType==0){
  376. obj[item.id].push(item.mallProductOpinionPriceDTOList[0].value)
  377. }
  378. }
  379. }
  380. this.ckMallProductOptionList=obj
  381. this.setTotalAmount()
  382. }
  383. // this.$nextTick(()=>{
  384. // var list =document.getElementsByClassName("details-picture")[0].getElementsByTagName("img");
  385. // for(var i=0;i<list.length;i++){
  386. // list[i].style='width: 100%;height: 100%;'
  387. // }
  388. // })
  389. }).catch(error => {
  390. uni.showToast({
  391. title: error,
  392. icon: "none"
  393. })
  394. })
  395. }
  396. }
  397. }
  398. </script>
  399. <style lang="scss" scoped>
  400. ::v-deep.u-back-wrap{
  401. background-color: #fff;
  402. }
  403. page {
  404. padding-bottom: 50px;
  405. }
  406. .main {
  407. background-color: #fff;
  408. padding: 32rpx 24rpx;
  409. // 价格 已售
  410. .price-sold {
  411. display: flex;
  412. justify-content: space-between;
  413. align-items: center;
  414. .price {
  415. color: rgba(255, 40, 0, 1);
  416. font-size: 48rpx;
  417. text {
  418. font-size: 24rpx
  419. }
  420. }
  421. .sold {
  422. color: rgba(119, 119, 119, 1);
  423. }
  424. }
  425. // 标题
  426. .title {
  427. color: rgba(16, 16, 16, 1);
  428. margin-top: 40rpx;
  429. font-size: 40rpx;
  430. font-weight: 600;
  431. .tag {
  432. display: inline-block;
  433. margin-right: 8rpx;
  434. img {
  435. width: 118rpx;
  436. height: 36rpx;
  437. }
  438. }
  439. }
  440. // 详细信息
  441. .infos {
  442. margin: 32rpx 0rpx;
  443. padding: 32rpx 16rpx;
  444. border-radius: 8px;
  445. background-color: rgba(244, 246, 248, 1);
  446. display: flex;
  447. align-items: center;
  448. justify-content: space-between;
  449. .item {
  450. // margin-left: 16rpx;
  451. text-align: center;
  452. .item-title {
  453. color: rgba(119, 119, 119, 1);
  454. }
  455. .item-value {
  456. color: rgba(51, 51, 51, 1);
  457. font-size: 32rpx;
  458. margin-top: 16rpx;
  459. }
  460. }
  461. }
  462. }
  463. // 商品详情图片
  464. .details-picture {
  465. background-color: #fff;
  466. padding: 0 40rpx;
  467. padding-bottom: 100px;
  468. ::v-deepimg{
  469. //display: inline-block;
  470. width: 100% !important;
  471. height: 100% !important;
  472. vertical-align: middle
  473. }
  474. }
  475. // 底部
  476. .bottom {
  477. position: fixed;
  478. bottom: 0;
  479. left: 0;
  480. right: 0;
  481. background-color: #fff;
  482. box-shadow: 0px -6px 6px 0px rgba(0, 0, 0, 0.05);
  483. display: flex;
  484. align-items: center;
  485. padding: 30rpx 40rpx;
  486. .service,
  487. .order {
  488. text-align: center;
  489. margin-right: 32rpx;
  490. img {
  491. width: 40rpx;
  492. height: 40rpx;
  493. }
  494. .text {
  495. color: rgba(16, 16, 16, 1);
  496. font-size: 24rpx;
  497. }
  498. }
  499. .buy-btn{
  500. width: 400rpx;
  501. height: 96rpx;
  502. border-radius: 50px;
  503. background-color: rgba(0, 185, 98, 1);
  504. text-align: center;
  505. display: flex;
  506. flex-direction: column;
  507. justify-content: center;
  508. margin-left: auto;
  509. color: #fff;
  510. .buy {
  511. font-size: 32rpx
  512. }
  513. .price {
  514. font-size: 24rpx;
  515. }
  516. }
  517. }
  518. // 产品参数
  519. .product-parameter {
  520. padding:40rpx 32rpx 40rpx 32rpx ;
  521. border-radius: 8px;
  522. .headline {
  523. border-radius: 12px 12px 0 0;
  524. font-size: 32rpx;
  525. color: #111111;
  526. text-align: center;
  527. height: 40rpx;
  528. position: fixed;
  529. top: 0px;
  530. left: 0;
  531. right: 0;
  532. padding: 40rpx 0;
  533. background: #fff;
  534. }
  535. }
  536. ::v-deep.u-drawer-content {
  537. border-radius: 12px 12px 0 0;
  538. .infos {
  539. margin: 44rpx 0;
  540. //height: 800rpx;
  541. overflow: auto;
  542. .item {
  543. display: flex;
  544. align-items: center;
  545. font-size: 32rpx;
  546. padding: 28rpx 0;
  547. border-bottom: 1px solid #e6e6e6;
  548. .title {
  549. color: rgba(51, 51, 51, 1);
  550. width: 128rpx;
  551. text-align: left;
  552. }
  553. .value {
  554. color: rgba(51, 51, 51, 1);
  555. margin-left: 48rpx;
  556. }
  557. }
  558. }
  559. // 按钮
  560. .btn {
  561. padding: 16rpx 32rpx;
  562. position: fixed;
  563. left: 0;
  564. right: 0;
  565. bottom: 0;
  566. background: #fff;
  567. .finish {
  568. width: 100%;
  569. height: 80rpx;
  570. background-color: rgba(0, 185, 98, 1);
  571. color: rgba(255, 255, 255, 1);
  572. font-size: 16px;
  573. }
  574. }
  575. }
  576. // 选择规格
  577. .specification-head{
  578. padding: 54rpx 48rpx ;
  579. background: #fff;
  580. .specification-infos{
  581. display: flex;
  582. justify-content: space-between;
  583. //position: fixed;
  584. top: 104rpx;
  585. left: 48rpx;
  586. right: 48rpx;
  587. height: 120rpx;
  588. z-index: 999;
  589. .picture{
  590. width: 152rpx;
  591. height: 152rpx;
  592. img{
  593. width: 100%;
  594. height: 100%;
  595. }
  596. }
  597. .else-infos{
  598. .name{
  599. color: rgba(51, 51, 51, 1);
  600. font-weight: bold;
  601. font-size: 40rpx;
  602. }
  603. .price{
  604. color: rgba(16, 16, 16, 1);
  605. font-size: 32rpx;
  606. margin-top: 12rpx;
  607. font-weight: bold;
  608. }
  609. .choose{
  610. color: rgba(153, 153, 153, 1);
  611. margin-top: 12rpx;
  612. }
  613. }
  614. }
  615. }
  616. // 选择规格
  617. .specification{
  618. margin-top: 120rpx;
  619. padding: 54rpx 28rpx ;
  620. background: #fff;
  621. // 选项
  622. .optopns-content{
  623. margin: 100rpx 0 40rpx;
  624. height: 800rpx;
  625. overflow: auto;
  626. }
  627. .options{
  628. .options-name{
  629. color: rgba(119, 119, 119, 1);
  630. .tag{
  631. background-color: #8D8072;
  632. color: #fff;
  633. padding: 2px 6px;
  634. border-radius: 15px;
  635. font-size: 10px;
  636. }
  637. }
  638. .options-item{
  639. display: flex;
  640. justify-content: space-between;
  641. flex-wrap: wrap;
  642. margin-top: 24rpx;
  643. margin-bottom: 40rpx;
  644. .item{
  645. min-width: 312rpx;
  646. line-height: 64rpx;
  647. border: 1px solid rgba(221, 221, 221, 1);
  648. text-align: center;
  649. color: rgba(51, 51, 51, 1);
  650. font-size: 32rpx;
  651. border-radius: 50px;
  652. margin-bottom: 24rpx;
  653. padding: 0 20px;
  654. }
  655. // 被选中的
  656. .item-chosen{
  657. border: 1px solid #53b56b;
  658. background-color: #53b56b;
  659. color: #fff;
  660. }
  661. }
  662. }
  663. .bottom{
  664. box-shadow: none;
  665. }
  666. }
  667. </style>