scenicList.js 2.7 KB

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