index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <view class="home">
  3. <view class="login-home">
  4. <image class="img" src="https://oss.dev.zonelife.cn/static/guida/img/life/hold_on2.png"></image>
  5. <view class="text">
  6. 印象生活,尽请期待...
  7. </view>
  8. </view>
  9. <zs-tab-bar :value="2"></zs-tab-bar>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. getUserDetail,
  15. getMenu,
  16. getAdv
  17. } from '@/api/common.js'
  18. import { search } from '@/api/shop.js';
  19. // 腾讯地图
  20. var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
  21. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  22. export default {
  23. data() {
  24. return {
  25. background:false,
  26. loading: false,
  27. userId: '',
  28. city:'定位中',
  29. status: 'more',
  30. current:0,
  31. bannerList:[],
  32. discountsList: [],//菜单
  33. advList:[],
  34. advList1:[],
  35. holdList:[
  36. {
  37. advertsImg:'https://oss.dev.zonelife.cn/static/guida/img/life/hold_on.jpg',
  38. id:1
  39. }
  40. ],
  41. list: [],
  42. list1: [],
  43. query:{
  44. queryName:'',
  45. 'location.lat':0,
  46. 'location.lon':0,
  47. pageCurrent:1,
  48. pageSize:10
  49. },
  50. }
  51. },
  52. methods: {
  53. // swiper变动
  54. swiperChange(val) {
  55. this.current = val.target.current
  56. },
  57. jump(url){
  58. uni.reLaunch({
  59. url
  60. })
  61. },
  62. // 点击搜索
  63. handleSearch(){
  64. if(!uni.getStorageSync('token')){
  65. return uni.showModal({
  66. title:'请登录',
  67. confirmText:'去登录',
  68. success(res){
  69. console.log(res);
  70. if(res.confirm){
  71. uni.navigateTo({
  72. url:'/login/login/login?redirect=/pages/index/index'
  73. })
  74. }
  75. }
  76. })
  77. }
  78. uni.reLaunch({
  79. url:'./search'
  80. })
  81. // if(!val) return
  82. // this.query.queryName = val
  83. // this.query.pageCurrent = 1
  84. // this.list = []
  85. // this.list1 = []
  86. // this.status = 'more'
  87. // this.search()
  88. },
  89. // 获取当前城市
  90. getCity(){
  91. let that = this
  92. return new Promise((resolve,reject)=>{
  93. uni.getLocation({
  94. type: 'gcj02',
  95. success: (res) => {
  96. // 解析地址
  97. that.query['location.lat'] = res.latitude
  98. that.query['location.lon'] = res.longitude
  99. // 存储经纬度
  100. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  101. qqmapsdk.reverseGeocoder({
  102. location: {
  103. latitude: res.latitude,
  104. longitude: res.longitude
  105. },
  106. success: function(res) {
  107. // 市
  108. that.city = res.result.address_component.city
  109. console.log(9999,that.city,res);
  110. if(uni.setStorageSync('districtList')&&uni.getStorageSync('city')==that.city) return
  111. uni.setStorageSync('city',res.result.address_component.city)
  112. // 获取市区的行政区
  113. qqmapsdk.getDistrictByCityId({
  114. // 传入对应省份ID获得城市数据,传入城市ID获得区县数据,依次类推
  115. id: res.result.ad_info.city_code.substr(3), //对应接口getCityList返回数据的Id,如:北京是'110000'
  116. success: function(res) {//成功后的回调
  117. console.log('对应城市ID下的区县数据:', res.result[0]);
  118. let data = res.result[0]
  119. data.map(item=>{
  120. item.label = item.fullname
  121. })
  122. uni.setStorageSync('districtList',JSON.stringify(data))
  123. },
  124. fail: function(error) {
  125. console.error(error);
  126. },
  127. complete: function(res) {
  128. console.log(res);
  129. }
  130. });
  131. resolve()
  132. },
  133. fail: function(res) {
  134. that.city = '定位失败'
  135. },
  136. })
  137. },
  138. fail: () => {
  139. console.log("获取经纬度失败");
  140. },
  141. })
  142. })
  143. },
  144. // 跳转优惠详情
  145. goDetail(url,id,banner,title) {
  146. uni.navigateTo({
  147. url: `${url}?id=${id}&title=${title}`,
  148. success(res) {
  149. res.eventChannel.emit('banner', banner)
  150. }
  151. })
  152. },
  153. goGoodsDetail(item) {
  154. uni.setStorageSync('shopInfo', JSON.stringify(item))
  155. uni.reLaunch({
  156. url: `../../detail/goodsDetail/index?id=${item.goodsVos[0].goodsId}`
  157. })
  158. },
  159. // 更多套餐
  160. handleMore() {
  161. uni.reLaunch({
  162. // url:'../../login/login/login'
  163. url: '../../combo/combo/combo'
  164. })
  165. },
  166. // 获取用户详情
  167. getUserDetail() {
  168. getUserDetail().then(res => {
  169. uni.setStorageSync('userInfo', JSON.stringify(res.content))
  170. })
  171. },
  172. loadMore() {
  173. if(this.query['location.lat']&&this.query['location.lon']){
  174. this.search()
  175. }
  176. },
  177. search() {
  178. if(this.status == 'noMore') return
  179. this.status = 'loading'
  180. search({
  181. ...this.query,
  182. belongType:2,
  183. isExceptGZU:true
  184. }).then(res=>{
  185. if(res.state == 'Success'){
  186. this.loading = false
  187. let list = []
  188. let list1 = []
  189. let data = res.content.records
  190. data.map((item,index)=>{
  191. if(index%2 == 0){
  192. list.push(item)
  193. }else{
  194. list1.push(item)
  195. }
  196. })
  197. this.list = this.list.concat(list)
  198. this.list1 = this.list1.concat(list1)
  199. if(this.query.pageCurrent == res.content.pages){
  200. this.status = 'noMore'
  201. }else{
  202. this.status = 'more'
  203. this.query.pageCurrent++
  204. }
  205. if(!this.advList1.length){
  206. this.getGoodsAdv().then(()=>{
  207. this.advList1.map(item=>{
  208. if(item.showSort<= (this.list.length + this.list1.length)){
  209. if((item.showSort-1)%2 == 0){
  210. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  211. }else{
  212. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  213. }
  214. }
  215. })
  216. }
  217. )
  218. }else{
  219. this.advList1.map(item=>{
  220. if(item.showSort<= (this.list.length + this.list1.length)){
  221. if((item.showSort-1)%2 == 0){
  222. this.list.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  223. }else{
  224. this.list1.splice(Math.ceil(item.showSort/2)-1,0,{isAdv:true,...item})
  225. }
  226. }
  227. })
  228. }
  229. // 获取商品里面的广告
  230. // getAdv({currentPage:1,pageSize:99,advertsType:2,status:1}).then(res1=>{
  231. // if(res.state == 'Success'){
  232. // res1.content.records.map(item=>{
  233. // data.splice(item.showSort-1,0,{isAdv:true,...item})
  234. // })
  235. // console.log(data);
  236. // data.map((item,index)=>{
  237. // if(index%2){
  238. // list.push(item)
  239. // }else{
  240. // list1.push(item)
  241. // }
  242. // })
  243. // this.list = this.list.concat(list)
  244. // this.list1 = this.list1.concat(list1)
  245. // // let total = this.list.length+this.list1.length
  246. // // if(total>=res.content.total){
  247. // if(this.query.pageCurrent == res.content.pages){
  248. // this.status = 'noMore'
  249. // }else{
  250. // this.status = 'more'
  251. // this.query.pageCurrent++
  252. // }
  253. // }
  254. // })
  255. }
  256. })
  257. },
  258. // 金刚区
  259. getMenu(){
  260. return new Promise((resolve,reject)=>{
  261. getMenu({belongType: 1,currentPage:1,pageSize:10,status:2}).then(res=>{
  262. if(res.state == 'Success'){
  263. this.discountsList = res.content.records
  264. resolve(1)
  265. }
  266. })
  267. })
  268. },
  269. // 广告位
  270. getAdv(){
  271. return new Promise((resolve,reject)=>{
  272. getAdv({belongType:2,currentPage:1,pageSize:99,advertsType:1,status:1}).then(res=>{
  273. if(res.state == 'Success'){
  274. this.advList = res.content.records
  275. // this.advList = res.content.records.filter((item,index)=>index<2)
  276. // this.advList1 = res.content.records.filter((item,index)=>index>=2)
  277. resolve(2)
  278. }
  279. })
  280. })
  281. },
  282. // 获取商品列表内广告位
  283. getGoodsAdv(){
  284. return new Promise((resolve,reject)=>{
  285. getAdv({belongType:2,currentPage:1,pageSize:99,advertsType:2,status:1}).then(res=>{
  286. if(res.state == 'Success'){
  287. this.advList1 = res.content.records
  288. resolve(2)
  289. }
  290. })
  291. })
  292. },
  293. },
  294. onPageScroll(e) {
  295. if(e.scrollTop >= 50){
  296. this.background = true
  297. }else{
  298. this.background = false
  299. }
  300. },
  301. onShow() {
  302. if (uni.getStorageSync('token')&&!uni.getStorageSync('userInfo')) {
  303. this.getUserDetail()
  304. }
  305. },
  306. onHide() {},
  307. onLoad(query){
  308. uni.setStorageSync('inviteCode',decodeURIComponent(query.scene))
  309. },
  310. created() {
  311. this.loading = true
  312. Promise.all([this.getMenu(),this.getAdv(),this.getCity()]).then(res=>{
  313. this.search()
  314. })
  315. }
  316. }
  317. </script>
  318. <style lang="scss">
  319. .home {
  320. // padding-bottom:120rpx;
  321. // background: linear-gradient(180deg, #FFFFFF 0%, #DCE8FF 100%);
  322. background: #F9F9F9;
  323. .card-title {
  324. display: flex;
  325. justify-content: center;
  326. .title {
  327. font-size: 32rpx;
  328. text-align: center;
  329. color: #fff;
  330. width: 210rpx;
  331. line-height: 64rpx;
  332. background: linear-gradient(360deg, #3074F8 0%, #568FFF 100%);
  333. border-radius: 0rpx 0rpx 24rpx 24rpx;
  334. }
  335. }
  336. .login-home {
  337. display: flex;
  338. flex-direction: column;
  339. align-items: center;
  340. // justify-content: center;
  341. height: 100vh;
  342. .img {
  343. margin-top: 524rpx;
  344. width: 252rpx;
  345. height: 252rpx;
  346. }
  347. .text {
  348. font-size: 32rpx;
  349. color: #CCCCCC;
  350. margin-top: 28rpx;
  351. }
  352. }
  353. }
  354. </style>