scenicList.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // pages/scenicList/scenicList.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. scenicList:[], //景点列表
  9. imageList:[], //景点照片列表
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad:async function(options) {
  15. // 进入页面时,提示“数据加载中”
  16. wx.showLoading({
  17. title: '数据加载中',
  18. mask:true
  19. })
  20. let imageList = this.data.imageList
  21. let imagePath = []
  22. let result = await request('/front/scenicSpotAndCallout').catch(err=>{
  23. wx.hideLoading()
  24. wx.showModal({
  25. title: '数据加载失败',
  26. content: '当前网络不佳,请稍后再试',
  27. complete: (res) => {
  28. if (res.cancel) {
  29. wx.navigateBack()
  30. }
  31. if (res.confirm) {
  32. wx.navigateBack()
  33. }
  34. }
  35. })
  36. }) //获取景点列表
  37. // console.log(result);
  38. for(let i = 0;i < result.length;i++){
  39. if(result[i].viewCount >= 10000){
  40. result[i].viewCount = result[i].viewCount/10000+'万'
  41. }
  42. }
  43. //获取景点照片列表
  44. for(let i = 0;i < result.length;i++){
  45. let id = result[i].id
  46. // console.log(id);
  47. imagePath = await request('/front/findAllScenicSpotFilesPath/'+id)
  48. // console.log(imagePath);
  49. imageList[i] = imagePath
  50. // 将景点照片添加到景点列表
  51. Object.assign(result[i],imagePath)
  52. // console.log(result);
  53. }
  54. this.setData({
  55. scenicList:result,
  56. imageList
  57. })
  58. //console.log(this.data.imageList);
  59. // console.log(this.data.scenicList);
  60. // 关闭“数据加载中”的提示
  61. if(this.data.scenicList.length != 0){
  62. wx.hideLoading()
  63. }else(
  64. setTimeout(function () {
  65. wx.hideLoading()
  66. }, 2000)
  67. )
  68. },
  69. //跳转到景点详情
  70. toScenicDetail(e) {
  71. // console.log(e);
  72. // console.log(e.currentTarget.dataset.index);
  73. // let scenicId = e.currentTarget.dataset.index
  74. let scenicId = e.currentTarget.dataset.item.id
  75. // console.log(scenicId);
  76. // 跳转传参
  77. wx.navigateTo({
  78. url: '/pages/scenicDetail/scenicDetail?id=' + scenicId,
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面初次渲染完成
  83. */
  84. onReady() {
  85. },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow() {
  90. },
  91. /**
  92. * 生命周期函数--监听页面隐藏
  93. */
  94. onHide() {
  95. },
  96. /**
  97. * 生命周期函数--监听页面卸载
  98. */
  99. onUnload() {
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh() {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. onReachBottom() {
  110. wx.showToast({
  111. title: '没有更多啦',
  112. icon:'none'
  113. })
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage() {
  119. }
  120. })