ourCanteen.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // pages/ourCanteen/index.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. request,
  7. baseUrl
  8. } from "../api/canteen-request.js";
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. canteenEmpty: false,
  15. isLoading: false,
  16. imgUrl: imgUrl,
  17. baseUrl: baseUrl + '/',
  18. tab: 0,
  19. item: '',
  20. canteenList: [],
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.canteenList();
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. this.setData({
  38. item: 0,
  39. isLoading: false,
  40. canteenEmpty: false
  41. })
  42. if (this.data.loginReturnFlag) {
  43. this.setData({
  44. loginReturnFlag: false
  45. })
  46. this.onLoad()
  47. }
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. },
  64. /**
  65. * 页面上拉触底事件的处理函数
  66. */
  67. onReachBottom: function () {
  68. },
  69. /**
  70. * 用户点击右上角分享
  71. */
  72. onShareAppMessage: function () {
  73. return {
  74. title: '食堂'
  75. }
  76. },
  77. imageError(e) {
  78. let temp = this.data.canteenList;
  79. temp[e.currentTarget.dataset.index].canteenPhotoPath = '';
  80. this.setData({
  81. canteenList: temp
  82. })
  83. },
  84. changeItem: function (e) {
  85. if (e.currentTarget.dataset.item == 1) {
  86. wx.navigateTo({
  87. url: '/pages/deliciousList/deliciousList'
  88. })
  89. } else {
  90. this.setData({
  91. item: e.currentTarget.dataset.item
  92. })
  93. }
  94. },
  95. changeTab: function (e) {
  96. this.setData({
  97. tab: e.detail.current
  98. })
  99. },
  100. toMenu: function (e) {
  101. var canteenId = e.currentTarget.dataset.item;
  102. var canteenName = e.currentTarget.dataset.name;
  103. if (canteenId && canteenId != '') {
  104. wx.navigateTo({
  105. url: `/pagesPublic/pages/menu/menu?canteenId=${canteenId}&canteenName=${canteenName}`
  106. })
  107. }
  108. },
  109. // 阻止手动拖动
  110. catchTouchMove: function (res) {
  111. return true
  112. },
  113. islogin() {
  114. let userid = wx.getStorageSync('userId');
  115. if (userid === null || userid === '') {
  116. this.showDialog();
  117. }
  118. },
  119. showDialog() {
  120. wx.showModal({
  121. title: '未授权',
  122. content: '您登录授权已过期,请重新录授权',
  123. showCancel: false,
  124. confirmText: '登录',
  125. success: function (res) {
  126. wx.navigateTo({
  127. url: '/pages/login/login',
  128. });
  129. },
  130. });
  131. },
  132. back() {
  133. wx.navigateBack({
  134. delta: 1,
  135. })
  136. },
  137. canteenList() {
  138. this.setData({
  139. isLoading: true
  140. })
  141. request({
  142. url: '/mini/canteen/getCanteenList',
  143. method: 'GET'
  144. }).then(res => {
  145. if (res.result) {
  146. let data = res.data
  147. if (data.length < 1) {
  148. this.setData({
  149. canteenEmpty: true
  150. })
  151. }
  152. for (let i = 0; i < data.length; i++) {
  153. const element = data[i];
  154. var timeFrame = "";
  155. var timeFrameinfo = [];
  156. var supplyTime = element.supplyTimeMaps.sort((a, b) => {
  157. return a.timeNode - b.timeNode
  158. })
  159. for (let j = 0; j < supplyTime.length; j++) {
  160. const childElement = supplyTime[j];
  161. switch (childElement.timeNode) {
  162. case 1:
  163. timeFrame += "早";
  164. childElement.timeNode = "早上";
  165. break
  166. case 2:
  167. timeFrame += "中";
  168. childElement.timeNode = "中午";
  169. break
  170. case 3:
  171. timeFrame += "晚";
  172. childElement.timeNode = "晚上";
  173. break
  174. case 4:
  175. timeFrame += "外卖";
  176. childElement.timeNode = "外卖";
  177. break
  178. }
  179. if (j != supplyTime.length - 1) {
  180. timeFrame += "/"
  181. }
  182. timeFrameinfo.push(childElement)
  183. }
  184. data[i].timeFrame = timeFrame;
  185. data[i].timeFrameinfo = timeFrameinfo;
  186. }
  187. this.setData({
  188. isLoading: false,
  189. canteenList: data
  190. })
  191. } else {
  192. this.setData({
  193. isLoading: false,
  194. })
  195. }
  196. })
  197. }
  198. })