<template>
	<view class="mb-5">
		<view class="m-3">
			<view class="centerY mt-3">
				<view class="bule_line" style=""></view>
				<text class="font-bold text-dark ml-2 fs-16 line-height1">全年检查计划</text>
			</view>
			<view class="mt-3 bg-white p-3">
				<view class="">
					<view class="mtable-title centerY bg-primary text-white fs-12">
						<view class=" w-20">
							时间
						</view>
						<view class=" text-center w-80">
							检查项
						</view>
					</view>
					<view v-if="yearCheck.length>0" class="mtable-body-item centerY fs-12"
						v-for="(item,index) in yearCheck" style="color: #868687;">
						<view class="w-20">
							{{item.date}}
						</view>
						<view class="w-80">
							<span>{{item.value}}</span>
						</view>
					</view>
					<view class="px-3 pb-3 mt-n2" v-if="yearCheck.length==0">
						<Empty title="没有检查计划" class="py-5" />
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Empty from '@/component/empty/empty.vue'
	import Moment from 'moment'
	export default {
		components: {
			Empty
		},
		name: "AnnualInspectionPlan",
		props: {
			propData: {
				type: Object,
				default () {
					return {
						yearCheck: []
					}
				},
			},
		},
		data() {
			return {
				yearCheck: []
			}
		},
		watch: {
			propData: {
				handler(val) {
					this.getyearCheck(val)
				},
			},
		},
		created() {

		},
		methods: {
			async getyearCheck(res) {
				// this.yearCheck = data
				let data = res.yearCheck ? res.yearCheck : [];
				if(data.length==0){
					this.yearCheck = [];
					return
				}
				let data1 = []
				data.map((item) => {
					let str = ''
					let arr = Object.values(item)
					arr.map((item1, index) => {
						str += index + 1 + '. ' + item1 + '；'
					})
					data1.push(str)
				})
				let yearList = (function() {
					let date = new Date()
					let arr = []
					for (let i = 0; i < 12; i++) {
						arr.push(
							date.getFullYear() +
							'-' +
							Moment(date.getFullYear()).add(i, 'months').format('MM')
						)
					}
					return arr
				})()
				// console.log(data1,yearList,this.yearCheck)
				let yearCheck1 = []
				yearList.map((item, index) => {
					yearCheck1.push({
						date: item,
						value: data1[index]
					})
				})
				this.yearCheck = yearCheck1
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F9FF;
	}

	.mtable {
		&-title {
			border-radius: 50rpx;
			padding: 20rpx;
			box-shadow: 0px 2px 7px 1px rgba(45, 142, 255, 0.5);
		}

		&-body {
			&-item {
				margin-top: 20rpx;
				border-radius: 50rpx;
				padding: 20rpx;
				background-color: #F6F9FE;
				color: #868687;
			}
		}
	}
</style>
