<template>
	<view>
		<view class="ythTimer">
			<!-- <view style="display: flex;align-items: center;"> -->
			<view>
				<view style="width: 30%;">
					<uni-data-select v-model="yearValue" :localdata="range" @change="change"
						:clear="false"></uni-data-select>
				</view>
				<!-- <view style="margin-left: 10px;background: #DFEDF8;color: #1872f8;border: 1px solid #1872f8;display: flex;justify-content: center;align-items: center;border-radius: 5px;">
          <span style="padding: 6rpx 24rpx;font-size: 26rpx;">全部</span>
        </view> -->
			</view>
			<view class="conWidth">
				<view v-if="listData && listData.length != 0">
					<view class="conItem" v-for="(item,index) in listData" :key="index">
						<view class="conTitle">
							<view style="font-size: 36rpx;color: #333;">{{ item.projectName }}</view>
							<view v-if="item.schemaStatus == '0'"
								style="background: #feefef;border: 1px solid #bd4040;border-radius: 6px;display: flex;justify-content: center;align-items: center;">
								<span style="font-size:24rpx;color:#bd4040;padding: 3px 8px;">未完成</span>
							</view>
							<view v-if="item.schemaStatus == '1'"
								style="background: #f8f8f8;border: 1px solid #e9e9e9;border-radius: 6px;display: flex;justify-content: center;align-items: center;">
								<span style="font-size:24rpx;color:#959595;padding: 3px 8px;">已完成</span>
							</view>
						</view>
						<view style="margin-top: 8px;line-height: 20px;">
							<view style="font-size: 24rpx;color: #999;">
								计划时间：{{ item.scheduleTime }}
							</view>
							<view style="font-size: 24rpx;color: #999;">
								有效时段：{{ item.minValidTime }} 至 {{ item.maxValidTime }}
							</view>
							<view style="font-size: 24rpx;color: #999;" v-if="item.schemaStatus == '1'">
								完成医生：{{ item.doctorName }}
							</view>
							<view style="font-size: 24rpx;color: #999;" v-if="item.schemaStatus == '1'">
								完成机构：{{ item.orgName }}
							</view>
							<view style="font-size: 24rpx;color: #999;" v-if="item.schemaStatus == '1'">
								实际完成时间：{{ item.actualTime }}
							</view>
						</view>
						<!-- <view style="border-bottom: 1px solid #EEEEEE;margin: 8px 0;" v-if="item.schemaStatus == '1'"></view> -->
						<!-- <view style="text-align: center;" @click="goToDetail" v-if="item.schemaStatus == '1'">
            <span style="color: #1872f8;font-size: 26rpx;">查看详情</span>
          </view> -->
					</view>
				</view>
				<view class="empty" v-else>
					暂无记录
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import lauwenSelect from "@/components/lauwen-select/lauwenSelect.vue"
	// lauwenSelect
	import {
		getIntegrationList
	} from '@/api/pagesC/integration/index.js'
	export default {
		components: {
		},
		data() {
			return {
				yearValue: '',
				lauwentext: 1,
				// options: [],
				range: [],
				listData: [],
				total: '',
				form: {
					pageNum: 1,
					pageSize: 15
				}
			};
		},
		onLoad() {
			let data = new Date()
			const getYear = (val) => {
				// 获取指定年份开始到现在年份的数组
				//获取到从那一年开始
				let timList = [];
				let smallYears = val;
				let date = new Date(); //获取当前时间
				let NowYears = date.getFullYear();
				var Years = NowYears - smallYears;
				let arrTim = [];
				for (let index = 0; index <= Years; index++) {
					arrTim.push(NowYears--);
				}
				arrTim.forEach((tim) => {
					timList.push(tim);
				});
				return timList
			}
			let arr = getYear(2022) //传入指定的开始年份
			// console.log(arr);
			// let Yearoption = [] //以一个Obj  push到Array里面
			for (let i = 0; i < arr.length; i++) {
				this.yearValue = arr[i]
				this.range.push({
					text: arr[i],
					value: arr[i]
				})
			}
			uni.$showMsg = function(title = '数据加载失败!', duration = 1500) {
				uni.showToast({
					title,
					duration,
					icon: 'none'
				})
			}
			this.listData = []
			this.yearValue = data.getFullYear()
			this.getYthList()
		},
		onReachBottom() {
			if (this.form.pageNum * 15 >= this.total) {
				return uni.$showMsg('数据加载完毕!')
			} else {
				this.form.pageNum++
				this.getYthList() //调用函数
			}
		},
		methods: {
			change(e) {
				this.listData = []
				this.yearValue = e
				this.getYthList()
			},
			// 获取列表
			getYthList() {
				let that = this
				let userInfo = uni.getStorageSync('userinfo')
				let data = {
					identity: userInfo.cardNo,
					// identity:'370503195407100031',
					year: that.yearValue,
					pageNum: this.form.pageNum,
					pageSize: this.form.pageSize
				}
				getIntegrationList(data).then(res => {
					// console.log(res);
					for (var i = 0; i < res.data.list.length; i++) {
						that.listData.push(res.data.list[i])
					}
					that.total = res.data.total
				})
			},
			getValue(index) {
				this.showIndex = index
			},
			// 查看详情
			goToDetail() {
				uni.navigateTo({
					url: '../integrationDatail/integrationDatail'
				})
			}
		}
	}
</script>

<style lang="scss">
	.empty {
		text-align: center;
		padding: 50rpx;
		color: #999;
	}

	page {
		background-color: #fff;
	}

	.ythTimer {
		width: 93%;
		margin: 0 auto;
		padding: 20rpx 0 50rpx;

		.conWidth {
			margin-top: 24px;

			.conItem {
				padding: 20rpx 30rpx;
				background-color: #f8f8f8;
				margin: 16px auto;

				.conTitle {
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
			}
		}
	}
</style>