<template>
	<view class="allpage">
		<view class="listtop pfixed">
			<tab-searchone @getSearch='getSearch' :name="name"></tab-searchone>
			<tab-list :tablist='tablist' :tabidx="tabidx" @getCheck="goCheck" :height='130'></tab-list>
			<time-year @bindDateChange="bindDateChange" :timedate="time"></time-year>
		</view>
		<view class="zhanline"></view>
		<view class="alllist">
			<!-- l列表 -->
			<project-list :datalist="list" :wtdt='wtdt' @getDetail='goDetail'></project-list>
			
		</view>
	</view>
</template>

<script>
	import projectList from "@/components/projectlist/list.vue"
	import tabList from "@/components/toptab/tab.vue"
	import tabSearchone from "@/components/toptab/searchone.vue"
	import timeYear from "@/components/timedata/timeyear.vue"
	import { getsbbzblist,getqyxxlist,getkgxxlist,gettcxxlist } from '@/api/work/clue.js'
	import {getCommonCensus} from "@/api/work/index.js"
	export default{
		data(){
			return{
				pageSize: 10,
				pageNum: 1,
				reachflag:true,
				itemslist:[],
				wtdt:'',
				tabidx:0,
				date:'',
				list:[],
				tablist:[{tit:'全部',val:0,txt:0,limt:'projectV2:sbbzb:list'},{tit:'线索',val:1,txt:0,limt:'projectV2:sbbzb:list'},{tit:'签约',val:2,txt:0,limt:'projectV2:sbbzb:list'},{tit:'开工',val:3,txt:0,limt:'projectV2:sbbzb:list'},{tit:'投产',val:4,txt:0,limt:'projectV2:sbbzb:list'},],
				year:'',
				beginTime:'',
				endTime:'',
				name:'',
				census:'',
				deptId:this.$store.state.user.deptId,
				time:""
			}
		},
		components:{
			projectList,tabList,tabSearchone,timeYear
		},
		onUnload(){
			uni.$off('refreshdatalist')
		},
		onLoad(e) {
			this.tabidx=Number(e.idx);
			if(e.xmmc){
				this.name=e.xmmc;
			}
			var y='';
			if(e.time){
				y=e.time
			}else{
				let date = new Date();
				y = date.getFullYear();
			}
			this.beginTime=y+'0101';
			this.endTime=y+'1231';
			this.time=y;
			this.getDataFn();
			this.getCommonCensus();
			uni.$on('refreshdatalist',(e) => {
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn();
				if(e&&e=='ldps'){
					
				}else{
					this.getCommonCensus();
				}
				
			})
		},
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			getCommonCensus(){
				var params={
					deptId:this.deptId,
					xmxsmc:this.name,
					params:{
						'beginTime':this.beginTime,
						'endTime':this.endTime
					}
				}
				// params['params[beginTime]']=this.beginTime
				// params['params[endTime]']=this.endTime
				getCommonCensus(params).then(res=>{
					if(res.code==200){
						this.census=res.data;
						var newArr=this.tablist;
						newArr.forEach(ite=>{
							if(ite.val==0){
								ite.txt=res.data.all||0
							}else if(ite.val==1){
								ite.txt=res.data.st||0
							}else if(ite.val==2){
								ite.txt=res.data.qy||0
							}else if(ite.val==3){
								ite.txt=res.data.kg||0
							}else if(ite.val==4){
								ite.txt=res.data.tc||0
							}
						})
					}else{
						this.$toast(res.msg)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					xmxsmc:this.name,
					deptId:this.$store.state.user.deptId
				}
				params['params[beginTime]']=this.beginTime
				params['params[endTime]']=this.endTime
				if(this.tabidx==0){
					
				}else if(this.tabidx==1){//线索
					params.progress='1,2'
				}else if(this.tabidx==2){//签约
					params.progress='3'
				}else if(this.tabidx==3){//开工
					params.progress='4'
				}else if(this.tabidx==4){//投产
					params.progress='5'
				}
				//1:项目首谈 2:项目承接 3:项目签约 4:项目开工 5:项目投产
				getsbbzblist(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)
					}
				})
			},
			getSearch(e){
				this.name=e;
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn();
				this.getCommonCensus();
			},
			bindDateChange(e){
				this.year=e;
				this.beginTime=e+'0101';
				this.endTime=e+'1231';
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn()
				this.getCommonCensus();
			},
			goCheck(data){
				this.tabidx=data;
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn()
				// this.getCommonCensus();
			},
			goDetail(e){
				this.$tab.navigateTo('/pages/work/cluedetails?id='+e.id)
				 // this.$tab.navigateTo('/pages/work/cluedetails?id='+e+"&tabidx="+this.tabidx)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.allpage{min-height: 100vh;background: #ffffff;padding-top:320rpx;box-sizing: border-box;}
.listtopa{border: 6rpx solid #FD5001;border-radius: 36rpx;height:72rpx;box-sizing: border-box;padding:0 140rpx 0 32rpx ;position: relative;
 input{}
 image{width: 30rpx;height: 30rpx;margin-right: 24rpx;}
 .btn{background: #FA5F03;border-radius: 36rpx;width: 140rpx;position: absolute;right: -2rpx;top: -2rpx;bottom:-2rpx;}
 }
 .listtopb{
	 .tit{flex: 1;height: 130rpx;display: flex;flex-direction: column;justify-content: center;position: relative;
	 view{text-align: center;}
	 .tits{color: #666666;}
	 .txt{color: #aaaaaa;}
	 &.act{
		 &::after{content: '';width: 100rpx;height: 6rpx;background:#FE5706 ;position: absolute;left: 50%;margin-left: -50rpx;bottom: 0;}
		.tits{color: #343434;}
		.txt{color: #FE5706;} 
	 }
	 }
 }
 .alllist{padding-top:10rpx ;}
</style>