dining.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var _request = require('../../../utils/request.js')
  2. var rid;
  3. Page({
  4. data: {
  5. detail: {},
  6. userInfo:{},
  7. mealInfo:{},
  8. info:{},
  9. bindTelfirst:0,
  10. },
  11. onLoad: function (options) {
  12. console.log('onload onLoad == dining',options)
  13. this.checkLogin();
  14. },
  15. checkLogin:function(){
  16. var that = this;
  17. //2020登陆检测
  18. wx.login({
  19. success: res => {
  20. getApp().globalData.try_login = true;
  21. console.log('checkLogin',res.code)
  22. var url = 'xcx/login';
  23. let invite = wx.getStorageSync('invite');
  24. var params = {
  25. code: res.code,
  26. invite_id: invite//新token模式
  27. }
  28. that.setData({
  29. wxlogincode: res.code
  30. })
  31. var success = function (res) {
  32. console.log('pageLogin',res);
  33. wx.setStorageSync('lbt_session_key', res.data.session_key)
  34. wx.setStorageSync('lbt_session_time', Date.now())
  35. wx.setStorageSync('lbt_token_key', res.data.token)
  36. console.log('nowtoken',res.data.token);
  37. if(res.data.wx_user && res.data.wx_user.head != ''){
  38. var userInfo = res.data.wx_user;
  39. that.info();
  40. that.setData({
  41. userInfo: userInfo
  42. })
  43. if(res.data.wx_user.head == '' ){
  44. that.setData({
  45. checkhead: false
  46. })
  47. that.setData({
  48. userInfo: 'nologin'
  49. })
  50. }
  51. //checkwxhead---end
  52. }else{
  53. that.setData({
  54. userInfo: 'nologin'
  55. })
  56. }
  57. }
  58. _request.$get(url, params, success)
  59. }
  60. })
  61. },
  62. info(){
  63. console.log('oninfo');
  64. var that = this
  65. var url = 'v1/user/info'
  66. var params = {}
  67. var success = function (res) {
  68. console.log(res)
  69. if(!res.data['user']['employ']){
  70. wx.showToast({
  71. title: '没有权限',
  72. icon: 'error',
  73. duration: 3000
  74. });
  75. wx.navigateBack();
  76. return;
  77. }
  78. that.setData({
  79. info: res.data,
  80. show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
  81. bindTel: res.data.user.tel ? true : false
  82. })
  83. console.log('untel',res.data.user.tel)
  84. console.log('res.data.wx_user',res.data.wx_user)
  85. if(res.data.wx_user.head == ''){
  86. console.log('indddddddddddddddddddddddd')
  87. that.setData({
  88. userInfo: 'nologin'
  89. })
  90. }
  91. if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
  92. that.setData({
  93. bindTelfirst:1
  94. })
  95. wx.navigateTo({
  96. url: '/packageUser/pages/user/bind/bind'
  97. })
  98. wx.showToast({
  99. title: '请先绑定手机号~',
  100. icon: 'none',
  101. duration: 2000
  102. })
  103. }
  104. that.getMeal();
  105. }
  106. _request.$get(url, params, success)
  107. },
  108. getMeal () {
  109. var that = this
  110. var url = 'newapi:food/get-meal-info'
  111. var params = {
  112. }
  113. var success = function (res) {
  114. var data = res.data.data
  115. console.log('mealinfo',data);
  116. that.setData({
  117. mealInfo: data
  118. })
  119. if(data.status == 'eating'){
  120. that.confirmDinging();
  121. }
  122. }
  123. _request.$get(url, params, success)
  124. },
  125. confirmDinging(){
  126. var url = 'newapi:food/scan-get-info';
  127. var params = {
  128. }
  129. var success = function (res) {
  130. console.log('用餐提醒',res);
  131. if(res.data.code != 0){
  132. wx.showToast({
  133. title: res.data.msg,
  134. icon: 'none',
  135. duration: 2000
  136. });
  137. return;
  138. }
  139. let data = res.data.data;
  140. let can = '';
  141. if(data.type == 1) can = "早餐";
  142. if(data.type == 2) can = "中餐";
  143. if(data.type == 3) can = "晚餐";
  144. wx.showModal({
  145. title: "用餐提醒",
  146. content: `当前用餐日期${data['foodDate']} [${can}] 数量 ${data['nums']},是否确定用餐?`,
  147. success: function(res) {
  148. if (res.confirm) {
  149. var url = 'newapi:food/comfirm-get-food'
  150. var params = {
  151. }
  152. var success = function (res) {
  153. var result = res.data
  154. if(result.code == 0){
  155. wx.showToast({
  156. title: '成功,用餐愉快',
  157. icon: 'success',
  158. duration: 3000
  159. });
  160. setTimeout(function(){
  161. wx.reLaunch({
  162. url: '/pages/canteen/canteen'
  163. })
  164. },1000)
  165. return;
  166. }else{
  167. wx.showToast({
  168. title: result.msg,
  169. icon: 'error',
  170. duration: 3000
  171. });
  172. }
  173. }
  174. _request.$get(url, params, success)
  175. } else if (res.cancel) {
  176. }
  177. }
  178. })
  179. }
  180. _request.$get(url, params, success)
  181. }
  182. })