scenicDetail.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/scenicDetail/scenicDetail.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgList:[], //景点路径列表
  9. scenicTitle:'', //景点标题
  10. scenicDescribe:'', //景点介绍
  11. attention:'', //旅游注意事项
  12. playTime:'', //建议游玩时间
  13. scenicLatitude:'', //景点纬度
  14. scenicLongtitude:'' //景点经度
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad:async function(options) {
  20. // 进入页面时,提示“数据加载中”
  21. wx.showLoading({
  22. title: '数据加载中',
  23. mask:true
  24. })
  25. // 获取上一个页面传过来的景点id
  26. // console.log(options.id);
  27. let id = options.id
  28. //更新浏览量
  29. await request('/front/scenicSpot/'+id).catch(err=>{
  30. wx.hideLoading()
  31. wx.showModal({
  32. title: '数据加载失败',
  33. content: '当前网络不佳,请稍后再试',
  34. complete: (res) => {
  35. if (res.cancel) {
  36. wx.navigateBack()
  37. }
  38. if (res.confirm) {
  39. wx.navigateBack()
  40. }
  41. }
  42. })
  43. })
  44. //获取景点照片
  45. let imagePath = await request('/front/findAllScenicSpotFilesPath/'+id)
  46. // console.log(imagePath);
  47. //获取景点列表
  48. let result = await request('/front/scenicSpotAndCallout')
  49. // console.log(result);
  50. for(let i = 0;i < result.length;i++){
  51. if(result[i].id == id){
  52. this.setData({
  53. scenicTitle:result[i].title,
  54. scenicDescribe:result[i].describes,
  55. attention:result[i].attention,
  56. playTime:result[i].playTime,
  57. scenicLatitude:result[i].latitude,
  58. scenicLongtitude:result[i].longitude
  59. })
  60. }
  61. }
  62. let imgList = this.data.imgList
  63. for(let j = 0;j < imagePath.length;j++){
  64. imgList[j] = imagePath[j].iconPath
  65. }
  66. this.setData({
  67. imgList
  68. })
  69. // console.log(this.data.imgList);
  70. // 关闭“数据加载中”的提示
  71. if(this.data.scenicTitle != ''){
  72. wx.hideLoading()
  73. }else{
  74. setTimeout(function () {
  75. wx.hideLoading()
  76. }, 2000)
  77. }
  78. },
  79. //点击预览图片
  80. toPreviewImage(){
  81. let imgList = this.data.imgList
  82. wx.previewImage({
  83. // current: imgList, // 当前显示图片的 http 链接
  84. urls: imgList // 需要预览的图片 http 链接列表
  85. })
  86. },
  87. // 去目的地按钮功能
  88. goDestination(){
  89. let latitude = parseFloat(this.data.scenicLatitude)
  90. let longtitude = parseFloat(this.data.scenicLongtitude)
  91. wx.openLocation({
  92. latitude: latitude,
  93. longitude: longtitude,
  94. name:this.data.scenicTitle
  95. })
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady() {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload() {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh() {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage() {
  131. }
  132. })