index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. <zs-tab-bar :value="2"></zs-tab-bar>
  114. </view>
  115. </template>
  116. <script>
  117. import {
  118. getUserDetail,
  119. getMenu,
  120. getAdv
  121. } from '@/api/common.js'
  122. import { search } from '@/api/shop.js';
  123. // 腾讯地图
  124. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  125. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  126. export default {
  127. data() {
  128. return {
  129. background:false,
  130. loading: false,
  131. userId: '',
  132. city:'定位中',
  133. status: 'more',
  134. current:0,
  135. bannerList:[],
  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({
  279. ...this.query,
  280. belongType:2,
  281. isExceptGZU:true
  282. }).then(res=>{
  283. if(res.state == 'Success'){
  284. this.loading = false
  285. let list = []
  286. let list1 = []
  287. let data = res.content.records
  288. data.map((item,index)=>{
  289. if(index%2 == 0){
  290. list.push(item)
  291. }else{
  292. list1.push(item)
  293. }
  294. })
  295. this.list = this.list.concat(list)
  296. this.list1 = this.list1.concat(list1)
  297. if(this.query.pageCurrent == res.content.pages){
  298. this.status = 'noMore'
  299. }else{
  300. this.status = 'more'
  301. this.query.pageCurrent++
  302. }
  303. if(!this.advList1.length){
  304. this.getGoodsAdv().then(()=>{
  305. this.advList1.map(item=>{
  306. if(item.showSort<= (this.list.length + this.list1.length)){
  307. if((item.showSort-1)%2 == 0){
  308. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  309. }else{
  310. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  311. }
  312. }
  313. })
  314. }
  315. )
  316. }else{
  317. this.advList1.map(item=>{
  318. if(item.showSort<= (this.list.length + this.list1.length)){
  319. if((item.showSort-1)%2 == 0){
  320. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  321. }else{
  322. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  323. }
  324. }
  325. })
  326. }
  327. // 获取商品里面的广告
  328. // getAdv({currentPage:1,pageSize:99,advertsType:2,status:1}).then(res1=>{
  329. // if(res.state == 'Success'){
  330. // res1.content.records.map(item=>{
  331. // data.splice(item.showSort-1,0,{isAdv:true,...item})
  332. // })
  333. // console.log(data);
  334. // data.map((item,index)=>{
  335. // if(index%2){
  336. // list.push(item)
  337. // }else{
  338. // list1.push(item)
  339. // }
  340. // })
  341. // this.list = this.list.concat(list)
  342. // this.list1 = this.list1.concat(list1)
  343. // // let total = this.list.length+this.list1.length
  344. // // if(total>=res.content.total){
  345. // if(this.query.pageCurrent == res.content.pages){
  346. // this.status = 'noMore'
  347. // }else{
  348. // this.status = 'more'
  349. // this.query.pageCurrent++
  350. // }
  351. // }
  352. // })
  353. }
  354. })
  355. },
  356. // 金刚区
  357. getMenu(){
  358. return new Promise((resolve,reject)=>{
  359. getMenu({belongType: 1,currentPage:1,pageSize:10,status:2}).then(res=>{
  360. if(res.state == 'Success'){
  361. this.discountsList = res.content.records
  362. resolve(1)
  363. }
  364. })
  365. })
  366. },
  367. // 广告位
  368. getAdv(){
  369. return new Promise((resolve,reject)=>{
  370. getAdv({belongType:2,currentPage:1,pageSize:99,advertsType:1,status:1}).then(res=>{
  371. if(res.state == 'Success'){
  372. this.advList = res.content.records
  373. // this.advList = res.content.records.filter((item,index)=>index<2)
  374. // this.advList1 = res.content.records.filter((item,index)=>index>=2)
  375. resolve(2)
  376. }
  377. })
  378. })
  379. },
  380. // 获取商品列表内广告位
  381. getGoodsAdv(){
  382. return new Promise((resolve,reject)=>{
  383. getAdv({belongType:2,currentPage:1,pageSize:99,advertsType:2,status:1}).then(res=>{
  384. if(res.state == 'Success'){
  385. this.advList1 = res.content.records
  386. resolve(2)
  387. }
  388. })
  389. })
  390. },
  391. },
  392. onPageScroll(e) {
  393. if(e.scrollTop >= 50){
  394. this.background = true
  395. }else{
  396. this.background = false
  397. }
  398. },
  399. onShow() {
  400. if (uni.getStorageSync('token')&&!uni.getStorageSync('userInfo')) {
  401. this.getUserDetail()
  402. }
  403. },
  404. onHide() {},
  405. onLoad(query){
  406. uni.setStorageSync('inviteCode',decodeURIComponent(query.scene))
  407. },
  408. created() {
  409. this.loading = true
  410. Promise.all([this.getMenu(),this.getAdv(),this.getCity()]).then(res=>{
  411. this.search()
  412. })
  413. }
  414. }
  415. </script>
  416. <style lang="scss">
  417. .home {
  418. // padding-bottom:120rpx;
  419. // background: linear-gradient(180deg, #FFFFFF 0%, #DCE8FF 100%);
  420. background: #F9F9F9;
  421. .card-title {
  422. display: flex;
  423. justify-content: center;
  424. .title {
  425. font-size: 32rpx;
  426. text-align: center;
  427. color: #fff;
  428. width: 210rpx;
  429. line-height: 64rpx;
  430. background: linear-gradient(360deg, #3074F8 0%, #568FFF 100%);
  431. border-radius: 0rpx 0rpx 24rpx 24rpx;
  432. }
  433. }
  434. .login-home {
  435. // background: linear-gradient(178deg, #FFFFFF 0%, #F9F9F9 100%);
  436. // background: #FFF;
  437. .discount-list {
  438. display: flex;
  439. flex-wrap: wrap;
  440. // padding: 30rpx 0;
  441. margin: 0 24rpx 20rpx;
  442. // background: #fff;
  443. border-radius: 16rpx;
  444. position: relative;
  445. top: 20rpx;
  446. padding-top: 20rpx;
  447. .discount-item {
  448. width: 20%;
  449. display: flex;
  450. flex-direction: column;
  451. align-items: center;
  452. margin-top: 20rpx;
  453. margin-bottom: 20rpx;
  454. position: relative;
  455. .icon {
  456. width: 80rpx;
  457. height: 80rpx;
  458. }
  459. .title {
  460. font-size: 24rpx;
  461. margin-top: 10rpx;
  462. font-weight: 300;
  463. color: #222222;
  464. }
  465. .tag {
  466. position: absolute;
  467. top: -20rpx;
  468. left: 50%;
  469. background: #FF0615;
  470. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  471. border-radius: 12rpx 14rpx 14rpx 0rpx;
  472. color: #fff;
  473. white-space: nowrap;
  474. font-size: 18rpx;
  475. line-height: 24rpx;
  476. height: 24rpx;
  477. padding: 0 10rpx;
  478. z-index: 1;
  479. // width: fit-content;
  480. background-size: 100% 34rpx;
  481. }
  482. .desc {
  483. color: #FF0817;
  484. font-size: 16rpx;
  485. text-align: center;
  486. margin-top: 4rpx;
  487. }
  488. }
  489. }
  490. .title-img {
  491. width: 686rpx;
  492. height: 166rpx;
  493. margin: 24rpx 32rpx;
  494. }
  495. .swiper-box{
  496. position: relative;
  497. margin: 0 24rpx 20rpx;
  498. padding-top: 20rpx;
  499. width: 702rpx;
  500. height: 284rpx;
  501. border-radius: 16rpx;
  502. .progress{
  503. position: absolute;
  504. top: 38rpx;
  505. right: 20rpx;
  506. z-index: 2;
  507. color: #FFFFFF;
  508. font-size: 16rpx;
  509. background: rgba(255, 255, 255, 0.3);
  510. padding: 2rpx 10rpx;
  511. border-radius: 14rpx;
  512. }
  513. .swiper {
  514. position: relative;
  515. height: 100%;
  516. .swiper-item {
  517. width: 100%;
  518. height: 100%;
  519. border-radius: 16rpx;
  520. object-fit: cover;
  521. }
  522. }
  523. }
  524. .advertise-box {
  525. display: flex;
  526. justify-content: space-between;
  527. margin: 0 24rpx;
  528. padding: 20rpx 0;
  529. }
  530. .content {
  531. border-radius: 16rpx 16rpx 0 0;
  532. }
  533. .zs-list {
  534. display: flex;
  535. flex-wrap: wrap;
  536. justify-content: space-between;
  537. padding: 0 24rpx;
  538. .left {
  539. .adv-swiper{
  540. width: 340rpx;
  541. height: 444rpx;
  542. margin-bottom: 25rpx;
  543. .adv-item{
  544. width: 340rpx;
  545. height: 444rpx;
  546. }
  547. }
  548. }
  549. .ad{
  550. width: 340rpx;
  551. border-radius: 16rpx;
  552. }
  553. .store-item {
  554. width: 340rpx;
  555. margin-bottom: 20rpx;
  556. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  557. border-radius: 16rpx;
  558. background: #fff;
  559. .icon {
  560. width: 100%;
  561. height: 300rpx;
  562. border-radius: 16rpx 16rpx 0 0;
  563. }
  564. .info{
  565. flex: 1;
  566. padding: 16rpx;
  567. display: flex;
  568. flex-direction: column;
  569. justify-content: space-between;
  570. position: relative;
  571. .title{
  572. font-size: 28rpx;
  573. font-weight: bold;
  574. width: 100%;
  575. white-space: nowrap;
  576. overflow: hidden;
  577. text-overflow: ellipsis;
  578. margin-top: 10rpx;
  579. }
  580. .desc{
  581. font-size: 24rpx;
  582. color: #AAAAAA;
  583. overflow: hidden;
  584. text-overflow: ellipsis;
  585. /* 弹性伸缩盒子模型显示 */
  586. display: -webkit-box;
  587. /* 限制在一个块元素显示的文本的行数 */
  588. -webkit-line-clamp: 2;
  589. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  590. -webkit-box-orient: vertical;
  591. margin-top: 12rpx;
  592. }
  593. .price-box{
  594. display: flex;
  595. justify-content: space-between;
  596. align-items: center;
  597. margin-top: 12rpx;
  598. .left{
  599. display: flex;
  600. align-items: flex-end;
  601. .unit{
  602. font-size: 20rpx;
  603. color: #FF4D3A;
  604. font-weight: bold;
  605. }
  606. .price{
  607. font-size: 32rpx;
  608. color: #FF4D3A;
  609. font-weight: bold;
  610. }
  611. }
  612. .right{
  613. font-size: 24rpx;
  614. color: #AAAAAA;
  615. }
  616. }
  617. }
  618. }
  619. }
  620. }
  621. }
  622. </style>