index.vue 18 KB

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