index.vue 15 KB

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