index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <template>
  2. <view class="goodsDetail">
  3. <zs-skeleton type="goodsDetail" :loading="pageLoading"></zs-skeleton>
  4. <image class="good-img" :src="info.goodsPath" mode="aspectFit"></image>
  5. <view class="info-box">
  6. <view class="tag" v-if="info.goodsLabel">
  7. {{info.goodsLabel}}
  8. </view>
  9. <view class="price-box">
  10. <view class="left">
  11. <view class="num-box">
  12. <view class="unit">
  13. </view>
  14. <view class="price">
  15. {{info.realPrice}}
  16. </view>
  17. </view>
  18. <view class="discount-tag" v-if="info.marketPrice">
  19. <image class="icon" src="@/static/down.png" mode=""></image>
  20. <view class="discount-num">
  21. {{((info.realPrice/info.marketPrice)*10).toFixed(1)}}折
  22. </view>
  23. </view>
  24. <view class="old-price">
  25. 市场价 ¥{{info.marketPrice}}
  26. </view>
  27. </view>
  28. <view class="right">
  29. 销量{{info.saleNum}}
  30. </view>
  31. </view>
  32. <view class="goods-info">
  33. <view class="goods-name">
  34. {{info.goodsName}}
  35. </view>
  36. <view class="desc">
  37. {{info.goodsDescribe}}
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 商品规格 -->
  42. <!-- <template v-if="info.specs[0].specValues.length">
  43. <view class="type-box" v-for="item in info.specs" :key="item.specId">
  44. <view class="type-title">
  45. {{item.specName}}
  46. </view>
  47. <view class="type-list">
  48. <view class="type-item" :class="[active == d?'active':'' ]" v-for="(i,d) in item.specValues" :key="i.specId">
  49. {{i.specValue}}
  50. </view>
  51. </view>
  52. </view>
  53. </template> -->
  54. <view class="shop-limit" @click="jump('/detail/shopList/index')">
  55. <view class="info">
  56. <view class="shop-name">
  57. <!-- 朱光玉火锅(天河店) -->
  58. {{info.shopInfo.shopName}}
  59. </view>
  60. <view class="address">
  61. <!-- 花溪区天河潭旅游度假区天河潭 22.65km -->
  62. {{info.shopInfo.address}} {{distance}} KM
  63. </view>
  64. </view>
  65. <view class="num">
  66. {{shopList.length}}家店适用
  67. <image class="icon" src="../../static/shop-desc.png" mode=""></image>
  68. </view>
  69. </view>
  70. <view class="combo-content" v-if="info.services.length">
  71. <view class="sub-title">
  72. 商品详情
  73. </view>
  74. <view class="item" v-for="(item,index) in info.services" :key="index">
  75. <view class="item-title">
  76. {{item.serviceName}}
  77. </view>
  78. <view class="item-content" v-for="i in item.services" :key="i.id">
  79. <view class="name">
  80. {{i.serviceName}}
  81. </view>
  82. <view class="left">
  83. <view class="unit" v-if="i.num">
  84. {{`(${i.num}${i.unit})`}}
  85. </view>
  86. <view class="price" v-if="i.price">
  87. ¥{{i.price}}
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <view class="tab-group">
  94. <view class="tab" :class="[tab == 1 ? 'active':'']" @click="handleTab(1)">
  95. 图文详情
  96. </view>
  97. <view class="tab" :class="[tab == 2 ? 'active':'']" @click="handleTab(2)">
  98. 购买须知
  99. </view>
  100. </view>
  101. <view class="desc-box" v-show="tab == 1">
  102. <rich-text class="goods-desc" :nodes="info.goodsDetail"></rich-text>
  103. </view>
  104. <view class="list" v-show="tab == 2">
  105. <view class="item" v-for="(item,index) in info.attrs" :key="index">
  106. <view class="label">
  107. {{item.attrName == 'validDay'?'有效期':item.attrName}}
  108. </view>
  109. <view class="value" v-html="filterMsg(item.attrValue,item.attrName)">
  110. </view>
  111. </view>
  112. <!-- <view class="item">
  113. <view class="label">
  114. 使用时间
  115. </view>
  116. <view class="value">
  117. 营业时间内可用
  118. </view>
  119. </view> -->
  120. </view>
  121. <view class="buy-box">
  122. <image class="head" :src="info.shopInfo.logoPath" @click="goShopDetail(shopInfo)" mode=""></image>
  123. <view class="btn-box">
  124. <!-- <view class="group-btn" @click="handleBuy">
  125. <view class="label">
  126. 团购
  127. </view>
  128. <view class="price">
  129. ¥{{info.realPrice}}
  130. </view>
  131. </view> -->
  132. <view class="buy-btn" :class="[info.realStockNum?'':'none']" @click="handleBuy">
  133. <view class="label">
  134. {{info.realStockNum?'会员专享价':'售罄'}}
  135. </view>
  136. <view class="price">
  137. ¥{{info.realPrice}}
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. <u-modal :show="show" title="开通会员" showCancelButton cancelText="下次再说" confirmColor="#FF4D3A" confirmText="立即开通" @cancel="cancel" @confirm="jump('/my/memberCenter/index')">
  143. <view class="slot-content">
  144. <view class="">
  145. 此商品需要开通
  146. <text :style="{color:'#FF4D3A'}">{{noticeContent}}</text>
  147. 才能购买
  148. </view>
  149. </view>
  150. </u-modal>
  151. </view>
  152. </template>
  153. <script>
  154. import {detail,valid} from '@/api/goods.js'
  155. import {search} from '@/api/shop.js'
  156. export default {
  157. data() {
  158. return {
  159. show:false,
  160. id:0,
  161. loading:false,
  162. pageLoading:false,
  163. active:0,
  164. tab:1,
  165. shopList:[],
  166. info: {},
  167. location:{},
  168. shopInfo:{},
  169. distance:0,
  170. noticeContent:''
  171. }
  172. },
  173. computed: {
  174. },
  175. methods: {
  176. cancel(){
  177. this.show = false
  178. },
  179. getDistance() {
  180. var radLat1 = this.location.latitude * Math.PI / 180.0;
  181. var radLat2 = this.info.shopInfo.mapLat* Math.PI / 180.0;
  182. var a = radLat1 - radLat2;
  183. var b = this.location.longitude* Math.PI / 180.0 - this.info.shopInfo.mapLon* Math.PI / 180.0;
  184. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  185. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  186. s = s * 6378137.0;//地球半径 单位米;
  187. s = Math.round(s * 10000) / 10000 /1000 //输出为千米
  188. s = s.toFixed(2)
  189. this.distance = s
  190. },
  191. // 获取当前城市
  192. getCity(){
  193. let that = this
  194. return new Promise((resolve,reject)=>{
  195. uni.getLocation({
  196. type: 'gcj02',
  197. success: (res) => {
  198. // 解析地址
  199. that.location.latitude = res.latitude
  200. that.location.longitude = res.longitude
  201. // 存储经纬度
  202. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  203. resolve()
  204. },
  205. fail: () => {
  206. console.log("获取经纬度失败");
  207. },
  208. })
  209. })
  210. },
  211. filterMsg(val,name){
  212. let msg = val.replace(/\n/g, "<br>")
  213. if(name == 'validDay'){
  214. msg = val + '天'
  215. }
  216. return msg
  217. },
  218. jump(url){
  219. uni.navigateTo({
  220. url
  221. })
  222. },
  223. handleTab(val){
  224. this.tab = val
  225. },
  226. handleBuy() {
  227. if(!this.info.realStockNum || this.loading) return
  228. let that = this
  229. if (uni.getStorageSync('token')) {
  230. this.loading = true
  231. valid({goodsId:that.info.goodsId,userId:JSON.parse(uni.getStorageSync('userInfo')).userId}).then(res=>{
  232. this.loading = false
  233. if(res.content){
  234. this.noticeContent = res.content.join().replace(/,/g,'、')
  235. this.show = true
  236. }else{
  237. uni.navigateTo({
  238. url:`/pay/pay`,
  239. success: function(res) {
  240. // 通过eventChannel向被打开页面传送数据
  241. res.eventChannel.emit('pay', that.info)
  242. }
  243. })
  244. }
  245. })
  246. } else {
  247. uni.showModal({
  248. title:'请登录',
  249. confirmText:'去登录',
  250. success(res){
  251. console.log(res);
  252. if(res.confirm){
  253. uni.navigateTo({
  254. url:`/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  255. })
  256. }
  257. }
  258. })
  259. }
  260. },
  261. detail(goodsId){
  262. this.pageLoading = true
  263. detail({goodsId,resource:2}).then(res=>{
  264. this.pageLoading = false
  265. if(res.state == 'Success'){
  266. this.info = res.content
  267. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  268. uni.setNavigationBarTitle({
  269. title:this.info.goodsName
  270. })
  271. }
  272. })
  273. },
  274. goShopDetail(shopInfo) {
  275. uni.setStorageSync('shopInfo', JSON.stringify(this.info.shopInfo))
  276. uni.navigateTo({
  277. url: `../../detail/shopDetail/shopDetail?id=${this.info.shopId}`
  278. })
  279. },
  280. getShopList(goodsId){
  281. // let location = JSON.parse(uni.getStorageSync('location'))
  282. let obj = {
  283. goodsId,
  284. pageCurrent:1,
  285. pageSize:99
  286. }
  287. obj['location.lat'] = this.location.latitude
  288. obj['location.lon'] = this.location.longitude
  289. search(obj).then(res=>{
  290. if(res.state == 'Success'){
  291. this.shopList = res.content.records
  292. uni.setStorageSync('shopList',JSON.stringify(this.shopList))
  293. this.getDistance()
  294. }
  295. })
  296. }
  297. },
  298. onLoad(option) {
  299. this.id = option.id
  300. console.log(111111,option);
  301. // this.shopInfo = uni.getStorageSync('shopInfo')? JSON.parse(uni.getStorageSync('shopInfo')) :{logoPath:'',}
  302. this.detail(option.id)
  303. this.getCity().then(()=>{
  304. this.getShopList(option.id)
  305. })
  306. let that = this
  307. // this.info = JSON.parse(uni.getStorageSync('goodsInfo'))
  308. // const eventChannel = this.getOpenerEventChannel();
  309. // if(JSON.stringify(eventChannel) !=='{}'){
  310. // eventChannel.on('goodsInfo', function(data) {
  311. // that.info = data
  312. // })
  313. // }
  314. },
  315. onShareTimeline() {
  316. return {
  317. title: "慧研学惠生活-"+this.info.goodsName,
  318. query: "id="+this.id,
  319. };
  320. },
  321. onShareAppMessage() {
  322. return {
  323. title: "慧研学惠生活-"+this.info.goodsName,
  324. path: "/detail/goodsDetail/index?id="+this.id,
  325. };
  326. },
  327. }
  328. </script>
  329. <style lang="scss" >
  330. .goodsDetail{
  331. background: #F9F9F9;
  332. padding-bottom: 200rpx;
  333. min-height: 100vh;
  334. .good-img{
  335. width: 100%;
  336. height: 750rpx;
  337. vertical-align: bottom;
  338. }
  339. .info-box{
  340. background: #fff;
  341. .tag{
  342. display: inline-block;
  343. text-align: center;
  344. font-size: 20rpx;
  345. color: #FFFFFF;
  346. background: $uni-color-primary;
  347. padding: 2rpx 10rpx;
  348. border-radius: 8rpx 8rpx 8rpx 8rpx;
  349. margin-left: 24rpx;
  350. margin-top: 24rpx;
  351. }
  352. .price-box{
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. width: 100%;
  357. height: 116rpx;
  358. box-sizing: border-box;
  359. border-bottom: 1rpx solid #F0F0F0;
  360. // background-image: url('../../static/price-bg.png');
  361. // background-repeat: no-repeat;
  362. // background-size: 100% 116rpx;
  363. padding: 10rpx 24rpx 24rpx;
  364. .left{
  365. display: flex;
  366. align-items: center;
  367. .num-box{
  368. display: flex;
  369. align-items: center;
  370. color: $uni-color-primary;
  371. .unit{
  372. font-size: 20rpx;
  373. font-weight: bold;
  374. align-self: flex-end;
  375. margin-bottom: 10rpx;
  376. }
  377. .price{
  378. font-weight: 600;
  379. font-size: 48rpx;
  380. }
  381. }
  382. .discount-tag{
  383. display: flex;
  384. align-items: center;
  385. width: 92rpx;
  386. height: 28rpx;
  387. line-height: 28rpx;
  388. background: #FFF6F5;
  389. border-radius: 8rpx 8rpx 8rpx 8rpx;
  390. border: 1rpx solid $uni-color-primary;
  391. margin-left: 10rpx;
  392. .icon{
  393. width: 30.5rpx;
  394. height: 28rpx;
  395. }
  396. .discount-num{
  397. flex: 1;
  398. text-align: center;
  399. font-size: 20rpx;
  400. color: $uni-color-primary;
  401. }
  402. }
  403. .old-price{
  404. text-decoration: line-through;
  405. margin-left: 12rpx;
  406. font-weight: 300;
  407. font-size: 20rpx;
  408. color: #AAAAAA;
  409. }
  410. }
  411. .right{
  412. font-size: 24rpx;
  413. font-weight: 300;
  414. font-size: 24rpx;
  415. }
  416. }
  417. .goods-info{
  418. padding: 24rpx;
  419. margin-bottom: 20rpx;
  420. background: #fff;
  421. .goods-name{
  422. font-size: 32rpx;
  423. color: #222222;
  424. font-weight: bold;
  425. }
  426. .desc{
  427. font-size: 24rpx;
  428. color: #AAAAAA;
  429. overflow: hidden;
  430. text-overflow: ellipsis;
  431. white-space: nowrap;
  432. margin-top: 12rpx;
  433. }
  434. }
  435. }
  436. .type-box{
  437. padding: 24rpx;
  438. background: #fff;
  439. margin-bottom: 20rpx;
  440. .type-title{
  441. font-size: 28rpx;
  442. color: #222222;
  443. }
  444. .type-list{
  445. display: flex;
  446. flex-wrap: wrap;
  447. justify-content: space-between;
  448. .type-item{
  449. width: 316rpx;
  450. height: 52rpx;
  451. text-align: center;
  452. line-height: 52rpx;
  453. background: #F0F0F0;
  454. border-radius: 26rpx 26rpx 26rpx 26rpx;
  455. font-weight: 300;
  456. font-size: 24rpx;
  457. color: #AAAAAA;
  458. margin-top: 28rpx;
  459. }
  460. .type-item.active{
  461. background: #EE4320;
  462. color: #FFFFFF;
  463. }
  464. }
  465. }
  466. .shop-limit{
  467. padding: 24rpx;
  468. background: #fff;
  469. display: flex;
  470. align-items: center;
  471. justify-content: space-between;
  472. margin-bottom: 20rpx;
  473. .info{
  474. .shop-name{
  475. font-size: 28rpx;
  476. color: #222222;
  477. }
  478. .address{
  479. font-size: 24rpx;
  480. color: #AAAAAA;
  481. margin-top: 16rpx;
  482. width: 450rpx;
  483. }
  484. }
  485. .num{
  486. display: flex;
  487. align-items: center;
  488. font-size: 24rpx;
  489. color: #AAAAAA;
  490. .icon{
  491. width: 48rpx;
  492. height: 48rpx;
  493. transform: rotate(-90deg);
  494. }
  495. }
  496. }
  497. .combo-content{
  498. background: #FFFFFF;
  499. padding: 24rpx 24rpx 24rpx 46rpx;
  500. border-radius: 16rpx;
  501. margin-bottom: 20rpx;
  502. .sub-title{
  503. font-size: 28rpx;
  504. color: #222222;
  505. font-weight: bold;
  506. padding: 20rpx 0;
  507. }
  508. .item{
  509. padding-bottom: 20rpx;
  510. .item-title{
  511. font-weight: 600;
  512. font-size: 24rpx;
  513. color: #222222;
  514. position: relative;
  515. &::before{
  516. content: '';
  517. position: absolute;
  518. top: 50%;
  519. left: -16rpx;
  520. width: 6rpx;
  521. height: 6rpx;
  522. border-radius: 50%;
  523. background: #CCCCCC;
  524. transform: translateY(-50%);
  525. }
  526. }
  527. .item-content{
  528. display: flex;
  529. align-items: center;
  530. justify-content: space-between;
  531. margin-top: 20rpx;
  532. .name{
  533. flex: 1;
  534. font-size: 24rpx;
  535. color: #222222;
  536. }
  537. .left{
  538. display: flex;
  539. align-items: center;
  540. justify-content: space-between;
  541. flex: 0 0 150rpx;
  542. .unit{
  543. font-size: 20rpx;
  544. color: #AAAAAA;
  545. }
  546. .price{
  547. font-size: 24rpx;
  548. color: #222222;
  549. font-weight: 600;
  550. margin-left: 20rpx;
  551. }
  552. }
  553. }
  554. }
  555. .item+.item{
  556. padding-top: 20rpx;
  557. border-top: 1rpx solid #F0F0F0;
  558. }
  559. }
  560. .tab-group{
  561. display: flex;
  562. background: #fff;
  563. .tab{
  564. flex:1;
  565. padding: 24rpx 0;
  566. text-align: center;
  567. font-size: 28rpx;
  568. color: #222222;
  569. }
  570. .tab.active{
  571. font-weight: 600;
  572. }
  573. }
  574. .desc-box{
  575. .goods-desc{
  576. color: #222222;
  577. font-size: 24rpx;
  578. .img_class{
  579. max-width: 100%!important;
  580. vertical-align: bottom;
  581. }
  582. }
  583. }
  584. .list{
  585. background: #fff;
  586. .item{
  587. padding: 24rpx;
  588. border-top:1rpx solid #F0F0F0;
  589. .label{
  590. font-weight: 600;
  591. font-size: 28rpx;
  592. color: #222222;
  593. }
  594. .value{
  595. font-size: 24rpx;
  596. color: #AAAAAA;
  597. margin-top: 16rpx;
  598. line-height: 40rpx;
  599. }
  600. }
  601. }
  602. .buy-box{
  603. position: fixed;
  604. bottom: 0%;
  605. left: 0%;
  606. width: 100%;
  607. background: #fff;
  608. padding: 10rpx 24rpx 76rpx;
  609. display: flex;
  610. justify-content: space-between;
  611. box-sizing: border-box;
  612. .head{
  613. width: 80rpx;
  614. height: 80rpx;
  615. background: #aaa;
  616. border-radius: 50%;
  617. }
  618. .btn-box{
  619. display: flex;
  620. text-align: center;
  621. .group-btn{
  622. width: 280rpx;
  623. height: 80rpx;
  624. background: #6499FF;
  625. border-radius: 40rpx 0rpx 0rpx 40rpx;
  626. display: flex;
  627. flex-direction: column;
  628. justify-content: space-around;
  629. .label{
  630. font-weight: 600;
  631. font-size: 28rpx;
  632. color: #FFFFFF;
  633. }
  634. .price{
  635. font-size: 24rpx;
  636. color: #FFFFFF;
  637. }
  638. }
  639. .buy-btn.none{
  640. filter: grayscale(1);
  641. }
  642. .buy-btn{
  643. // width: 280rpx;
  644. width: 560rpx;
  645. height: 80rpx;
  646. background: $uni-color-primary;
  647. border-radius: 40rpx;
  648. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  649. display: flex;
  650. flex-direction: column;
  651. justify-content: space-around;
  652. .label{
  653. font-weight: 600;
  654. font-size: 28rpx;
  655. color: #FFFFFF;
  656. }
  657. .price{
  658. font-size: 24rpx;
  659. color: #FFFFFF;
  660. }
  661. }
  662. }
  663. }
  664. }
  665. </style>