index.vue.bak 16 KB

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