recommendFood.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // pages/recommendFood/recommendFood.js
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. foodList:[]
  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/merchantAndCallout').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. this.setData({
  37. foodList:result
  38. })
  39. // console.log(this.data.foodList);
  40. // 关闭“数据加载中”的提示
  41. if(this.data.foodList.length != 0){
  42. wx.hideLoading()
  43. }else{
  44. setTimeout(function () {
  45. wx.hideLoading()
  46. }, 2000)
  47. }
  48. },
  49. //跳转到美食详情页
  50. tofoodDetail(e){
  51. console.log(e);
  52. let foodId = e.currentTarget.dataset.item.id
  53. wx.navigateTo({
  54. url: '/pages/foodDetail/foodDetail?id=' + foodId,
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady() {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow() {
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide() {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload() {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh() {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom() {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage() {
  91. }
  92. })