deliciousList.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/deliciousList.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. request,
  7. baseUrl
  8. } from "../api/canteen-request"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. // 图片前缀
  15. imgUrl: imgUrl,
  16. // 服务器地址
  17. baseUrl: baseUrl + '/',
  18. // 默认选中
  19. currentTab: 0,
  20. // 食堂列表
  21. canteenList: [],
  22. isLoading: false
  23. },
  24. getDeliciousList() {
  25. var that = this;
  26. this.setData({
  27. isLoading: true
  28. })
  29. request({
  30. url: '/mini/canteen/getDeliciousList',
  31. method: 'GET'
  32. }).then(res => {
  33. if (res.result) {
  34. let temp = [];
  35. if (res.data.length < 0) {
  36. this.setData({
  37. isLoading: false
  38. })
  39. return;
  40. }
  41. res.data.forEach(element => {
  42. if (element.deliciousList.length > 0) {
  43. temp.push(element);
  44. }
  45. })
  46. temp.forEach(element => {
  47. element.deliciousList.forEach(item => {
  48. if (item.dishesPic) {
  49. wx.getImageInfo({
  50. src: this.data.baseUrl + item.dishesPic,
  51. fail() {
  52. item.dishesPic = '';
  53. that.setData({
  54. canteenList: temp
  55. })
  56. }
  57. });
  58. }
  59. });
  60. });
  61. this.setData({
  62. isLoading: false,
  63. canteenList: temp
  64. })
  65. } else {
  66. this.setData({
  67. isLoading: false
  68. })
  69. }
  70. })
  71. },
  72. // 切换食堂
  73. tabNav(e) {
  74. let currentTab = e.currentTarget.dataset.index
  75. this.setData({
  76. currentTab
  77. })
  78. },
  79. // 切换食堂
  80. handleSwiper(e) {
  81. let {
  82. current,
  83. source
  84. } = e.detail
  85. if (source === 'autoplay' || source === 'touch') {
  86. const currentTab = current
  87. this.setData({
  88. currentTab
  89. })
  90. }
  91. },
  92. // 查看评论
  93. toComment: function (e) {
  94. wx.navigateTo({
  95. url: '/pages/commentList/commentList?dishesId=' + e.currentTarget.dataset.data.dishesId + '&commentCount=' + e.currentTarget.dataset.data.commentCount + '&compliment=' + e.currentTarget.dataset.data.compliment + '&canteenId=' + this.data.canteenList[this.data.currentTab].id
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function (options) {
  102. this.getDeliciousList();
  103. // 加载字体
  104. // wx.loadFontFace({
  105. // family: 'DOUYU',
  106. // source: 'url("https://www.cqna.gov.cn/mnazw/applet/font/douyu.ttf")',
  107. // success: function (e) {
  108. // console.log(e, '动态加载字体成功')
  109. // },
  110. // fail: function (e) {
  111. // console.log(e, '动态加载字体失败')
  112. // },
  113. // })
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. if (this.data.loginReturnFlag) {
  125. this.setData({
  126. loginReturnFlag: false
  127. })
  128. this.onLoad()
  129. }
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload: function () {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh: function () {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom: function () {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage: function () {
  155. return {
  156. title: '菜品榜单'
  157. }
  158. }
  159. })