foodDetail.js 4.1 KB

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