index.vue 17 KB

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