index.vue 15 KB

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