| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- var _request = require('../../../utils/request.js')
- var rid;
- Page({
- data: {
- detail: {},
- userInfo:{},
- mealInfo:{},
- info:{},
- bindTelfirst:0,
- },
- onLoad: function (options) {
- console.log('onload onLoad == dining',options)
- this.checkLogin();
- },
- checkLogin:function(){
- var that = this;
- //2020登陆检测
- wx.login({
- success: res => {
- getApp().globalData.try_login = true;
- console.log('checkLogin',res.code)
- var url = 'xcx/login';
- let invite = wx.getStorageSync('invite');
- var params = {
- code: res.code,
- invite_id: invite//新token模式
- }
- that.setData({
- wxlogincode: res.code
- })
- var success = function (res) {
- console.log('pageLogin',res);
- wx.setStorageSync('lbt_session_key', res.data.session_key)
- wx.setStorageSync('lbt_session_time', Date.now())
- wx.setStorageSync('lbt_token_key', res.data.token)
- console.log('nowtoken',res.data.token);
-
- if(res.data.wx_user && res.data.wx_user.head != ''){
- var userInfo = res.data.wx_user;
-
- that.info();
- that.setData({
- userInfo: userInfo
- })
- if(res.data.wx_user.head == '' ){
- that.setData({
- checkhead: false
- })
-
- that.setData({
- userInfo: 'nologin'
- })
- }
- //checkwxhead---end
- }else{
- that.setData({
- userInfo: 'nologin'
- })
- }
- }
- _request.$get(url, params, success)
- }
- })
- },
- info(){
- console.log('oninfo');
- var that = this
- var url = 'v1/user/info'
- var params = {}
- var success = function (res) {
- console.log(res)
- if(!res.data['user']['employ']){
- wx.showToast({
- title: '没有权限',
- icon: 'error',
- duration: 3000
- });
- wx.navigateBack();
- return;
- }
- that.setData({
- info: res.data,
- show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
- bindTel: res.data.user.tel ? true : false
- })
- console.log('untel',res.data.user.tel)
-
- console.log('res.data.wx_user',res.data.wx_user)
- if(res.data.wx_user.head == ''){
- console.log('indddddddddddddddddddddddd')
- that.setData({
- userInfo: 'nologin'
- })
- }
- if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
- that.setData({
- bindTelfirst:1
- })
- wx.navigateTo({
- url: '/packageUser/pages/user/bind/bind'
- })
-
- wx.showToast({
- title: '请先绑定手机号~',
- icon: 'none',
- duration: 2000
- })
- }
-
- that.getMeal();
-
-
- }
- _request.$get(url, params, success)
- },
- getMeal () {
- var that = this
- var url = 'newapi:food/get-meal-info'
- var params = {
- }
- var success = function (res) {
- var data = res.data.data
- console.log('mealinfo',data);
- that.setData({
- mealInfo: data
- })
- if(data.status == 'eating'){
- that.confirmDinging();
- }
- }
- _request.$get(url, params, success)
- },
- confirmDinging(){
- var url = 'newapi:food/scan-get-info';
- var params = {
- }
- var success = function (res) {
- console.log('用餐提醒',res);
- if(res.data.code != 0){
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- });
-
- return;
- }
- let data = res.data.data;
- let can = '';
- if(data.type == 1) can = "早餐";
- if(data.type == 2) can = "中餐";
- if(data.type == 3) can = "晚餐";
- wx.showModal({
- title: "用餐提醒",
- content: `当前用餐日期${data['foodDate']} [${can}] 数量 ${data['nums']},是否确定用餐?`,
- success: function(res) {
- if (res.confirm) {
- var url = 'newapi:food/comfirm-get-food'
- var params = {
-
- }
- var success = function (res) {
- var result = res.data
- if(result.code == 0){
- wx.showToast({
- title: '成功,用餐愉快',
- icon: 'success',
- duration: 3000
- });
- setTimeout(function(){
- wx.reLaunch({
- url: '/pages/canteen/canteen'
- })
- },1000)
- return;
- }else{
- wx.showToast({
- title: result.msg,
- icon: 'error',
- duration: 3000
- });
- }
- }
- _request.$get(url, params, success)
- } else if (res.cancel) {
-
- }
- }
- })
- }
- _request.$get(url, params, success)
- }
-
- })
|