<template>
	<view class="allpage">
		<view class="listtop pfixed">
			<tab-searchone @getSearch='getSearch' placeholder='单位'></tab-searchone>
			<tab-list :tablist='tablist' :tabidx="tabidx" @getCheck="goCheck" ></tab-list>
			<view class="flexc allpage_zd">
				<time-year :fields="fields" @bindDateChange="bindDateChange" textAlign='right' timetxt='选择日期'></time-year>
			</view>
			
			
		</view>
		<view class="alllist">
			<!-- l列表 -->
			<project-list :datalist="list" v-if="tabidx==0" :wtdt="wtdt" type='tongjizs' @getDetail='goDetail'></project-list>
			<project-list :datalist="list" v-if="tabidx==1" :wtdt="wtdt" type='tongjiks' @getDetail='goDetail'></project-list>
		</view>
		<!-- <block v-if="checkPermi(['system:qktj:add'])">
			<view style="height: 100rpx;"></view>
			<view class="count_btn" @click="getAddCount" >
				<image :src="addimg"></image>新增</view>
		</block> -->
		
	</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 { getdjkslistFn,getwczslistFn} from '@/api/work/count.js'
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		data(){
			return{
				upimg:require("@/static/images/index/up.png"),
				addimg:require("@/static/images/index/addt.png"),
				tabidx:0,
				// projectV2:sbbzb:list
				// 
				tablist:[{tit:'外出招商',val:0,limt:'system:wczs:list'},{tit:'对接客商',val:1,limt:'system:djks:list'}],
				list:[],
				fields:'month',
				pageSize: 10,
				pageNum: 1,
				reachflag:true,
				wtdt:'',
				time:'',
				beginTime:'',
				endTime:'',
				name:'',
				wtdt:'',
				deptId:this.$store.state.user.deptId,
				strfrom:'',
				
			}
		},
		components:{
			projectList,tabList,tabSearchone,timeYear
		},
		onUnload(){
			uni.$off('refreshdata')
		},
		onLoad(e) {
			uni.$on('refreshdata',(e) => {
				// // 修改统计列表数据
				uni.$emit('refreshdatatong')
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn();
			})
			this.strfrom=e.strfrom||'';
			this.getDataFn()
		},
		//
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getAddCount(){
				// this.$tab.navigateTo('/pages/work/count/addcount?strfrom=list') 
			},
			bindDateChange(e){
				this.time=e;
				var timestr=e.split('-');
				this.year=timestr[0];
				this.month=timestr[1];
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn()
			},
			goCheck(data){
				this.tabidx=data;
				this.reachflag=true;
				this.pageNum=1;
				this.list=[];
				this.getDataFn()
			},
			goDetail(e){
				if(this.tabidx==0){
					this.$tab.navigateTo('/pages/work/count/addzscount?id='+e.id+'&strfrom=list&pagetype=update')
				}else{
					this.$tab.navigateTo('/pages/work/count/addkscount?id='+e.id+'&strfrom=list&pagetype=update')
				}
				
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					year:this.year,
					month:this.month,
					deptName:this.name
				}
				
				if(this.tabidx==0){//外出招商
					getwczslistFn(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)
						}
					})
				}else {//对接客商
					getdjkslistFn(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()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.allpage{min-height: 100vh;background: #ffffff;padding-top:280rpx;box-sizing: border-box;}
.listtop{box-shadow: none !important;}
.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 ;}
 //统计
  .allpage_zd{background-color:#F2F2F2;padding: 0 28rpx;justify-content: space-between;
 	.allpage_zdl{font-size: 30rpx;font-weight: 500;
 color: #666666;
 	text{font-weight: bold;color: #FE5706;margin: 0 8rpx;}
 }
 }
 .count_btn{position: fixed;left: 0;right: 0;bottom: 0;z-index: 4;width: 100%;height: 100rpx;font-size: 32rpx;color: #ffffff;font-weight: 500;
 background: #FE5706;display: flex;align-items: center;justify-content: center;
 image{width: 34rpx;height: 34rpx;margin-right: 16rpx;}
 
 }
</style>