ourCanteen.js 3.5 KB

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