123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- // pages/main/main.js
- import request from '../../utils/request'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- bannerList:[], //轮播图列表
- naxiImgUrl:'', //纳溪介绍的图片
- macunImgUrl:'', //马村介绍的图片
- hotScenicList:[], //热门景点列表
- hotCountList:[], //热度统计
- leftImg:[], //景点介绍左侧列表
- rightImg:[], //景点介绍右侧列表
- hotFoodList:[], //商户列表信息
- swiperImgPath:[] //轮播图照片地址
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad:async function(options) {
- //获取轮播图列表
- let banners = await request('/front/banner')
- // console.log(banners);
- this.setData({
- bannerList:banners
- })
-
- //获取纳溪照片(默认取第一张)
- let naxiImg = await request('/front/introduce/files/1')
- // console.log(naxiImg[0].iconPath);
- this.setData({
- naxiImgUrl:naxiImg[0].iconPath
- })
- //获取马村照片(默认取第一张)
- let macunImg = await request('/front/introduce/files/2')
- // console.log(macunImg[0].iconPath);
- this.setData({
- macunImgUrl:macunImg[0].iconPath
- })
- //获取景点列表
- let sceneryImgList = await request('/front/scenicSpotAndCallout')
- // console.log(sceneryImgList);
-
- // 按景点热度降序重新排列
- for(let i = 0;i < sceneryImgList.length - 1;i++){
- for(let j = 0;j < sceneryImgList.length - 1 - i;j++){
- if(sceneryImgList[j].viewCount < sceneryImgList[j+1].viewCount){
- let temp = sceneryImgList[j]
- sceneryImgList[j] = sceneryImgList[j+1]
- sceneryImgList[j+1] = temp
- }
- }
- }
- this.setData({
- hotScenicList:sceneryImgList
- })
- // 获取景点介绍左右列表数据
- let leftImg = this.data.leftImg
- let rightImg = this.data.rightImg
- let hotScenicList = this.data.hotScenicList
- for(let i = 0;i < hotScenicList.length;i++){
- if(i % 2 == 0 && leftImg.length < 2){
- leftImg.push(hotScenicList[i])
- }else if(i % 2 != 0 && rightImg.length < 2){
- rightImg.push(hotScenicList[i])
- }
- }
- this.setData({
- leftImg,
- rightImg
- })
- // console.log(this.data.leftImg);
- //获取商户信息
- let foodList = await request('/front/merchantAndCallout')
- console.log(foodList);
- // 按商户热度进行降序重新排列
- for(let i = 0;i < foodList.length - 1;i++){
- for(let j = 0;j < foodList.length - 1 - i;j++){
- if(foodList[j].viewCount < foodList[j+1].viewCount){
- let temp = foodList[j]
- foodList[j] = foodList[j+1]
- foodList[j+1] = temp
- }
- }
- }
- // 获取热门商户列表
- let hotFoodList = this.data.hotFoodList
- for(let i = 0;i <foodList.length;i++){
- if(hotFoodList.length < 4){
- hotFoodList.push(foodList[i])
- }
- }
- this.setData({
- hotFoodList
- })
- console.log(this.data.hotFoodList);
-
- },
- // 点击轮播图照片放大查看
- toPreviewImage(){
- let imgUrl = this.data.bannerList
- let swiperImgPath = this.data.swiperImgPath
- for(let i = 0;i < imgUrl.length;i++){
- swiperImgPath[i] = imgUrl[i].iconPath
- }
- // console.log(swiperImgPath);
- wx.previewImage({
- urls: swiperImgPath,
- })
- },
- // 跳转到纳溪介绍页面
- toMainIntro() {
- wx.navigateTo({
- url: '/pages/naxiIntro/naxiIntro',
- })
- },
- //跳转到马村介绍
- toSecondIntro() {
- wx.navigateTo({
- url: '/pages/macunIntro/macunIntro',
- })
- },
- //跳转到景区列表
- toScenicList() {
- wx.navigateTo({
- url: '/pages/scenicList/scenicList',
- })
- },
-
- // 跳转到推荐美食
- toRecommendFood(){
- wx.navigateTo({
- url: '/pages/recommendFood/recommendFood',
- })
- },
- // 跳转到导航地图
- toNavMap(){
- wx.switchTab({
- url: '/pages/map/map',
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|