index.vue 13 KB

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