foodDetail.js 4.0 KB

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