打卡调数据

<view class="ctn">
                    
                    <view class="itm" @click="clockIn(1, breakfast_time, a)">//形参
                        <text>今日早餐</text>
                        <image src="../../static/icon/icon_punch2.png"></image>
                        <text>打卡时间 {{breakfast_time}}</text>
                        <text v-if="a" class="unsign">已打卡</text>
                        <text v-else class="sign">去打卡</text>
                    </view>
                    <view class="itm" @click="clockIn(2, lunch_time, b)">
                        <text >今日午餐</text>
                        <image src="../../static/icon/icon_punch3.png"></image>
                        <text>打卡时间 {{lunch_time}}</text>
                        <text v-if="b" class="unsign">已打卡</text>
                        <text v-else class="sign">去打卡</text>
                    </view>
                    <view class="itm" @click="clockIn(3, dinner_time, c)">
                        <text>今日晚餐</text>
                        <image src="../../static/icon/icon_punch4.png"></image>
                        <text>打卡时间 {{dinner_time}}</text>
                        <text v-if="c" class="unsign">已打卡</text>
                        <text v-else class="sign">去打卡</text>
                    </view>
                </view>
//获取打卡列表
			getRecord(date:any){
				var that:any = this
				
				new HealthService().getRecord(date)
				.then((data:any)=>{
					// if(data.code==1){
					// 	that.date=data.data.date
					// }
					if (data.code == 1) {
			                let a = 0, b = 0, c = 0; //设三个参数
			                if (data.data.length) {  //如果接口有数据
			                  data.data.forEach(el => { //遍历到每个上面
			                
			                    if (el.meal_type == 1) {  //类型为1 为早餐 a=1  有数据就是1就是打卡 反之没数据0就是未打卡
			                       a = 1
			                    } 
			                    if (el.meal_type == 2) {  //类型为2 为午餐 b=1
			                	 b = 1
			                       }
			                    if (el.meal_type == 3) {  //类型为3 为晚餐 c=1
			                       c = 1
			                    }
			                });
			            }
			
						this.a = a;
						this.b = b;
						this.c = c;
			          }
				})
				.catch((error:any)=>{
					that.alert(error.msg)
				})
			},

  

                <view class="ctn">
					
					<view class="itm" @click="clockIn(1, '', a)">//三个入参
						<text>今日早餐</text>
						<image src="../../static/icon/icon_punch2.png"></image>
						<text>打卡时间 {{breakfast_time}}</text>
						<text v-if="a" class="unsign">已打卡</text>
						<text v-else class="sign">去打卡</text>
					</view>
					<view class="itm" @click="clockIn(2, '', b)">
						<text >今日午餐</text>
						<image src="../../static/icon/icon_punch3.png"></image>
						<text>打卡时间 {{lunch_time}}</text>
						<text v-if="b" class="unsign">已打卡</text>
						<text v-else class="sign">去打卡</text>
					</view>
					<view class="itm" @click="clockIn(3, '', c)">
						<text>今日晚餐</text>
						<image src="../../static/icon/icon_punch4.png"></image>
						<text>打卡时间 {{dinner_time}}</text>  
						<text v-if="c" class="unsign">已打卡</text>
						<text v-else class="sign">去打卡</text>
					</view>
				</view>

  

//获取设置 调用方法
            getRemind(){
                var that:any = this
                
                new HealthService().getRemindSett()
                .then((data:any)=>{
                    if(data.code==1){
                        
                        that.breakfast_time = data.data.breakfast_time;
                        that.lunch_time = data.data.lunch_time;
                        that.dinner_time = data.data.dinner_time;
                        that.lead_time = data.data.lead_time+"分钟";
                        
                        return;
                    }
                    
                    this.requestTodayData(this.date); 

            //执行完上面设置的接口调用 紧接着执行已打卡的接口调用 保持页面顺序正确 先是设置的时间点击加载上已打卡的当前时间 }) .
catch((error:any)=>{ that.alert(error.msg) }) },

 

requestTodayData(dt:any){
                var that:any = this 
                
                new HealthService().getRecord(dt)
                .then((data:any)=>{
                    if(data.code!=1) return
                    
                    that.list = data.data
                    
                    var _b:any = that.list.filter((i:any)=>i.meal_type==1)
                    if(_b&&_b.length>0)
                    that.breakfast_time = _b[0].time
                    
                    
                    _b = that.list.filter((i:any)=>i.meal_type==2)
                    if(_b&&_b.length>0)
                    that.lunch_time= _b[0].time
                    
                    _b = that.list.filter((i:any)=>i.meal_type==3)
                    if(_b&&_b.length>0)
                    that.dinner_time= _b[0].time
                })
                .catch((error:any)=>{
                    that.alert(error.msg)
                })
            },

 

//点击打卡 进餐打卡
clockIn(meal_type:any,time:any,num:any){//对应三个入参 var that:any = this
//点击一次 当为1时 已打卡 跳出方法
         //注意双等号赋值 if(num==1) return;
           //获取数据的时候走这 new HealthService().clockIn(meal_type,time) 传参打卡 .then((data:any)=>{ if(data.code==1){

                //返回time数据格式是时间戳 转化成08:00的格式
                var time:any = new Date(data.data.time*1000);
                time = `${time.getHours()>9?'':'0'}${time.getHours()}:${time.getMinutes()>9?'':'0'}${time.getMinutes()}`


                //点击后立即已打卡 时间从设置时间变更为打卡的时间

                if(meal_type==1){
                  that.a = 1
                  that.breakfast_time = time //接口返回的数据time加载到设置的原来时间 覆盖得出
                }
                else if(meal_type==2){
                  that.b = 1
                  that.lunch_time = time
                }
                else if(meal_type==3){
                  that.c = 1
                  that.dinner_time = time
                }

                console.log(data);
                that.meal_type = data.data.meal_type;
                that.time = data.data.time;
                return;

                    }
                    
                })
                .catch((error:any)=>{
                    that.alert(error.msg)
                })
                
            }

 

 

posted @ 2020-08-17 12:01  小平头~  阅读(162)  评论(0编辑  收藏  举报