index.vue 17 KB

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