<template>
	<view>
		<view class=""v-if="list.length > 0">
			<view class="Inspection" @click="todetails(item)" v-for="(item,index) in list">
				<view class='Inspection_name'>{{item.project_name ? item.project_name : ''}}</view>
				<view class="Inspection_time">{{formatDate(item.inspect_date,'yyyy-MM-dd hh:mm:ss') !='' ? formatDate(item.inspect_date,'yyyy-MM-dd hh:mm:ss') : ''}}</view>
			</view>
		</view>
		<emptyPage v-else></emptyPage>
		<!-- <view class="red" v-if='page>1' @click="dainji_top">
			返回上页
		</view> -->
		<!-- <view class="gengduo" v-if='wenzishow'>
			无更多数据
		</view> -->
		<van-toast id="van-toast" />
	</view>
</template>

<script>
	// import movableRefresh from '@/components/zyq-movableRefresh/zyq-movableRefresh.vue'
	import {getInspection} from '@/api/api.js'
	import {formatDate} from "@/utils/formatDate.js"
	import emptyPage from '@/components/emptyPage.vue'
	import Toast from '@/wxcomponents/vant/toast/toast';
	// import icon from '@/wxcomponents/vant/icon/index'
	export default {
		components: {
			// movableRefresh,
			emptyPage
		},
		data() {
			return {
				list: [],
				contune:[],
				page: 1,
				number:10,
				patient_id:0,
				org_id:0,
				scrollHeight: 300,
				noMore: false,
				total:null,
				wenzishow:false,
			}
		},
		onLoad() {
			console.log('this.$store.state.data',this.page);
			this.patient_id = this.$store.state.data.userInfo.id
			this.org_id = this.$store.state.data.userInfo.user_org_id
			console.log('00000',this.patient_id);
			this.getInspection()
			let system = uni.getSystemInfoSync()
			this.scrollHeight = system.windowHeight - system.statusBarHeight - 50
			console.log('system.windowHeight',system.windowHeight,system.statusBarHeight);
			// this.refresh()
		},
		methods: {
			async getInspection(){
				const toast = Toast.loading({
					message: '加载中...',
					forbidClick: true,
				});
				let params={
					page: this.page,
					number:this.number,
					patient_id:this.patient_id,
					// patient_id:20214,
					org_id:this.org_id,
				}
				let res=await getInspection(params)
				let list=[]
				console.log('asdfsgertqewr',res);
				if(res.data.state==1){
					list =res.data.data.list
					// this.list=list
					this.list =this.list.concat(list)
					// console.log('');
					// if(this.page>1){
						// list =list.concat(list)
						// this.list=list
					// }
					
					console.log('mmmmm',this.list);
					this.total=list.length
					// console.log('contune',contune);
				}
				toast.clear()
			},
			formatDate(value, fmt) {
				return formatDate(new Date(value * 1000), fmt)
			},
			todetails(item){
				console.log(item,'item,idx')
				uni.navigateTo({
					// url: '/pages/inspection_new/detail?project_id='
					url:`/pages/inspection_new/detail?project_id=${item.project_id}&inspect_date=${item.inspect_date}`
				})
			},
			// refresh() {
			// 	this.page = 1
			// 	this.noMore = false
			// 	let list = []
			// 	for (let i = 0; i < 15; i++) {
			// 		list.push(i)
			// 	}
			// 	this.list = list
			// 	this.page++
			// 	if (this.$refs.movableRefresh) {
			// 		let that = this
			// 		setTimeout(function() {
			// 			that.$refs.movableRefresh.endLoad() //刷新结束
			// 		}, 500)
			// 	}
			// },
			// loadMore() {
			// 	if (this.noMore) {
			// 		return
			// 	}
			// 	let list = this.list
			// 	let page = this.page
			// 	let that = this
			// 	let start = (page - 1) * 15
			// 	setTimeout(function() {
			// 		for (let i = 0; i < 15; i++) {
			// 			list.push(start + i)
			// 		}
			// 		that.page++
			// 		that.list = list
			// 		that.$refs.movableRefresh.endLoad() //刷新结束
			// 		if (that.page > 2) {
			// 			that.noMore = true
			// 		}
			// 	}, 500)
			// },
			dainji_top(){
				console.log('yyyyy',this.page);
				this.page--;
				console.log('uuuuu',this.page);
				this.getInspection()
			}
		},
		onReachBottom(){
			console.log('已加载全部数据',this.page)
			// let  allTotal = (this.page+1) * this.number
			// if(allTotal < this.total){
				//当前条数小于总条数 则增加请求页数
				this.page ++;
				this.getInspection() //调用加载数据方法
			// }else{
			// 	this.wenzishow=true
			// 	console.log('已加载全部数据')
			// }
		},
	}
</script>

<style>
	@import url(./Inspection.css);
</style>
<style>
	.red{
		background: #03a9f461;
		position: fixed;
		right: 0;
		bottom: 30px;
		height: 40px;
		width: 40px;
		border-radius: 25px;
		font-size: 14px;
		text-align: center;
	}
</style>


