<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true" :isRingt="true">
			<block slot="backText">返回</block>
			<block slot="content">清单检查记录</block>
		</cu-custom>
		<view class="top-fixed">
			<scroll-view scroll-x class="bg-white nav" scroll-with-animation :scroll-left="scrollLeft">
				<view class="flex text-center">
					<view class="cu-item flex-sub" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in tabNav" :key="index" @tap="tabSelect" :data-id="index">
						{{tabNav[index]}}
					</view>
				</view>
			</scroll-view>
			<view class="cu-bar search bg-white">
				<view class="search-form radius">
					<text class="cuIcon-search"></text>
					<input @input="InputBlur" placeholder="请输入关键字"></input>
				</view>
				<view class="action">
					<button class="cu-btn bg-green shadow-blur radius" @click="getQuery()">搜索</button>
				</view>
			</view>
			<view class="line"></view>
		</view>

		<block v-if="TabCur==0">

			<scroll-view class="dy-scroll-nobg"  scroll-y :style="'top:'+sTop+'px;height:calc(100vh - '+totalHeight+'px)'">
				<view v-if="list.length>0" >
					<view class="dy-card" v-for="item in list" :key="item.CHECKRECORD_ID" @click="$noMultipleClicks(goToList,item.CHECKRECORD_ID)">
						<view class="dy-card-title">
							<text>清单名称：{{item.LIST_NAME}}</text>
							<text class="cuIcon-right f30 text-gray"></text>
						</view>
						<view class="dy-card-content">
							<view class="dy-sub-stitle">
								<text class="text-grey">人员：{{item.PRINCIPALNAME?item.PRINCIPALNAME:ls.USER_NAME}}</text>
							</view>
							<view class="dy-sub-stitle">
								<text class="text-grey">检查周期：{{item.DATESTART}}-{{item.DATEEND}}</text>
							</view>
							<view class="dy-sub-stitle">
								<text class="text-grey">检查人：{{item.CHECK_USERS}}</text>
								<text class="text-grey">检查时间：{{item.CHECK_TIME}}</text>
							</view>
<!--							<view class="cu-progress radius striped active">-->
<!--								<view class="bg-olive" :style="[{ width:loading?((item.checkedItem>0 && item.count>0)?(item.checkedItem/item.count*100):0)+'%':''}]">{{(item.checkedItem>0 && item.count>0)?(item.checkedItem/item.count*100):0}}%</view>-->
<!--							</view>-->
						</view>
					</view>
				</view>
				<view v-else-if="dataFlag=='noData'" class="dy-null">
					<view class="dy-null-img">
						<image :src="background[dataFlag].url" mode=""></image>
					</view>
					<view class="dy-null-title">
						{{background[dataFlag].msg}}
					</view>
				</view>
			<!-- <view class="cu-tabbar-height"></view> -->
			</scroll-view>
		</block>

		<block v-if="TabCur==1">
			<scroll-view class="dy-scroll-nobg" scroll-y :style="'top:'+sTop+'px;height:calc(100vh - '+totalHeight+'px)'">
				<view v-if="list1.length>0" >
					<view class="dy-card" v-for="item in list1" :key="item.CHECKRECORD_ID" >
						<view class="dy-card-title">
							<text>清单名称：{{item.LIST_NAME?item.LIST_NAME:ls.NAME}}</text>
						</view>
						<view class="dy-card-content">
							<view class="dy-sub-stitle">
								<text class="text-grey">人员：{{item.PRINCIPALNAME?item.PRINCIPALNAME:ls.USER_NAME}}</text>
							</view>
							<view class="dy-sub-stitle">
								<text class="text-grey">检查周期：{{item.DATESTART}}-{{item.DATEEND}}</text>
							</view>
							<view class="dy-sub-stitle">
								<text class="text-grey">清单类型：{{ls.TYPENAME}}</text>
								<text class="text-grey">清单周期：{{ls.PERIODNAME}}</text>
							</view>
<!--							<view class="cu-progress radius striped active">-->
<!--								<view class="bg-olive" :style="[{ width:loading?((item.checkedItem>0 && item.count>0)?(item.checkedItem/item.count*100):0)+'%':''}]">{{(item.checkedItem>0 && item.count>0)?(item.checkedItem/item.count*100):0}}%</view>-->
<!--							</view>-->
						</view>
					</view>
				</view>
				<view v-else-if="dataFlag=='noData'" class="dy-null">
					<view class="dy-null-img">
						<image :src="background[dataFlag].url" mode=""></image>
					</view>
					<view class="dy-null-title">
						{{background[dataFlag].msg}}
					</view>
				</view>
				<view class="cu-tabbar-height"></view>
			</scroll-view>
		</block>
	</view>
</template>

<script>
	import {
		basePath,loginUser,loginSession
	} from '@/common/tool.js';
	export default {
		data() {
			return {
				noClick:true,
				initflag:false,
				sTop:0,
				totalHeight:0,
				TabCur: 0,
				scrollLeft: 0,
				tabNav: ['已检查记录', '超期未检查记录'],
				loading: false,
				list: [],
                list1: [],
				totalList:[],
				page: 1,
				rows: 1000,
				totalCount:0,
				isEnd: false,
				total:0,
				dataFlag:'noData',
				isIndex:0,
				loginUserId:'',
				LISTMANAGER_ID:'',
				ls:'',
				KEYWORDS:'',
			}
		},
		onLoad: function(e) {
			let that = this;
			this.loginUserId = loginUser.USER_ID;
			this.LISTMANAGER_ID=e.LISTMANAGER_ID;
			this.getData();
			this.background = require('@/common/background.json');
			setTimeout(function() {
				that.loading = true
			}, 500)
			loginSession();
		},
		onReady() {
			let that=this;
			let CustomBar = this.CustomBar;
			uni.getSystemInfo({ //调用uni-app接口获取屏幕高度
				success(res) { //成功回调函数
					let titleH=uni.createSelectorQuery().select(".top-fixed"); //想要获取高度的元素名（class/id）
					titleH.boundingClientRect(data=>{
						that._data.sTop=data.height  //计算高度：元素高度=窗口高度-元素距离顶部的距离（data.top）
						that.totalHeight = data.height+CustomBar
					}).exec()
				}
			})
		},
		onShow() {
			var _this = this;
			if(_this.initflag){
				_this.initflag = false;
				_this.list = [];
				_this.list1 = [];
				this.getData()
			}
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			getData(){
				var _this=this;
				console.info(_this.isEnd);
				if (_this.isEnd){
					return
				}
				uni.showLoading({
					title: '加载中'
				})

					console.info(loginUser);
				uni.request({

					url: basePath + '/app/checkrecord/list',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						LISTMANAGER_ID:_this.LISTMANAGER_ID,
						KEYWORDS:_this.KEYWORDS,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if("success" == res.data.result){
							uni.hideLoading();
							var content = res.data.varList;
							_this.ls = res.data.ls;
							for(var i=0;i<content.length;i++){
								content[i].DATESTART = content[i].DATESTART.substring(0,content[i].DATESTART.length-3)
								content[i].DATEEND = content[i].DATEEND.substring(0,content[i].DATEEND.length-3)
								if(content[i].TYPE=='1'){
									this.list.push(content[i]);
									this.totalList.push(content[i]);
								}else{
									this.list1.push(content[i]);
									this.totalList.push(content[i]);
								}
							}
						}else{
							uni.showToast({
								icon:'none',
								title: '系统异常',
								duration: 2000
							});
						}
					}
				})
			},

			getQuery() { //搜索按钮事件
				var _this = this;
				_this.showCount = -1;
				_this.currentPage = 1;
				_this.list = [];
				_this.list1 = [];
				_this.isEnd = false;
				_this.getData();
			},
			InputBlur(e){
				this.KEYWORDS = e.detail.value
			},
			// 滑动到底方法
			scrolltolower(){
				var _this = this;
				_this.getData();
			},
			//跳转事件
			goToList(e) {
				uni.navigateTo({
					url: '/pages/application/check-record/record_info?CHECKRECORD_ID='+e
				});
				// uni.navigateTo({
				// 	url: '/pages/application/hidden-trouble-investigation/hidden-trouble-app/check-items-list?listId='+e.listId+'&listName='+e.listName
				// });
			}

		}
	}
</script>

<style>
	.dy-list {
		background: #fff;
		margin-top: 2upx;
	}
	.dy-card{
		background-color: #fff;
		border-radius: 10upx;
		margin:30upx
	}
	.dy-stitle{
		margin: 16upx 0;
	}
	.dy-sub-stitle{
		margin: 16upx 0;
		display: flex;
		justify-content: space-between;
	}
	.dy-card-title{
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #eee;
		min-height: 80upx;
		line-height: 80upx;
		padding: 0 30upx;
	}
	.dy-card-content{
		padding: 0upx 30upx 30upx;

	}
</style>
