index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. 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. if(uni.setStorageSync('districtList')&&uni.getStorageSync('city')==that.city) return
  213. uni.setStorageSync('city',res.result.address_component.city)
  214. // 获取市区的行政区
  215. qqmapsdk.getDistrictByCityId({
  216. // 传入对应省份ID获得城市数据,传入城市ID获得区县数据,依次类推
  217. id: res.result.ad_info.city_code.substr(3), //对应接口getCityList返回数据的Id,如:北京是'110000'
  218. success: function(res) {//成功后的回调
  219. console.log('对应城市ID下的区县数据:', res.result[0]);
  220. let data = res.result[0]
  221. data.map(item=>{
  222. item.label = item.fullname
  223. })
  224. uni.setStorageSync('districtList',JSON.stringify(data))
  225. },
  226. fail: function(error) {
  227. console.error(error);
  228. },
  229. complete: function(res) {
  230. console.log(res);
  231. }
  232. });
  233. resolve()
  234. },
  235. fail: function(res) {
  236. that.city = '定位失败'
  237. },
  238. })
  239. },
  240. fail: () => {
  241. console.log("获取经纬度失败");
  242. },
  243. })
  244. })
  245. },
  246. // 跳转优惠详情
  247. goDetail(url,id,banner,title) {
  248. uni.navigateTo({
  249. url: `${url}?id=${id}&title=${title}`,
  250. success(res) {
  251. res.eventChannel.emit('banner', banner)
  252. }
  253. })
  254. },
  255. goGoodsDetail(item) {
  256. uni.setStorageSync('shopInfo', JSON.stringify(item))
  257. uni.navigateTo({
  258. url: `../../detail/goodsDetail/index?id=${item.goodsVos[0].goodsId}`
  259. })
  260. // uni.reLaunch({
  261. // url: `/signUp/index?id=${item.goodsVos[0].goodsId}`
  262. // })
  263. },
  264. // 更多套餐
  265. handleMore() {
  266. uni.reLaunch({
  267. // url:'../../login/login/login'
  268. url: '../../combo/combo/combo'
  269. })
  270. },
  271. // 获取用户详情
  272. getUserDetail() {
  273. getUserDetail().then(res => {
  274. uni.setStorageSync('userInfo', JSON.stringify(res.content))
  275. })
  276. },
  277. loadMore() {
  278. if(this.query['location.lat']&&this.query['location.lon']){
  279. this.search()
  280. }
  281. },
  282. search() {
  283. if(this.status == 'noMore' || this.status == 'loading') return
  284. console.log('加载数据',this.status,this.list,this.list1,this.query.pageCurrent);
  285. this.status = 'loading'
  286. search(this.query).then(res=>{
  287. if(res.state == 'Success'){
  288. this.loading = false
  289. let list = []
  290. let list1 = []
  291. let data = res.content.records
  292. data.map((item,index)=>{
  293. if(index%2 == 0){
  294. list.push(item)
  295. }else{
  296. list1.push(item)
  297. }
  298. })
  299. // 存储原始数据
  300. this.copyList = this.copyList.concat(list)
  301. this.copyList1 = this.copyList1.concat(list1)
  302. this.list = JSON.parse(JSON.stringify(this.copyList))
  303. this.list1 = JSON.parse(JSON.stringify(this.copyList1))
  304. if(this.query.pageCurrent == res.content.pages){
  305. this.status = 'noMore'
  306. }else{
  307. this.status = 'more'
  308. this.query.pageCurrent++
  309. }
  310. if(!this.advList1.length){
  311. this.getGoodsAdv().then(()=>{
  312. this.advList1.map(item=>{
  313. if(item.showSort<= (this.list.length + this.list1.length)){
  314. if((item.showSort-1)%2 == 0){
  315. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  316. }else{
  317. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  318. }
  319. }
  320. })
  321. }
  322. )
  323. }else{
  324. this.advList1.map(item=>{
  325. if(item.showSort<= (this.list.length + this.list1.length)){
  326. if((item.showSort-1)%2 == 0){
  327. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  328. }else{
  329. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  330. }
  331. }
  332. })
  333. }
  334. // 获取商品里面的广告
  335. // getAdv({currentPage:1,pageSize:99,advertsType:2,status:1}).then(res1=>{
  336. // if(res.state == 'Success'){
  337. // res1.content.records.map(item=>{
  338. // data.splice(item.showSort-1,0,{isAdv:true,...item})
  339. // })
  340. // console.log(data);
  341. // data.map((item,index)=>{
  342. // if(index%2){
  343. // list.push(item)
  344. // }else{
  345. // list1.push(item)
  346. // }
  347. // })
  348. // this.list = this.list.concat(list)
  349. // this.list1 = this.list1.concat(list1)
  350. // // let total = this.list.length+this.list1.length
  351. // // if(total>=res.content.total){
  352. // if(this.query.pageCurrent == res.content.pages){
  353. // this.status = 'noMore'
  354. // }else{
  355. // this.status = 'more'
  356. // this.query.pageCurrent++
  357. // }
  358. // }
  359. // })
  360. }
  361. })
  362. },
  363. // 金刚区
  364. getMenu(){
  365. return new Promise((resolve,reject)=>{
  366. getMenu({currentPage:1,pageSize:10,status:2,belongType:2}).then(res=>{
  367. if(res.state == 'Success'){
  368. this.discountsList = res.content.records
  369. resolve(1)
  370. }
  371. })
  372. })
  373. },
  374. // 广告位
  375. getAdv(){
  376. return new Promise((resolve,reject)=>{
  377. getAdv({currentPage:1,pageSize:10,advertsType:1,status:1,belongType:2}).then(res=>{
  378. if(res.state == 'Success'){
  379. this.advList = res.content.records
  380. // this.advList = res.content.records.filter((item,index)=>index<2)
  381. // this.advList1 = res.content.records.filter((item,index)=>index>=2)
  382. resolve(2)
  383. }
  384. })
  385. })
  386. },
  387. // 弹窗广告
  388. getDialogAdv() {
  389. let loginShow
  390. if(uni.getStorageSync('token')){
  391. loginShow = 2
  392. }else{
  393. loginShow = 1
  394. }
  395. getAdv({
  396. currentPage: 1,
  397. pageSize: 99,
  398. status:1,
  399. belongType: 2,
  400. loginShow,
  401. advertsType: 6,
  402. }).then((res) => {
  403. if (res.state == "Success") {
  404. this.dialogAdvList = res.content.records
  405. }
  406. });
  407. },
  408. // 获取商品列表内广告位
  409. getGoodsAdv(){
  410. return new Promise((resolve,reject)=>{
  411. getAdv({currentPage:1,pageSize:99,advertsType:2,status:1,belongType:2}).then(res=>{
  412. if(res.state == 'Success'){
  413. this.advList1 = res.content.records
  414. resolve(2)
  415. }
  416. })
  417. })
  418. },
  419. },
  420. onPageScroll(e) {
  421. if(e.scrollTop >= 50){
  422. this.background = true
  423. }else{
  424. this.background = false
  425. }
  426. },
  427. onShow() {
  428. if (uni.getStorageSync('token')&&!uni.getStorageSync('userInfo')) {
  429. this.getUserDetail()
  430. }
  431. },
  432. onHide() {
  433. },
  434. onLoad(query){
  435. if(query.scene){
  436. if(!uni.getStorageSync('token')){
  437. uni.showToast({
  438. title: '已经是平台用户',
  439. icon: 'none'
  440. });
  441. return
  442. }
  443. uni.setStorageSync('inviteCode',decodeURIComponent(query.scene))
  444. }
  445. },
  446. onShareTimeline() {
  447. return {
  448. title: "慧研学惠生活",
  449. query: "id=1",
  450. imageUrl: "https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/XHBjBiMRhVYG8f1a30bbbd80c2346197b81470444c9a.png/1.png",
  451. };
  452. },
  453. onShareAppMessage() {
  454. return {
  455. title: "慧研学惠生活",
  456. path: "/pages/index/index",
  457. };
  458. },
  459. created() {
  460. this.loading = true
  461. this.getDialogAdv()
  462. Promise.all([this.getMenu(),this.getAdv(),this.getCity()]).then(res=>{
  463. this.search()
  464. })
  465. }
  466. }
  467. </script>
  468. <style lang="scss">
  469. .home {
  470. // padding-bottom:120rpx;
  471. // background: linear-gradient(180deg, #FFFFFF 0%, #DCE8FF 100%);
  472. background: #F9F9F9;
  473. .card-title {
  474. display: flex;
  475. justify-content: center;
  476. .title {
  477. font-size: 32rpx;
  478. text-align: center;
  479. color: #fff;
  480. width: 210rpx;
  481. line-height: 64rpx;
  482. background: linear-gradient(360deg, #3074F8 0%, #568FFF 100%);
  483. border-radius: 0rpx 0rpx 24rpx 24rpx;
  484. }
  485. }
  486. .login-home {
  487. // background: linear-gradient(178deg, #FFFFFF 0%, #F9F9F9 100%);
  488. // background: #FFF;
  489. .discount-list {
  490. display: flex;
  491. flex-wrap: wrap;
  492. // padding: 30rpx 0;
  493. margin: 0 24rpx 20rpx;
  494. // background: #fff;
  495. border-radius: 16rpx;
  496. position: relative;
  497. top: 20rpx;
  498. padding-top: 20rpx;
  499. .discount-item {
  500. width: 20%;
  501. display: flex;
  502. flex-direction: column;
  503. align-items: center;
  504. margin-top: 20rpx;
  505. margin-bottom: 20rpx;
  506. position: relative;
  507. .icon {
  508. width: 80rpx;
  509. height: 80rpx;
  510. }
  511. .title {
  512. font-size: 24rpx;
  513. margin-top: 10rpx;
  514. font-weight: 300;
  515. color: #222222;
  516. }
  517. .tag {
  518. position: absolute;
  519. top: -20rpx;
  520. left: 50%;
  521. background: #FF0615;
  522. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  523. border-radius: 14rpx 14rpx 14rpx 0rpx;
  524. color: #fff;
  525. white-space: nowrap;
  526. font-size: 18rpx;
  527. line-height: 24rpx;
  528. height: 24rpx;
  529. padding: 0 10rpx;
  530. // width: fit-content;
  531. // background-size: 100% 34rpx;
  532. }
  533. .desc {
  534. color: #FF0817;
  535. font-size: 16rpx;
  536. text-align: center;
  537. margin-top: 4rpx;
  538. }
  539. }
  540. }
  541. .title-img {
  542. width: 686rpx;
  543. height: 166rpx;
  544. margin: 24rpx 32rpx;
  545. }
  546. .swiper-box{
  547. position: relative;
  548. width: 344rpx;
  549. height: 462rpx;
  550. border-radius: 16rpx;
  551. margin-bottom: 20rpx;
  552. .progress{
  553. position: absolute;
  554. top: 38rpx;
  555. right: 20rpx;
  556. z-index: 2;
  557. color: #FFFFFF;
  558. font-size: 16rpx;
  559. background: rgba(255, 255, 255, 0.3);
  560. padding: 2rpx 10rpx;
  561. border-radius: 14rpx;
  562. }
  563. .swiper {
  564. position: relative;
  565. height: 100%;
  566. .swiper-item {
  567. width: 344rpx;
  568. height: 462rpx;
  569. border-radius: 16rpx;
  570. object-fit: cover;
  571. }
  572. }
  573. }
  574. .advertise-box {
  575. display: flex;
  576. justify-content: space-between;
  577. margin: 0 24rpx;
  578. padding: 20rpx 0;
  579. }
  580. .content {
  581. border-radius: 16rpx 16rpx 0 0;
  582. }
  583. .zs-list {
  584. display: flex;
  585. flex-wrap: wrap;
  586. justify-content: space-between;
  587. padding: 0 24rpx;
  588. .left {
  589. .adv-swiper{
  590. width: 340rpx;
  591. height: 444rpx;
  592. margin-bottom: 25rpx;
  593. .adv-item{
  594. width: 340rpx;
  595. height: 444rpx;
  596. }
  597. }
  598. }
  599. .ad{
  600. width: 340rpx;
  601. border-radius: 16rpx;
  602. }
  603. .store-item {
  604. width: 344rpx;
  605. margin-bottom: 20rpx;
  606. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  607. border-radius: 16rpx;
  608. background: #fff;
  609. .icon {
  610. width: 100%;
  611. height: 300rpx;
  612. border-radius: 16rpx 16rpx 0 0;
  613. }
  614. .info{
  615. flex: 1;
  616. padding: 16rpx;
  617. display: flex;
  618. flex-direction: column;
  619. justify-content: space-between;
  620. position: relative;
  621. .title{
  622. font-size: 28rpx;
  623. font-weight: bold;
  624. width: 100%;
  625. white-space: nowrap;
  626. overflow: hidden;
  627. text-overflow: ellipsis;
  628. margin-top: 10rpx;
  629. }
  630. .desc{
  631. font-size: 24rpx;
  632. color: #AAAAAA;
  633. overflow: hidden;
  634. text-overflow: ellipsis;
  635. /* 弹性伸缩盒子模型显示 */
  636. display: -webkit-box;
  637. /* 限制在一个块元素显示的文本的行数 */
  638. -webkit-line-clamp: 2;
  639. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  640. -webkit-box-orient: vertical;
  641. margin-top: 12rpx;
  642. }
  643. .price-box{
  644. display: flex;
  645. justify-content: space-between;
  646. align-items: center;
  647. margin-top: 12rpx;
  648. .left{
  649. display: flex;
  650. align-items: flex-end;
  651. .unit{
  652. font-size: 20rpx;
  653. color: $uni-color-primary;
  654. font-weight: bold;
  655. }
  656. .price{
  657. font-size: 32rpx;
  658. color: $uni-color-primary;
  659. font-weight: bold;
  660. }
  661. .old-price{
  662. font-size: 20rpx;
  663. color: #AAAAAA;
  664. text-decoration: line-through;
  665. margin-left: 12rpx;
  666. }
  667. }
  668. .right{
  669. font-size: 24rpx;
  670. color: #AAAAAA;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. }
  678. </style>