<template>
	<view class="yybox">
		<!-- <nav-bar navtit="预约信息" ></nav-bar> -->
		<!-- 主体 -->
		<view class="yydet">
			<view class="yytab flexc">
				<view :class="ite.val==tabval?'act':''" v-for="(ite,idx) in tablist" :key='idx' @click="getTab(ite.val)">{{ite.tit}}</view>
			</view>
				<!-- 列表 -->
				<scroll-view scroll-y class="yylists"  lower-threshold="40" @scrolltolower="reach_btn">
					<view class="mt12">
						<y-list type='order' :datalist="list" :wtdt="wtdt" @getDetail='getDetail' :adrlist="adrlist" @getDelFn="getDelFn" @gettypeFn="gettypeFn"></y-list>
					</view>
				</scroll-view>
		</view>
	
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import yList from "@/components/order/list.vue"
	import navBar from "@/components/toptab/navbar.vue"
	import {getReservatList,getReservatDel,getReservatSh} from "@/api/mine/order.js"
	import {getDictionaryFn} from "@/api/mine/register.js"
  export default {
	components:{yList,navBar},
	data(){
		return{
			navbg:require("@/static/images/navbg.png"),
			headimg:require("@/static/images/order/staff/head.png"),
			listline:require("@/static/images/order/staff/listline.png"),
			backgroundColor: "transparent",
			tabval:'0',
			tablist:[{tit:"全部",val:0},{tit:"未审核",val:1},{tit:"已拒绝",val:2},{tit:"已审核",val:3},],
			list:[],
			adrlist:[],
			wtdt:'',
			pageSize: 10,
			pageNum: 1,
			reachflag: true,	
		}
	},
	onPageScroll(e) {
		var scrollTop = Number(e.scrollTop);
		if (scrollTop > 0) {
			this.backgroundColor = '#0491FD'
		} else {
			this.backgroundColor = 'transparent'
		}
	},
	onLoad: function() {
		uni.$on('refreshdatalists',(e) => {
			this.reachflag=true;
			this.pageNum=1;
			this.list=[];
			this.getDataFn();
		})
		this.init()
		this.getDataFn()
		
	},
	onUnload() {
		uni.$off('refreshdatalists')
	},
	methods:{
		checkPermi, checkRole,
		reach_btn(){
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		getTab(val){
			this.tabval=val;
			this.reachflag=true;
			this.pageNum=1;
			this.list=[];
			this.getDataFn();
		},
		init(){
			// 记录来源
			getDictionaryFn('jluly').then(res=>{
				if(res.code==200){
					this.adrlist = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
				}
			})
		},
		getDelFn(id){
			var that=this;
			getReservatDel(id).then(res=>{
				if(res.code==200){
					that.$toast('删除成功')
					setTimeout(function(){
						that.reachflag=true;
						that.pageNum=1;
						that.list=[];
						that.getDataFn();
						uni.$emit('refreshdatalist')
						// that.getcount();
					},1500)
					
				}else{
					that.$toast(res.msg)
				}
			})
		},
		gettypeFn(ite){
			var that=this;
			var params={
				reservatId:ite.id,
				visitType:ite.type
			}
			getReservatSh(params).then(res=>{
				if(res.code==200){
					that.$toast('审核成功')
					setTimeout(function(){
						that.reachflag=true;
						that.pageNum=1;
						that.list=[];
						that.getDataFn();
						uni.$emit('refreshdatalist','sh')
						// that.getcount();
					},1500)
					
				}else{
					that.$toast(res.msg)
				}
			})
		},
		getDetail(data){
			this.$tab.navigateTo('/pages/order/staffcode?type=look&id='+data)
		},
		getDataFn(){
			var params={
				pageSize:this.pageSize,
				pageNum: this.pageNum,
			}
			if(this.tabval==0){
				
			}else{
				params.visitType=this.tabval
			}
			getReservatList(params).then(res=>{
				if(res.code==200){
					if (res.rows.length < this.pageSize) {
						this.reachflag = false
						this.wtdt = '到底了~';
					} else {
						var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
						if (num < res.total) {
							this.reachflag = true
							this.wtdt = '上拉加载更多'
						} else {
							this.reachflag = false
							this.wtdt = '到底了~';
						}
					}
					if (this.pageNum == 1) {
						this.list = res.rows;
					} else {
						this.list = this.list.concat(res.rows)
					}
				}else{
					this.$toast(res.msg)
				}
			}) 
			
		},
	},
	
  }
</script>

<style lang="scss" scoped>
.yytab{height: 80rpx;flex: 0 0 auto;background-color: #ffffff;
	view{flex: 1;display: flex;align-items: center;justify-content: center;height: 80rpx;position: relative;color: #666;
		&.act{color: $com-cd3;
			&::after{content: '';width: 100rpx;height: 6rpx;background: $com-cd3;position: absolute;left: 50%;margin-left: -50rpx;bottom: 0;}
		}
	}
}

.yylists{width: 684rpx;margin: 0 auto 0;flex: 1;overflow: auto;}

</style>
