index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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.platformPrice?info.platformPrice.price: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.platformPrice?info.platformPrice.price: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.platformPrice?info.platformPrice.price: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. if(JSON.parse(uni.getStorageSync('userInfo')).setMealCode != 0&&JSON.parse(uni.getStorageSync('userInfo')).setMealCode){
  231. // this.loading = true
  232. // valid({goodsId:that.info.goodsId,userId:JSON.parse(uni.getStorageSync('userInfo')).userId}).then(res=>{
  233. // this.loading = false
  234. // if(res.content){
  235. // this.noticeContent = res.content.join().replace(/,/g,'、')
  236. // this.show = true
  237. // }else{
  238. // uni.navigateTo({
  239. // url:`/pay/pay`,
  240. // success: function(res) {
  241. // // 通过eventChannel向被打开页面传送数据
  242. // res.eventChannel.emit('pay', that.info)
  243. // }
  244. // })
  245. // }
  246. // })
  247. let info = JSON.parse(JSON.stringify(this.info))
  248. if(info.platformPrice){
  249. info.realPrice = info.platformPrice.price
  250. }
  251. uni.navigateTo({
  252. url:`/pay/pay`,
  253. success: function(res) {
  254. // 通过eventChannel向被打开页面传送数据
  255. res.eventChannel.emit('pay', info)
  256. }
  257. })
  258. }else{
  259. uni.showModal({
  260. title:'此商品需要开通会员才能购买',
  261. cancelText:'下次再说',
  262. confirmText:'立即开通',
  263. success(res) {
  264. if(res.confirm){
  265. uni.navigateTo({
  266. url:'/my/memberCenter/index'
  267. })
  268. }
  269. }
  270. })
  271. }
  272. } else {
  273. uni.showModal({
  274. title:'请登录',
  275. confirmText:'去登录',
  276. success(res){
  277. console.log(res);
  278. if(res.confirm){
  279. uni.navigateTo({
  280. url:`/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  281. })
  282. }
  283. }
  284. })
  285. }
  286. },
  287. detail(goodsId){
  288. this.pageLoading = true
  289. detail({goodsId,resource:2,platform:'520100'}).then(res=>{
  290. this.pageLoading = false
  291. if(res.state == 'Success'){
  292. this.info = res.content
  293. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  294. uni.setNavigationBarTitle({
  295. title:this.info.goodsName
  296. })
  297. }
  298. })
  299. },
  300. goShopDetail(shopInfo) {
  301. uni.setStorageSync('shopInfo', JSON.stringify(this.info.shopInfo))
  302. uni.navigateTo({
  303. url: `../../detail/shopDetail/shopDetail?id=${this.info.shopId}`
  304. })
  305. },
  306. getShopList(goodsId){
  307. // let location = JSON.parse(uni.getStorageSync('location'))
  308. let obj = {
  309. goodsId,
  310. pageCurrent:1,
  311. pageSize:99
  312. }
  313. obj['location.lat'] = this.location.latitude
  314. obj['location.lon'] = this.location.longitude
  315. search(obj).then(res=>{
  316. if(res.state == 'Success'){
  317. this.shopList = res.content.records
  318. uni.setStorageSync('shopList',JSON.stringify(this.shopList))
  319. this.getDistance()
  320. }
  321. })
  322. }
  323. },
  324. onLoad(option) {
  325. this.id = option.id
  326. console.log(111111,option);
  327. // this.shopInfo = uni.getStorageSync('shopInfo')? JSON.parse(uni.getStorageSync('shopInfo')) :{logoPath:'',}
  328. this.detail(option.id)
  329. this.getCity().then(()=>{
  330. this.getShopList(option.id)
  331. })
  332. let that = this
  333. // this.info = JSON.parse(uni.getStorageSync('goodsInfo'))
  334. // const eventChannel = this.getOpenerEventChannel();
  335. // if(JSON.stringify(eventChannel) !=='{}'){
  336. // eventChannel.on('goodsInfo', function(data) {
  337. // that.info = data
  338. // })
  339. // }
  340. },
  341. onShareTimeline() {
  342. return {
  343. title: "慧研学惠生活-"+this.info.goodsName,
  344. query: "id="+this.id,
  345. };
  346. },
  347. onShareAppMessage() {
  348. return {
  349. title: "慧研学惠生活-"+this.info.goodsName,
  350. path: "/detail/goodsDetail/index?id="+this.id,
  351. };
  352. },
  353. }
  354. </script>
  355. <style lang="scss" >
  356. .goodsDetail{
  357. background: #F9F9F9;
  358. padding-bottom: 200rpx;
  359. min-height: 100vh;
  360. .good-img{
  361. width: 100%;
  362. height: 750rpx;
  363. vertical-align: bottom;
  364. }
  365. .info-box{
  366. background: #fff;
  367. .tag{
  368. display: inline-block;
  369. text-align: center;
  370. font-size: 20rpx;
  371. color: #FFFFFF;
  372. background: $uni-color-primary;
  373. padding: 2rpx 10rpx;
  374. border-radius: 8rpx 8rpx 8rpx 8rpx;
  375. margin-left: 24rpx;
  376. margin-top: 24rpx;
  377. }
  378. .price-box{
  379. display: flex;
  380. justify-content: space-between;
  381. align-items: center;
  382. width: 100%;
  383. height: 116rpx;
  384. box-sizing: border-box;
  385. border-bottom: 1rpx solid #F0F0F0;
  386. // background-image: url('../../static/price-bg.png');
  387. // background-repeat: no-repeat;
  388. // background-size: 100% 116rpx;
  389. padding: 10rpx 24rpx 24rpx;
  390. .left{
  391. display: flex;
  392. align-items: center;
  393. .num-box{
  394. display: flex;
  395. align-items: center;
  396. color: $uni-color-primary;
  397. .unit{
  398. font-size: 20rpx;
  399. font-weight: bold;
  400. align-self: flex-end;
  401. margin-bottom: 10rpx;
  402. }
  403. .price{
  404. font-weight: 600;
  405. font-size: 48rpx;
  406. }
  407. }
  408. .discount-tag{
  409. display: flex;
  410. align-items: center;
  411. width: 82rpx;
  412. height: 28rpx;
  413. line-height: 28rpx;
  414. background: #FFF6F5;
  415. border-radius: 8rpx 8rpx 8rpx 8rpx;
  416. border: 1rpx solid $uni-color-primary;
  417. margin-left: 10rpx;
  418. .icon{
  419. width: 30.5rpx;
  420. height: 28rpx;
  421. }
  422. .discount-num{
  423. flex: 1;
  424. text-align: center;
  425. font-size: 20rpx;
  426. color: $uni-color-primary;
  427. }
  428. }
  429. .old-price{
  430. text-decoration: line-through;
  431. margin-left: 12rpx;
  432. font-weight: 300;
  433. font-size: 20rpx;
  434. color: #AAAAAA;
  435. }
  436. }
  437. .right{
  438. font-size: 24rpx;
  439. font-weight: 300;
  440. font-size: 24rpx;
  441. }
  442. }
  443. .goods-info{
  444. padding: 24rpx;
  445. margin-bottom: 20rpx;
  446. background: #fff;
  447. .goods-name{
  448. font-size: 32rpx;
  449. color: #222222;
  450. font-weight: bold;
  451. }
  452. .desc{
  453. font-size: 24rpx;
  454. color: #AAAAAA;
  455. overflow: hidden;
  456. text-overflow: ellipsis;
  457. white-space: nowrap;
  458. margin-top: 12rpx;
  459. }
  460. }
  461. }
  462. .type-box{
  463. padding: 24rpx;
  464. background: #fff;
  465. margin-bottom: 20rpx;
  466. .type-title{
  467. font-size: 28rpx;
  468. color: #222222;
  469. }
  470. .type-list{
  471. display: flex;
  472. flex-wrap: wrap;
  473. justify-content: space-between;
  474. .type-item{
  475. width: 316rpx;
  476. height: 52rpx;
  477. text-align: center;
  478. line-height: 52rpx;
  479. background: #F0F0F0;
  480. border-radius: 26rpx 26rpx 26rpx 26rpx;
  481. font-weight: 300;
  482. font-size: 24rpx;
  483. color: #AAAAAA;
  484. margin-top: 28rpx;
  485. }
  486. .type-item.active{
  487. background: #EE4320;
  488. color: #FFFFFF;
  489. }
  490. }
  491. }
  492. .shop-limit{
  493. padding: 24rpx;
  494. background: #fff;
  495. display: flex;
  496. align-items: center;
  497. justify-content: space-between;
  498. margin-bottom: 20rpx;
  499. .info{
  500. .shop-name{
  501. font-size: 28rpx;
  502. color: #222222;
  503. }
  504. .address{
  505. font-size: 24rpx;
  506. color: #AAAAAA;
  507. margin-top: 16rpx;
  508. width: 450rpx;
  509. }
  510. }
  511. .num{
  512. display: flex;
  513. align-items: center;
  514. font-size: 24rpx;
  515. color: #AAAAAA;
  516. .icon{
  517. width: 48rpx;
  518. height: 48rpx;
  519. transform: rotate(-90deg);
  520. }
  521. }
  522. }
  523. .combo-content{
  524. background: #FFFFFF;
  525. padding: 24rpx 24rpx 24rpx 46rpx;
  526. border-radius: 16rpx;
  527. margin-bottom: 20rpx;
  528. .sub-title{
  529. font-size: 28rpx;
  530. color: #222222;
  531. font-weight: bold;
  532. padding: 20rpx 0;
  533. }
  534. .item{
  535. padding-bottom: 20rpx;
  536. .item-title{
  537. font-weight: 600;
  538. font-size: 24rpx;
  539. color: #222222;
  540. position: relative;
  541. &::before{
  542. content: '';
  543. position: absolute;
  544. top: 50%;
  545. left: -16rpx;
  546. width: 6rpx;
  547. height: 6rpx;
  548. border-radius: 50%;
  549. background: #CCCCCC;
  550. transform: translateY(-50%);
  551. }
  552. }
  553. .item-content{
  554. display: flex;
  555. align-items: center;
  556. justify-content: space-between;
  557. margin-top: 20rpx;
  558. .name{
  559. flex: 1;
  560. font-size: 24rpx;
  561. color: #222222;
  562. }
  563. .left{
  564. display: flex;
  565. align-items: center;
  566. justify-content: space-between;
  567. flex: 0 0 150rpx;
  568. .unit{
  569. font-size: 20rpx;
  570. color: #AAAAAA;
  571. }
  572. .price{
  573. font-size: 24rpx;
  574. color: #222222;
  575. font-weight: 600;
  576. margin-left: 20rpx;
  577. }
  578. }
  579. }
  580. }
  581. .item+.item{
  582. padding-top: 20rpx;
  583. border-top: 1rpx solid #F0F0F0;
  584. }
  585. }
  586. .tab-group{
  587. display: flex;
  588. background: #fff;
  589. .tab{
  590. flex:1;
  591. padding: 24rpx 0;
  592. text-align: center;
  593. font-size: 28rpx;
  594. color: #222222;
  595. }
  596. .tab.active{
  597. font-weight: 600;
  598. }
  599. }
  600. .desc-box{
  601. .goods-desc{
  602. color: #222222;
  603. font-size: 24rpx;
  604. .img_class{
  605. max-width: 100%!important;
  606. vertical-align: bottom;
  607. }
  608. }
  609. }
  610. .list{
  611. background: #fff;
  612. .item{
  613. padding: 24rpx;
  614. border-top:1rpx solid #F0F0F0;
  615. .label{
  616. font-weight: 600;
  617. font-size: 28rpx;
  618. color: #222222;
  619. }
  620. .value{
  621. font-size: 24rpx;
  622. color: #AAAAAA;
  623. margin-top: 16rpx;
  624. line-height: 40rpx;
  625. }
  626. }
  627. }
  628. .buy-box{
  629. position: fixed;
  630. bottom: 0%;
  631. left: 0%;
  632. width: 100%;
  633. background: #fff;
  634. padding: 10rpx 24rpx 76rpx;
  635. display: flex;
  636. justify-content: space-between;
  637. box-sizing: border-box;
  638. .head{
  639. width: 80rpx;
  640. height: 80rpx;
  641. background: #aaa;
  642. border-radius: 50%;
  643. }
  644. .btn-box{
  645. display: flex;
  646. text-align: center;
  647. .group-btn{
  648. width: 280rpx;
  649. height: 80rpx;
  650. background: #6499FF;
  651. border-radius: 40rpx 0rpx 0rpx 40rpx;
  652. display: flex;
  653. flex-direction: column;
  654. justify-content: space-around;
  655. .label{
  656. font-weight: 600;
  657. font-size: 28rpx;
  658. color: #FFFFFF;
  659. }
  660. .price{
  661. font-size: 24rpx;
  662. color: #FFFFFF;
  663. }
  664. }
  665. .buy-btn.none{
  666. filter: grayscale(1);
  667. }
  668. .buy-btn{
  669. // width: 280rpx;
  670. width: 560rpx;
  671. height: 80rpx;
  672. background: $uni-color-primary;
  673. border-radius: 40rpx;
  674. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  675. display: flex;
  676. flex-direction: column;
  677. justify-content: space-around;
  678. .label{
  679. font-weight: 600;
  680. font-size: 28rpx;
  681. color: #FFFFFF;
  682. }
  683. .price{
  684. font-size: 24rpx;
  685. color: #FFFFFF;
  686. }
  687. }
  688. }
  689. }
  690. }
  691. </style>