index.vue 16 KB

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