index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <view class="home">
  3. <zs-skeleton :loading="loading"></zs-skeleton>
  4. <zs-banner :city="city" :background="background" position @search="handleSearch"></zs-banner>
  5. <view class="login-home">
  6. <!-- 登录显示的套餐列表 -->
  7. <view class="discount-list">
  8. <view class="discount-item" v-for="(item,index) in discountsList" :key="index" @click="goDetail(item.linkUrl,item.id,item.secondaryImg,item.menuName)">
  9. <image class="icon" :src="item.imgUrl" mode=""></image>
  10. <view class="title">{{item.menuName}}</view>
  11. <view class="tag" v-if="item.labelAbove">
  12. {{item.labelAbove}}
  13. </view>
  14. <view class="desc">
  15. {{item.labelBelow || ''}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="swiper-box">
  20. <view class="progress">
  21. {{current+1+'/'+advList.length}}
  22. </view>
  23. <swiper class="swiper" @change="swiperChange" :current="current" :indicator-dots="false" circular :autoplay="true"
  24. :interval="3000" :duration="1000">
  25. <swiper-item v-for="(item,index) in advList" :key="item.id" @click="jump(item.jumpUrl)">
  26. <image class="swiper-item" mode="" :src="item.advertsImg">
  27. </image>
  28. </swiper-item>
  29. </swiper>
  30. </view>
  31. <!-- 广告位 -->
  32. <!-- <view class="advertise-box">
  33. <view class="item" v-for="item in advList" :key="item.id">
  34. <zs-img
  35. :src="item.advertsImg"
  36. width="335rpx" height="188rpx" radius="full" mode=""></zs-img>
  37. </view>
  38. </view> -->
  39. <view class="content">
  40. <!-- 列表 -->
  41. <zs-list class="store-box" mt="0" @load="loadMore" :status="status">
  42. <view class="left">
  43. <!-- 广告banner -->
  44. <swiper class="adv-swiper" v-if="advList1.length" indicator-active-color="#fff" indicator-color="rgba(255, 255, 255, .46)" :indicator-dots="advList1.length>1" circular autoplay>
  45. <swiper-item v-for="item in advList1" :key="item" @click="jump(item.jumpUrl)">
  46. <image class="adv-item"
  47. :src="item.advertsImg"
  48. mode=""></image>
  49. </swiper-item>
  50. </swiper>
  51. <view class="store-item" v-for="(item,index) in list" :key="index" @click="goShopDetail(item)">
  52. <zs-img :src="item.logoPath" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
  53. <view class="info">
  54. <view class="title">
  55. {{item.shopVo.shopName}}
  56. </view>
  57. <view class="address">
  58. <image class="position" src="../../static/position.png" mode=""></image>
  59. {{(item.shopVo.distance/1000).toFixed(2)}}km
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="right">
  65. <view class="store-item" v-for="(item,index) in list1" :key="index" @click="goShopDetail(item)">
  66. <zs-img :src="item.logoPath" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
  67. <view class="info">
  68. <view class="title">
  69. {{item.shopVo.shopName}}
  70. </view>
  71. <view class="address">
  72. <image class="position" src="../../static/position.png" mode=""></image>
  73. {{(item.shopVo.distance/1000).toFixed(2)}}km
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </zs-list>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import {
  85. getUserDetail,
  86. getMenu,
  87. getAdv
  88. } from '@/api/common.js'
  89. import { search } from '@/api/shop.js';
  90. // 腾讯地图
  91. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  92. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  93. export default {
  94. data() {
  95. return {
  96. background:false,
  97. loading: false,
  98. userId: '',
  99. city:'定位中',
  100. status: 'more',
  101. current:0,
  102. bannerList:['https://alipic.lanhuapp.com/XDSlicePNGMAX2f4cb415a269b2e935c7a97da9077db4d78ddb8306ac44ec1e10274387048a22.png',
  103. 'https://alipic.lanhuapp.com/XDSlicePNGMAX2f4cb415a269b2e935c7a97da9077db4d78ddb8306ac44ec1e10274387048a22.png'],
  104. discountsList: [],//菜单
  105. advList:[],
  106. advList1:[],
  107. list: [],
  108. list1: [],
  109. query:{
  110. queryName:'',
  111. 'location.lat':0,
  112. 'location.lon':0,
  113. pageCurrent:1,
  114. pageSize:10
  115. },
  116. }
  117. },
  118. methods: {
  119. // swiper变动
  120. swiperChange(val) {
  121. this.current = val.target.current
  122. },
  123. jump(url){
  124. uni.reLaunch({
  125. url
  126. })
  127. },
  128. // 点击搜索
  129. handleSearch(){
  130. if(!uni.getStorageSync('token')){
  131. return uni.showModal({
  132. title:'请登录',
  133. confirmText:'去登录',
  134. success(res){
  135. console.log(res);
  136. if(res.confirm){
  137. uni.navigateTo({
  138. url:'/login/login/login?redirect=/pages/index/index'
  139. })
  140. }
  141. }
  142. })
  143. }
  144. uni.reLaunch({
  145. url:'./search'
  146. })
  147. // if(!val) return
  148. // this.query.queryName = val
  149. // this.query.pageCurrent = 1
  150. // this.list = []
  151. // this.list1 = []
  152. // this.status = 'more'
  153. // this.search()
  154. },
  155. // 获取当前城市
  156. getCity(){
  157. let that = this
  158. return new Promise((resolve,reject)=>{
  159. uni.getLocation({
  160. type: 'gcj02',
  161. success: (res) => {
  162. // 解析地址
  163. that.query['location.lat'] = res.latitude
  164. that.query['location.lon'] = res.longitude
  165. // 存储经纬度
  166. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  167. qqmapsdk.reverseGeocoder({
  168. location: {
  169. latitude: res.latitude,
  170. longitude: res.longitude
  171. },
  172. success: function(res) {
  173. // 市
  174. that.city = res.result.address_component.city
  175. console.log(9999,that.city);
  176. resolve()
  177. },
  178. fail: function(res) {
  179. that.city = '定位失败'
  180. },
  181. })
  182. },
  183. fail: () => {
  184. console.log("获取经纬度失败");
  185. },
  186. })
  187. })
  188. },
  189. // 跳转优惠详情
  190. goDetail(url,id,banner,title) {
  191. uni.navigateTo({
  192. url: `${url}?id=${id}&title=${title}`,
  193. success(res) {
  194. res.eventChannel.emit('banner', banner)
  195. }
  196. })
  197. },
  198. goShopDetail(item) {
  199. uni.setStorageSync('shopInfo', JSON.stringify(item))
  200. uni.reLaunch({
  201. url: `../../detail/shopDetail/shopDetail`
  202. })
  203. },
  204. // 更多套餐
  205. handleMore() {
  206. uni.reLaunch({
  207. // url:'../../login/login/login'
  208. url: '../../combo/combo/combo'
  209. })
  210. },
  211. // 获取用户详情
  212. getUserDetail() {
  213. getUserDetail().then(res => {
  214. uni.setStorageSync('userInfo', JSON.stringify(res.content))
  215. })
  216. },
  217. loadMore() {
  218. if(this.query['location.lat']&&this.query['location.lon']){
  219. this.search()
  220. }
  221. },
  222. search() {
  223. if(this.status == 'noMore') return
  224. this.status = 'loading'
  225. search(this.query).then(res=>{
  226. if(res.state == 'Success'){
  227. this.loading = false
  228. let list = []
  229. let list1 = []
  230. res.content.records.map((item,index)=>{
  231. if(index%2){
  232. list.push(item)
  233. }else{
  234. list1.push(item)
  235. }
  236. })
  237. this.list = this.list.concat(list)
  238. this.list1 = this.list1.concat(list1)
  239. let total = this.list.length+this.list1.length
  240. if(total>=res.content.total){
  241. this.status = 'noMore'
  242. }else{
  243. this.status = 'more'
  244. this.query.pageCurrent++
  245. }
  246. }
  247. })
  248. },
  249. // 金刚区
  250. getMenu(){
  251. return new Promise((resolve,reject)=>{
  252. getMenu({currentPage:1,pageSize:10}).then(res=>{
  253. if(res.state == 'Success'){
  254. this.discountsList = res.content.records
  255. resolve(1)
  256. }
  257. })
  258. })
  259. },
  260. // 广告位
  261. getAdv(){
  262. return new Promise((resolve,reject)=>{
  263. getAdv({currentPage:1,pageSize:99,advertsType:1}).then(res=>{
  264. if(res.state == 'Success'){
  265. this.advList = res.content.records.filter((item,index)=>index<2)
  266. this.advList1 = res.content.records.filter((item,index)=>index>=2)
  267. resolve(2)
  268. }
  269. })
  270. })
  271. }
  272. },
  273. onPageScroll(e) {
  274. if(e.scrollTop >= 50){
  275. this.background = true
  276. }else{
  277. this.background = false
  278. }
  279. },
  280. onShow() {
  281. if (uni.getStorageSync('token')&&!uni.getStorageSync('userInfo')) {
  282. this.getUserDetail()
  283. }
  284. },
  285. onHide() {},
  286. onLoad(query){
  287. uni.setStorageSync('inviteCode',decodeURIComponent(query.scene))
  288. },
  289. created() {
  290. this.loading = true
  291. Promise.all([this.getMenu(),this.getAdv(),this.getCity()]).then(res=>{
  292. this.search()
  293. })
  294. }
  295. }
  296. </script>
  297. <style lang="scss">
  298. .home {
  299. // padding-bottom:120rpx;
  300. background: linear-gradient(180deg, #FFFFFF 0%, #DCE8FF 100%);
  301. .card-title {
  302. display: flex;
  303. justify-content: center;
  304. .title {
  305. font-size: 32rpx;
  306. text-align: center;
  307. color: #fff;
  308. width: 210rpx;
  309. line-height: 64rpx;
  310. background: linear-gradient(360deg, #3074F8 0%, #568FFF 100%);
  311. border-radius: 0rpx 0rpx 24rpx 24rpx;
  312. }
  313. }
  314. .login-home {
  315. // background: linear-gradient(178deg, #FFFFFF 0%, #F9F9F9 100%);
  316. background: #FFF;
  317. .discount-list {
  318. display: flex;
  319. flex-wrap: wrap;
  320. // padding: 30rpx 0;
  321. margin: 0 24rpx 20rpx;
  322. background: #fff;
  323. border-radius: 16rpx;
  324. position: relative;
  325. top: 20rpx;
  326. padding-top: 20rpx;
  327. .discount-item {
  328. width: 20%;
  329. display: flex;
  330. flex-direction: column;
  331. align-items: center;
  332. margin-top: 20rpx;
  333. margin-bottom: 20rpx;
  334. position: relative;
  335. .icon {
  336. width: 56rpx;
  337. height: 56rpx;
  338. }
  339. .title {
  340. font-size: 26rpx;
  341. margin-top: 10rpx;
  342. }
  343. .tag {
  344. position: absolute;
  345. top: -20rpx;
  346. left: 50%;
  347. background: #FF0615;
  348. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  349. border-radius: 12rpx 14rpx 14rpx 0rpx;
  350. color: #fff;
  351. white-space: nowrap;
  352. font-size: 18rpx;
  353. line-height: -14rpx;
  354. height: 24rpx;
  355. padding: 0 10rpx;
  356. // width: fit-content;
  357. background-size: 100% 34rpx;
  358. }
  359. .desc {
  360. color: #FF0817;
  361. font-size: 16rpx;
  362. text-align: center;
  363. margin-top: 4rpx;
  364. }
  365. }
  366. }
  367. .title-img {
  368. width: 686rpx;
  369. height: 166rpx;
  370. margin: 24rpx 32rpx;
  371. }
  372. .swiper-box{
  373. position: relative;
  374. margin: 0 24rpx 20rpx;
  375. padding-top: 20rpx;
  376. width: 702rpx;
  377. height: 284rpx;
  378. border-radius: 16rpx;
  379. .progress{
  380. position: absolute;
  381. top: 38rpx;
  382. right: 20rpx;
  383. z-index: 2;
  384. color: #FFFFFF;
  385. font-size: 16rpx;
  386. background: rgba(255, 255, 255, 0.3);
  387. padding: 2rpx 10rpx;
  388. border-radius: 14rpx;
  389. }
  390. .swiper {
  391. position: relative;
  392. height: 100%;
  393. .swiper-item {
  394. width: 100%;
  395. height: 100%;
  396. border-radius: 16rpx;
  397. object-fit: cover;
  398. }
  399. }
  400. }
  401. .advertise-box {
  402. display: flex;
  403. justify-content: space-between;
  404. margin: 0 24rpx;
  405. padding: 20rpx 0;
  406. }
  407. .content {
  408. border-radius: 16rpx 16rpx 0 0;
  409. }
  410. .zs-list {
  411. display: flex;
  412. flex-wrap: wrap;
  413. justify-content: space-between;
  414. padding: 0 24rpx;
  415. .left {
  416. .adv-swiper{
  417. width: 340rpx;
  418. height: 444rpx;
  419. margin-bottom: 25rpx;
  420. .adv-item{
  421. width: 340rpx;
  422. height: 444rpx;
  423. }
  424. }
  425. }
  426. .right {
  427. }
  428. .store-item {
  429. width: 340rpx;
  430. margin-bottom: 25rpx;
  431. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  432. border-radius: 16rpx;
  433. background: #fff;
  434. .icon {
  435. width: 100%;
  436. height: 300rpx;
  437. border-radius: 16rpx 16rpx 0 0;
  438. }
  439. .info {
  440. padding: 20rpx;
  441. background: #fff;
  442. border-radius: 0 0 16rpx 16rpx;
  443. position: relative;
  444. .title {
  445. font-weight: bold;
  446. width: 100%;
  447. white-space: nowrap;
  448. text-overflow: ellipsis;
  449. overflow: hidden;
  450. }
  451. .tags {
  452. display: flex;
  453. align-items: center;
  454. .tag-item {
  455. line-height: 50rpx;
  456. border-radius: 8rpx;
  457. padding: 6rpx 0;
  458. font-size: 24rpx;
  459. margin-left: 10rpx;
  460. display: flex;
  461. .label {
  462. background: #FFF;
  463. color: #FE5B47;
  464. padding: 0 10rpx;
  465. border-radius: 8rpx 0 0 8rpx;
  466. }
  467. .value {
  468. color: #FFF;
  469. background: rgba(255, 255, 255, .2);
  470. padding: 0 14rpx;
  471. border-radius: 0 8rpx 8rpx 0;
  472. }
  473. }
  474. }
  475. .address {
  476. display: flex;
  477. align-items: center;
  478. margin-top: 15rpx;
  479. color: #999;
  480. .position {
  481. width: 25rpx;
  482. height: 29rpx;
  483. margin-right: 8rpx;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. </style>