index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template>
  2. <view class="home">
  3. <zs-skeleton :loading="loading"></zs-skeleton>
  4. <zs-banner :city="city" :background="background" position @handlePosition="getCity" @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.domainUrl,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">
  52. <template v-if="item.isAdv">
  53. <!-- <image class="ad" :src="item.advertsImg" mode="widthFix"></image> -->
  54. <zs-img :src="item.advertsImg" radius="full" width="340rpx" mode="widthFix" @click.native="jump(item.jumpUrl)"></zs-img>
  55. </template>
  56. <view v-else @click="goGoodsDetail(item)">
  57. <zs-img :src="item.goodsVos[0].goodsImg" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
  58. <view class="info">
  59. <view class="title">
  60. {{item.goodsVos[0].goodsName}}
  61. </view>
  62. <view class="desc">
  63. {{item.goodsVos[0].goodsDescribe}}
  64. </view>
  65. <view class="price-box">
  66. <view class="left">
  67. <!-- <view class="unit">
  68. </view> -->
  69. <view class="price">
  70. ¥{{item.goodsVos[0].realPrice}}
  71. </view>
  72. </view>
  73. <view class="right">
  74. 销量{{item.goodsVos[0].saleNum}}
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="right">
  82. <view class="store-item" v-for="(item,index) in list1" :key="index">
  83. <template v-if="item.isAdv">
  84. <zs-img :src="item.advertsImg" radius="full" width="340rpx" mode="widthFix" @click.native="jump(item.jumpUrl)"></zs-img>
  85. <!-- <image class="ad" :src="item.advertsImg" mode="widthFix"></image> -->
  86. </template>
  87. <view v-else @click="goGoodsDetail(item)">
  88. <zs-img :src="item.goodsVos[0].goodsImg" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
  89. <view class="info">
  90. <view class="title">
  91. {{item.goodsVos[0].goodsName}}
  92. </view>
  93. <view class="desc">
  94. {{item.goodsVos[0].goodsDescribe}}
  95. </view>
  96. <view class="price-box">
  97. <view class="left">
  98. <!-- <view class="unit">
  99. </view> -->
  100. <view class="price">
  101. ¥{{item.goodsVos[0].realPrice}}
  102. </view>
  103. </view>
  104. <view class="right">
  105. 销量{{item.goodsVos[0].saleNum}}
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. </zs-list>
  113. </view>
  114. </view>
  115. </view>
  116. </template>
  117. <script>
  118. import {
  119. getUserDetail,
  120. getMenu,
  121. getAdv
  122. } from '@/api/common.js'
  123. import { search } from '@/api/shop.js';
  124. // 腾讯地图
  125. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  126. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  127. export default {
  128. data() {
  129. return {
  130. background:false,
  131. loading: false,
  132. userId: '',
  133. city:'定位中',
  134. status: 'more',
  135. current:0,
  136. bannerList:['https://alipic.lanhuapp.com/XDSlicePNGMAX2f4cb415a269b2e935c7a97da9077db4d78ddb8306ac44ec1e10274387048a22.png',
  137. 'https://alipic.lanhuapp.com/XDSlicePNGMAX2f4cb415a269b2e935c7a97da9077db4d78ddb8306ac44ec1e10274387048a22.png'],
  138. discountsList: [],//菜单
  139. advList:[],
  140. advList1:[],
  141. list: [],
  142. copyList: [],
  143. list1: [],
  144. copyList1: [],
  145. query:{
  146. queryName:'',
  147. 'location.lat':0,
  148. 'location.lon':0,
  149. pageCurrent:1,
  150. pageSize:10
  151. },
  152. }
  153. },
  154. methods: {
  155. // swiper变动
  156. swiperChange(val) {
  157. this.current = val.target.current
  158. },
  159. jump(url){
  160. uni.reLaunch({
  161. url
  162. })
  163. },
  164. // 点击搜索
  165. handleSearch(){
  166. if(!uni.getStorageSync('token')){
  167. return uni.showModal({
  168. title:'请登录',
  169. confirmText:'去登录',
  170. success(res){
  171. console.log(res);
  172. if(res.confirm){
  173. uni.navigateTo({
  174. url:'/login/login/login?redirect=/pages/index/index'
  175. })
  176. }
  177. }
  178. })
  179. }
  180. uni.reLaunch({
  181. url:'./search'
  182. })
  183. // if(!val) return
  184. // this.query.queryName = val
  185. // this.query.pageCurrent = 1
  186. // this.list = []
  187. // this.list1 = []
  188. // this.status = 'more'
  189. // this.search()
  190. },
  191. // 获取当前城市
  192. getCity(){
  193. let that = this
  194. this.city = '定位中'
  195. return new Promise((resolve,reject)=>{
  196. uni.getLocation({
  197. type: 'gcj02',
  198. success: (res) => {
  199. // 解析地址
  200. that.query['location.lat'] = res.latitude
  201. that.query['location.lon'] = res.longitude
  202. // 存储经纬度
  203. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  204. qqmapsdk.reverseGeocoder({
  205. location: {
  206. latitude: res.latitude,
  207. longitude: res.longitude
  208. },
  209. success: function(res) {
  210. // 市
  211. that.city = res.result.address_component.city
  212. console.log(9999,that.city,res);
  213. if(uni.setStorageSync('districtList')&&uni.getStorageSync('city')==that.city) return
  214. uni.setStorageSync('city',res.result.address_component.city)
  215. // 获取市区的行政区
  216. qqmapsdk.getDistrictByCityId({
  217. // 传入对应省份ID获得城市数据,传入城市ID获得区县数据,依次类推
  218. id: res.result.ad_info.city_code.substr(3), //对应接口getCityList返回数据的Id,如:北京是'110000'
  219. success: function(res) {//成功后的回调
  220. console.log('对应城市ID下的区县数据:', res.result[0]);
  221. let data = res.result[0]
  222. data.map(item=>{
  223. item.label = item.fullname
  224. })
  225. uni.setStorageSync('districtList',JSON.stringify(data))
  226. },
  227. fail: function(error) {
  228. console.error(error);
  229. },
  230. complete: function(res) {
  231. console.log(res);
  232. }
  233. });
  234. resolve()
  235. },
  236. fail: function(res) {
  237. that.city = '定位失败'
  238. },
  239. })
  240. },
  241. fail: () => {
  242. console.log("获取经纬度失败");
  243. },
  244. })
  245. })
  246. },
  247. // 跳转优惠详情
  248. goDetail(url,id,banner,title) {
  249. uni.navigateTo({
  250. url: `${url}?id=${id}&title=${title}`,
  251. success(res) {
  252. res.eventChannel.emit('banner', banner)
  253. }
  254. })
  255. },
  256. goGoodsDetail(item) {
  257. uni.setStorageSync('shopInfo', JSON.stringify(item))
  258. uni.navigateTo({
  259. url: `../../detail/goodsDetail/index?id=${item.goodsVos[0].goodsId}`
  260. })
  261. // uni.reLaunch({
  262. // url: `/signUp/index?id=${item.goodsVos[0].goodsId}`
  263. // })
  264. },
  265. // 更多套餐
  266. handleMore() {
  267. uni.reLaunch({
  268. // url:'../../login/login/login'
  269. url: '../../combo/combo/combo'
  270. })
  271. },
  272. // 获取用户详情
  273. getUserDetail() {
  274. getUserDetail().then(res => {
  275. uni.setStorageSync('userInfo', JSON.stringify(res.content))
  276. })
  277. },
  278. loadMore() {
  279. if(this.query['location.lat']&&this.query['location.lon']){
  280. this.search()
  281. }
  282. },
  283. search() {
  284. if(this.status == 'noMore' || this.status == 'loading') return
  285. console.log('加载数据',this.status,this.list,this.list1,this.query.pageCurrent);
  286. this.status = 'loading'
  287. search(this.query).then(res=>{
  288. if(res.state == 'Success'){
  289. this.loading = false
  290. let list = []
  291. let list1 = []
  292. let data = res.content.records
  293. data.map((item,index)=>{
  294. if(index%2 == 0){
  295. list.push(item)
  296. }else{
  297. list1.push(item)
  298. }
  299. })
  300. // 存储原始数据
  301. this.copyList = this.copyList.concat(list)
  302. this.copyList1 = this.copyList1.concat(list1)
  303. this.list = JSON.parse(JSON.stringify(this.copyList))
  304. this.list1 = JSON.parse(JSON.stringify(this.copyList1))
  305. if(this.query.pageCurrent == res.content.pages){
  306. this.status = 'noMore'
  307. }else{
  308. this.status = 'more'
  309. this.query.pageCurrent++
  310. }
  311. if(!this.advList1.length){
  312. this.getGoodsAdv().then(()=>{
  313. this.advList1.map(item=>{
  314. if(item.showSort<= (this.list.length + this.list1.length)){
  315. if((item.showSort-1)%2 == 0){
  316. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  317. }else{
  318. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  319. }
  320. }
  321. })
  322. }
  323. )
  324. }else{
  325. this.advList1.map(item=>{
  326. if(item.showSort<= (this.list.length + this.list1.length)){
  327. if((item.showSort-1)%2 == 0){
  328. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  329. }else{
  330. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  331. }
  332. }
  333. })
  334. }
  335. // 获取商品里面的广告
  336. // getAdv({currentPage:1,pageSize:99,advertsType:2,status:1}).then(res1=>{
  337. // if(res.state == 'Success'){
  338. // res1.content.records.map(item=>{
  339. // data.splice(item.showSort-1,0,{isAdv:true,...item})
  340. // })
  341. // console.log(data);
  342. // data.map((item,index)=>{
  343. // if(index%2){
  344. // list.push(item)
  345. // }else{
  346. // list1.push(item)
  347. // }
  348. // })
  349. // this.list = this.list.concat(list)
  350. // this.list1 = this.list1.concat(list1)
  351. // // let total = this.list.length+this.list1.length
  352. // // if(total>=res.content.total){
  353. // if(this.query.pageCurrent == res.content.pages){
  354. // this.status = 'noMore'
  355. // }else{
  356. // this.status = 'more'
  357. // this.query.pageCurrent++
  358. // }
  359. // }
  360. // })
  361. }
  362. })
  363. },
  364. // 金刚区
  365. getMenu(){
  366. return new Promise((resolve,reject)=>{
  367. getMenu({currentPage:1,pageSize:10,status:2}).then(res=>{
  368. if(res.state == 'Success'){
  369. this.discountsList = res.content.records
  370. resolve(1)
  371. }
  372. })
  373. })
  374. },
  375. // 广告位
  376. getAdv(){
  377. return new Promise((resolve,reject)=>{
  378. getAdv({currentPage:1,pageSize:10,advertsType:1,status:1,belongType:2}).then(res=>{
  379. if(res.state == 'Success'){
  380. this.advList = res.content.records
  381. // this.advList = res.content.records.filter((item,index)=>index<2)
  382. // this.advList1 = res.content.records.filter((item,index)=>index>=2)
  383. resolve(2)
  384. }
  385. })
  386. })
  387. },
  388. // 获取商品列表内广告位
  389. getGoodsAdv(){
  390. return new Promise((resolve,reject)=>{
  391. getAdv({currentPage:1,pageSize:99,advertsType:2,status:1,belongType:2}).then(res=>{
  392. if(res.state == 'Success'){
  393. this.advList1 = res.content.records
  394. resolve(2)
  395. }
  396. })
  397. })
  398. },
  399. },
  400. onPageScroll(e) {
  401. if(e.scrollTop >= 50){
  402. this.background = true
  403. }else{
  404. this.background = false
  405. }
  406. },
  407. onShow() {
  408. if (uni.getStorageSync('token')&&!uni.getStorageSync('userInfo')) {
  409. this.getUserDetail()
  410. }
  411. },
  412. onHide() {},
  413. onLoad(query){
  414. uni.setStorageSync('inviteCode',decodeURIComponent(query.scene))
  415. },
  416. created() {
  417. // this.loading = true
  418. Promise.all([this.getMenu(),this.getAdv(),this.getCity()]).then(res=>{
  419. this.search()
  420. })
  421. }
  422. }
  423. </script>
  424. <style lang="scss">
  425. .home {
  426. // padding-bottom:120rpx;
  427. // background: linear-gradient(180deg, #FFFFFF 0%, #DCE8FF 100%);
  428. background: #F9F9F9;
  429. .card-title {
  430. display: flex;
  431. justify-content: center;
  432. .title {
  433. font-size: 32rpx;
  434. text-align: center;
  435. color: #fff;
  436. width: 210rpx;
  437. line-height: 64rpx;
  438. background: linear-gradient(360deg, #3074F8 0%, #568FFF 100%);
  439. border-radius: 0rpx 0rpx 24rpx 24rpx;
  440. }
  441. }
  442. .login-home {
  443. // background: linear-gradient(178deg, #FFFFFF 0%, #F9F9F9 100%);
  444. // background: #FFF;
  445. .discount-list {
  446. display: flex;
  447. flex-wrap: wrap;
  448. // padding: 30rpx 0;
  449. margin: 0 24rpx 20rpx;
  450. // background: #fff;
  451. border-radius: 16rpx;
  452. position: relative;
  453. top: 20rpx;
  454. padding-top: 20rpx;
  455. .discount-item {
  456. width: 20%;
  457. display: flex;
  458. flex-direction: column;
  459. align-items: center;
  460. margin-top: 20rpx;
  461. margin-bottom: 20rpx;
  462. position: relative;
  463. .icon {
  464. width: 80rpx;
  465. height: 80rpx;
  466. }
  467. .title {
  468. font-size: 24rpx;
  469. margin-top: 10rpx;
  470. font-weight: 300;
  471. color: #222222;
  472. }
  473. .tag {
  474. position: absolute;
  475. top: -20rpx;
  476. left: 50%;
  477. background: #FF0615;
  478. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  479. border-radius: 14rpx 14rpx 14rpx 0rpx;
  480. color: #fff;
  481. white-space: nowrap;
  482. font-size: 18rpx;
  483. line-height: 24rpx;
  484. height: 24rpx;
  485. padding: 0 10rpx;
  486. // width: fit-content;
  487. // background-size: 100% 34rpx;
  488. }
  489. .desc {
  490. color: #FF0817;
  491. font-size: 16rpx;
  492. text-align: center;
  493. margin-top: 4rpx;
  494. }
  495. }
  496. }
  497. .title-img {
  498. width: 686rpx;
  499. height: 166rpx;
  500. margin: 24rpx 32rpx;
  501. }
  502. .swiper-box{
  503. position: relative;
  504. margin: 0 24rpx 20rpx;
  505. padding-top: 20rpx;
  506. width: 702rpx;
  507. height: 284rpx;
  508. border-radius: 16rpx;
  509. .progress{
  510. position: absolute;
  511. top: 38rpx;
  512. right: 20rpx;
  513. z-index: 2;
  514. color: #FFFFFF;
  515. font-size: 16rpx;
  516. background: rgba(255, 255, 255, 0.3);
  517. padding: 2rpx 10rpx;
  518. border-radius: 14rpx;
  519. }
  520. .swiper {
  521. position: relative;
  522. height: 100%;
  523. .swiper-item {
  524. width: 100%;
  525. height: 100%;
  526. border-radius: 16rpx;
  527. object-fit: cover;
  528. }
  529. }
  530. }
  531. .advertise-box {
  532. display: flex;
  533. justify-content: space-between;
  534. margin: 0 24rpx;
  535. padding: 20rpx 0;
  536. }
  537. .content {
  538. border-radius: 16rpx 16rpx 0 0;
  539. }
  540. .zs-list {
  541. display: flex;
  542. flex-wrap: wrap;
  543. justify-content: space-between;
  544. padding: 0 24rpx;
  545. .left {
  546. .adv-swiper{
  547. width: 340rpx;
  548. height: 444rpx;
  549. margin-bottom: 25rpx;
  550. .adv-item{
  551. width: 340rpx;
  552. height: 444rpx;
  553. }
  554. }
  555. }
  556. .ad{
  557. width: 340rpx;
  558. border-radius: 16rpx;
  559. }
  560. .store-item {
  561. width: 340rpx;
  562. margin-bottom: 20rpx;
  563. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  564. border-radius: 16rpx;
  565. background: #fff;
  566. .icon {
  567. width: 100%;
  568. height: 300rpx;
  569. border-radius: 16rpx 16rpx 0 0;
  570. }
  571. .info{
  572. flex: 1;
  573. padding: 16rpx;
  574. display: flex;
  575. flex-direction: column;
  576. justify-content: space-between;
  577. position: relative;
  578. .title{
  579. font-size: 28rpx;
  580. font-weight: bold;
  581. width: 100%;
  582. white-space: nowrap;
  583. overflow: hidden;
  584. text-overflow: ellipsis;
  585. margin-top: 10rpx;
  586. }
  587. .desc{
  588. font-size: 24rpx;
  589. color: #AAAAAA;
  590. overflow: hidden;
  591. text-overflow: ellipsis;
  592. /* 弹性伸缩盒子模型显示 */
  593. display: -webkit-box;
  594. /* 限制在一个块元素显示的文本的行数 */
  595. -webkit-line-clamp: 2;
  596. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  597. -webkit-box-orient: vertical;
  598. margin-top: 12rpx;
  599. }
  600. .price-box{
  601. display: flex;
  602. justify-content: space-between;
  603. align-items: center;
  604. margin-top: 12rpx;
  605. .left{
  606. display: flex;
  607. align-items: flex-end;
  608. .unit{
  609. font-size: 20rpx;
  610. color: $uni-color-primary;
  611. font-weight: bold;
  612. }
  613. .price{
  614. font-size: 32rpx;
  615. color: $uni-color-primary;
  616. font-weight: bold;
  617. }
  618. }
  619. .right{
  620. font-size: 24rpx;
  621. color: #AAAAAA;
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. }
  629. </style>