main.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // pages/main/main.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. bannerList:[], //轮播图列表
  9. naxiImgUrl:'', //纳溪介绍的图片
  10. macunImgUrl:'', //马村介绍的图片
  11. hotScenicList:[], //热门景点列表
  12. hotCountList:[], //热度统计
  13. leftImg:[], //景点介绍左侧列表
  14. rightImg:[], //景点介绍右侧列表
  15. hotFoodList:[], //商户列表信息
  16. swiperImgPath:[] //轮播图照片地址
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad:async function(options) {
  22. //获取轮播图列表
  23. let banners = await request('/front/banner')
  24. // console.log(banners);
  25. this.setData({
  26. bannerList:banners
  27. })
  28. //获取纳溪照片(默认取第一张)
  29. let naxiImg = await request('/front/introduce/files/1')
  30. // console.log(naxiImg[0].iconPath);
  31. this.setData({
  32. naxiImgUrl:naxiImg[0].iconPath
  33. })
  34. //获取马村照片(默认取第一张)
  35. let macunImg = await request('/front/introduce/files/2')
  36. // console.log(macunImg[0].iconPath);
  37. this.setData({
  38. macunImgUrl:macunImg[0].iconPath
  39. })
  40. //获取景点列表
  41. let sceneryImgList = await request('/front/scenicSpotAndCallout')
  42. // console.log(sceneryImgList);
  43. // 按景点热度降序重新排列
  44. for(let i = 0;i < sceneryImgList.length - 1;i++){
  45. for(let j = 0;j < sceneryImgList.length - 1 - i;j++){
  46. if(sceneryImgList[j].viewCount < sceneryImgList[j+1].viewCount){
  47. let temp = sceneryImgList[j]
  48. sceneryImgList[j] = sceneryImgList[j+1]
  49. sceneryImgList[j+1] = temp
  50. }
  51. }
  52. }
  53. this.setData({
  54. hotScenicList:sceneryImgList
  55. })
  56. // 获取景点介绍左右列表数据
  57. let leftImg = this.data.leftImg
  58. let rightImg = this.data.rightImg
  59. let hotScenicList = this.data.hotScenicList
  60. for(let i = 0;i < hotScenicList.length;i++){
  61. if(i % 2 == 0 && leftImg.length < 2){
  62. leftImg.push(hotScenicList[i])
  63. }else if(i % 2 != 0 && rightImg.length < 2){
  64. rightImg.push(hotScenicList[i])
  65. }
  66. }
  67. this.setData({
  68. leftImg,
  69. rightImg
  70. })
  71. // console.log(this.data.leftImg);
  72. //获取商户信息
  73. let foodList = await request('/front/merchantAndCallout')
  74. console.log(foodList);
  75. // 按商户热度进行降序重新排列
  76. for(let i = 0;i < foodList.length - 1;i++){
  77. for(let j = 0;j < foodList.length - 1 - i;j++){
  78. if(foodList[j].viewCount < foodList[j+1].viewCount){
  79. let temp = foodList[j]
  80. foodList[j] = foodList[j+1]
  81. foodList[j+1] = temp
  82. }
  83. }
  84. }
  85. // 获取热门商户列表
  86. let hotFoodList = this.data.hotFoodList
  87. for(let i = 0;i <foodList.length;i++){
  88. if(hotFoodList.length < 4){
  89. hotFoodList.push(foodList[i])
  90. }
  91. }
  92. this.setData({
  93. hotFoodList
  94. })
  95. console.log(this.data.hotFoodList);
  96. },
  97. // 点击轮播图照片放大查看
  98. toPreviewImage(){
  99. let imgUrl = this.data.bannerList
  100. let swiperImgPath = this.data.swiperImgPath
  101. for(let i = 0;i < imgUrl.length;i++){
  102. swiperImgPath[i] = imgUrl[i].iconPath
  103. }
  104. // console.log(swiperImgPath);
  105. wx.previewImage({
  106. urls: swiperImgPath,
  107. })
  108. },
  109. // 跳转到纳溪介绍页面
  110. toMainIntro() {
  111. wx.navigateTo({
  112. url: '/pages/naxiIntro/naxiIntro',
  113. })
  114. },
  115. //跳转到马村介绍
  116. toSecondIntro() {
  117. wx.navigateTo({
  118. url: '/pages/macunIntro/macunIntro',
  119. })
  120. },
  121. //跳转到景区列表
  122. toScenicList() {
  123. wx.navigateTo({
  124. url: '/pages/scenicList/scenicList',
  125. })
  126. },
  127. // 跳转到推荐美食
  128. toRecommendFood(){
  129. wx.navigateTo({
  130. url: '/pages/recommendFood/recommendFood',
  131. })
  132. },
  133. // 跳转到导航地图
  134. toNavMap(){
  135. wx.switchTab({
  136. url: '/pages/map/map',
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow() {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide() {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload() {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh() {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom() {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage() {
  173. }
  174. })