menu.js 2.77 KB
import App from '../../utils/api';
import util from '../../utils/util'
Component({
	data:{
		menuhidden:true,
        customer_activity:'',
		url:'pages/reserve/index_new',
	},
	attached: function() {
	  this.setStatus();
	  this.getuser();
	  this.getautomenu();
	  this.getorder();
      this.getCheckUserHavePhone()
	},
	methods:{
        // 检测用户是否绑定手机号
        getCheckUserHavePhone() {
            App.Wechat.CheckUserHavePhone({
                openid: getApp().openid,
            }).then((json) => {
                if (json.ret == 200) {
                    let data = json.data;
                    let phone = (data && data.phone) ? data.phone : '';
                    this.getlist(phone)
                }
            })
        },
        //获取用户未使用优惠券列表数量
        getlist(phone) {
            let params = {
              openid: getApp().openid,
          }
          if(phone) params.phone = phone
            App.Activity.GetNewRechargeListByOpenid({...params}).then((res) => {
                if (res.ret == 200) {
                    let list = res.data;
                    list = list.filter(item => {
                        return (item.recharge_name || item.aname)
                    })
                    this.setData({
                        'customer_activity': list.length,
                    })
                }
            })
        },
		getuser(){
			App.User.GetBalance().then(res=>{
			  this.setData({
			    user:res.data
			  })
			})
		},
		getorder(){
			App.Reserve.GetReserveIsConsume().then((json)=>{
				if(json.ret==200){
					console.log('787878',json.data)
					this.setData({
						haveorder:json.data.is_customer==1 || json.data.is_manager==1
					})
				}
			})
		},
		getautomenu(){
			App.Foodset.GetUserFoodOrders({
				status:2,//tabType,
				openid: getApp().openid,
				offset:1,
				limit:1,
				size:1,
			}).then(res=>{
				console.log(res)
				if(res.data.length>0){
					this.setData({
						shownotice:true
					})
				}
			})  
		},
		showmenu(){
			  this.setData({
				  menuhidden:false
			  })
		},
		hidemenu(){
			  this.setData({
				  menuhidden:true
			  })
		},
		topage(e){
			let url=e.currentTarget.dataset.path;
			wx.navigateTo({
				url:url
			})
		},
		topagerelunch(e){
			let url=e.currentTarget.dataset.path;
			wx.reLaunch({
				url:url
			})
		},
		tosearch(e){
			let url=e.currentTarget.dataset.path;
			wx.navigateTo({
				url:url
			})
		},
		gotoList(e){
		  getApp().meListType=e.currentTarget.dataset.type;
		  wx.redirectTo({
		    url:'/pages/me/list?type='+e.currentTarget.dataset.type
		  })
		},
		setStatus(){
		  let pages = getCurrentPages();
		  let p = pages[pages.length - 1];
		  console.log('custom-tab-bar.setStatus',p.route)
		  this.setData({
		    url:p.route,
		  })
		},
	}
})