index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // pages/home/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. height: app.globalData.height * 2 + 25,
  9. navbarData: {
  10. name: '节俭会'
  11. },
  12. background: '',
  13. tenant: '',
  14. heat: 80,
  15. heatColor: {
  16. '0%': '#E1FFFF',
  17. '25%': '#00FF7F',
  18. '50%': '#191970',
  19. '75%': '#ee0a24',
  20. '100%': '#ff0000',
  21. },
  22. thrList: [
  23. {
  24. name: '菜名',
  25. num: 1,
  26. reserve: '100'
  27. },
  28. {
  29. name: '菜名',
  30. num: 1,
  31. reserve: '100'
  32. },
  33. {
  34. name: '菜名',
  35. num: 1,
  36. reserve: '100'
  37. },
  38. ]
  39. },
  40. // 查看本周菜谱
  41. reserveBtn: function () {
  42. wx.redirectTo({
  43. url: '/pages/food/index',
  44. })
  45. },
  46. // 报餐:1,余菜打包:2,卡路里计算:3
  47. twoBtn: function (e) {
  48. let type = e.currentTarget.dataset.smile
  49. if (type == '1') {
  50. wx.switchTab({
  51. url: '/pages/reserve/index',
  52. })
  53. } else if (type == '2') {
  54. wx.showToast({
  55. title: '暂未开通',
  56. })
  57. } else {
  58. wx.showToast({
  59. title: '暂未开通',
  60. })
  61. // wx.redirectTo({
  62. // url: '/pages/calorie/index',
  63. // })
  64. }
  65. },
  66. /**
  67. * 生命周期函数--监听页面加载
  68. */
  69. onLoad: function (options) {
  70. console.log(app.globalData.wxInfo);
  71. wx.request({
  72. url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  73. method: "get",
  74. header: { 'x-tenant': app.globalData.tenant },
  75. data: {},
  76. success: res => {
  77. const { data } = res.data;
  78. this.setData({ background: `${app.globalData.fileUrl}` + data.img.home })
  79. this.setData({ tenant: data.name })
  80. },
  81. error: err => {
  82. wx.showToast({
  83. title: err.msg,
  84. icon: 'error'
  85. })
  86. }
  87. })
  88. console.log('function in')
  89. wx.getWeRunData({
  90. success(res) {
  91. console.log(res);
  92. const { encryptedData, iv } = res
  93. const session_key = app.globalData.wxInfo.session_key
  94. const data = { encryptedData, iv, session_key }
  95. // // 拿 encryptedData 到开发者后台解密开放数据
  96. wx.request({
  97. url: `${app.globalData.publicUrl}/api/st/system/weixin/decrypt`,
  98. method: "POST",
  99. data,
  100. header: {
  101. 'x-tenant': app.globalData.tenant
  102. },
  103. success: (res) => {
  104. console.log(res);
  105. },
  106. })
  107. }
  108. })
  109. },
  110. /**
  111. * 生命周期函数--监听页面初次渲染完成
  112. */
  113. onReady: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面显示
  117. */
  118. onShow: function () {
  119. if (typeof this.getTabBar === 'function' &&
  120. this.getTabBar()) {
  121. this.getTabBar().setData({
  122. selected: 0
  123. })
  124. }
  125. },
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面卸载
  133. */
  134. onUnload: function () {
  135. },
  136. /**
  137. * 页面相关事件处理函数--监听用户下拉动作
  138. */
  139. onPullDownRefresh: function () {
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function () {
  145. },
  146. /**
  147. * 用户点击右上角分享
  148. */
  149. onShareAppMessage: function () {
  150. }
  151. })