<template>
	<view class="userinform">
		<view class="userinformItem">
			<view class="exit" v-for="(item, index) in starRating" :key="item.id" @click="Onrating(5,item.id)">
				<view class="exitItem">
					<text style="margin-left: 30rpx;font-size: 16px;">{{ item.name }}</text>
				</view>
				<view style="margin-right: 40rpx">
					<text class="iconoscope"></text>
				</view>
			</view>
			<view>
				<u--form labelWidth="100rpx">
					<u-form-item label="备注:" borderBottom>
						<u--textarea v-model="daily.comment" :maxlength="-1" placeholder="请输入内容" autoHeight></u--textarea>
					</u-form-item>
				</u--form>
			</view>


			<!-- 签字 -->
			<view>
				<u--form labelWidth="320rpx" labelAlign="left">
					<u-form-item label="考核人员签字:">
						<navigator :url="`/pages/signature/signature?index=${2}&name=${1}`"
							hover-class="navigator-hover">
							<u-button type="default">考核人员签字</u-button>
						</navigator>
					</u-form-item>
					<u-form-item v-if="mydailycolors">
						<view style="padding: 0;">
							<image :src="mydailycolors"></image>
						</view>
					</u-form-item>
					<u-form-item label="被考评学校签名:">
						<navigator :url="`/pages/signature/signature?index=${2}&name=${2}`"
							hover-class="navigator-hover">
							<u-button type="default">被考评学校负责人</u-button>
						</navigator>
					</u-form-item>
					<u-form-item v-if="mydailycolorschools">
						<view style="padding: 0;">
							<image :src="mydailycolorschools"></image>
						</view>
					</u-form-item>
					<u-form-item label="确认:">
						<u-button @click="OnSubmit">确认提交</u-button>
					</u-form-item>
					<view style="height: 20px;"></view>
				</u--form>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	import {
		getstationbase,
		getcheckaddList
	} from '@/api/login';
	import {
		timestampFormatTime,
		Time
	} from '@/utils/index.js';
	// import {starRating} from '../enumeration.js'
	export default {
		data() {
			return {
				starRating: [{
						id: 0,
						name: '人防',
						score: 20,
						score1: '20',
						topic: '6'
					},
					{
						id: 1,
						name: '物防',
						score: 20,
						score1: '20',
						topic: '3'
					},
					{
						id: 2,
						name: '技防',
						score: 30,
						score1: '30',
						topic: '4'
					},
					{
						id: 3,
						name: '心防',
						score: 10,
						score1: '10',
						topic: '2'
					},
					{
						id: 4,
						name: '制度防',
						score: 20,
						score1: '20',
						topic: '8'
					},
					// {
					//   id: 5,
					//   name: '防范案事件'
					// }
				],
				Colour: 0,
				Colour1: 0,
				Colour2: 0,
				Colour3: 0,
				Colour4: 0,
				baseURl: 'https://www.lonsungsh.com:8083',
				mydailycolors: '',
				mydailycolorschools: ''
				// markColor1:100
			};
		},
		created() {
			
		},
		beforeDestroy(){
			 uni.removeStorage({key:'dailycolor'})
			 uni.removeStorage({key:'dailycolorschool'})
			 this.cleardailtcolour();
		},
		mounted() {},
		computed: {
			// 拿取vuex数据三色评定数据
			...mapGetters({
				daily: 'daily/getdailyinspection',
				// 用户信息
				userInfo: 'users/getLoginInfo',
				 usershool: 'users/getschoolList',
			})
		},
		onLoad(val) {
			console.log(val);
		},
		onShow() {
			
			this.mydailycolors = uni.getStorageSync("dailycolor");
			this.mydailycolorschools = uni.getStorageSync("dailycolorschool");
		},
		methods: {
			...mapMutations({
				// 提交以后清空
				cleardailtcolour: 'daily/cleardailtcolour'
			}),
			Onrating(index,id) {
				console.log(index,id);
				switch (id) {
				  case 0:
				    uni.navigateTo({
				      url: `/pagesC/dailyLife/dailyLife?index=${id}&&number=${index}`
				    });
				    break;
				  case 1:
				    uni.navigateTo({
				      url: `/pagesC/Encapsulation/Encapsulation?index=${id}`
				    });
				    break;
				  case 2:
				   uni.navigateTo({
				     url: `/pagesC/prevendaily/prevendaily?index=${id}`
				   });
				    break;
				  case 3:
				  uni.navigateTo({
				    url: `/pagesC/psydaily/psydaily?index=${id}`
				  });
				    break;
				  case 4:
				  uni.navigateTo({
				    url: `/pagesC/regimedaily/regimedaily?index=${id}`
				  });				   
				    break;
				}
			},
			// 确定
			OnSubmit() {
				let dailycolours = this.daily;
				const { borough,nickname} = this.usershool;
				const { name } = this.userInfo
				const threeList = {
					brigade: '长沙芙蓉区',
					station: nickname,
					borough: borough,
					detachment: '',
					checkerName: name,
					schoolTime: Time(),
					guarderCount: Math.abs(Number(dailycolours.guarderCount)),
					guarderCountDetail: dailycolours.guarderCountDetail,
					guarderCert: Math.abs(Number(dailycolours.guarderCert)),
					guarderCertDetail: dailycolours.guarderCertDetail,
					guarderOverAge: Math.abs(Number(dailycolours.guarderOverAge)),
					guarderOverAgeDetail: dailycolours.guarderOverAgeDetail,
					peakGuarderArmed: Math.abs(Number(dailycolours.peakGuarderArmed)),
					peakGuarderArmedDetail: dailycolours.peakGuarderArmedDetail,
					peakProtectScheme: Math.abs(Number(dailycolours.peakProtectScheme)),
					peakProtectSchemeDetail: dailycolours.peakProtectSchemeDetail,
					peakStaff: Math.abs(Number(dailycolours.peakStaff)),
					peakStaffDetail: dailycolours.peakStaffDetail,
					zoneClosed: Math.abs(Number(dailycolours.zoneClosed)),
					zoneClosedDetail: dailycolours.zoneClosedDetail,
					equipCount: Math.abs(Number(dailycolours.equipCount)), //8
					equipCountDetail: dailycolours.equipCountDetail,
					collision: Math.abs(Number(dailycolours.collision)),
					collisiontDetail: dailycolours.collisiontDetail,
					ipcCover: Math.abs(Number(dailycolours.ipcCover)), //10
					ipcCoverDetail: dailycolours.ipcCoverDetail,
					alarmSystem: Math.abs(Number(dailycolours.alarmSystem)),
					alarmSystemDetail: dailycolours.alarmSystemDetail,
					ipcGate: Math.abs(Number(dailycolours.ipcGate)),
					ipcGateDetail: dailycolours.ipcGateDetail,
					ipcRecord: Math.abs(Number(dailycolours.ipcRecord)),
					ipcRecordDetail: dailycolours.ipcRecordDetail,
					lawEducation: Math.abs(Number(dailycolours.lawEducation)),
					lawEducationDetail: dailycolours.lawEducationDetail,
					conflict: Math.abs(Number(dailycolours.conflict)),
					conflictDetail: dailycolours.conflictDetail,
					guarderScheme: Math.abs(Number(dailycolours.guarderScheme)),
					guarderSchemetDetail: dailycolours.guarderSchemetDetail,
					buildingScheme: Math.abs(Number(dailycolours.buildingScheme)),
					buildingSchemeDetail: dailycolours.buildingSchemeDetail,
					fireScheme: Math.abs(Number(dailycolours.fireScheme)),
					fireSchemeDetail: dailycolours.fireSchemeDetail,
					dangerousScheme: Math.abs(Number(dailycolours.dangerousScheme)),
					dangerousSchemeDetail: dailycolours.dangerousSchemeDetail,
					conflictScheme: Math.abs(Number(dailycolours.conflictScheme)),
					conflictSchemeDetail: dailycolours.conflictSchemeDetail,
					guarderPMIScheme: Math.abs(Number(dailycolours.guarderPMIScheme)),
					guarderPMISchemeDetail: dailycolours.guarderPMISchemeDetail,
					securityServiceScheme: Math.abs(Number(dailycolours.securityServiceScheme)),
					securityServiceSchemeDetail: dailycolours.securityServiceSchemeDetail,
					criminalCase: Math.abs(Number(dailycolours.criminalCase)),
					criminalCaseDetail: dailycolours.criminalCaseDetail,
					signatureImage: this.mythreecolors,
					signatureImageSchool: this.mythreecolorschools,
					comment:dailycolours.comment
				};

				if (this.userInfo.personType === 'school.manager' || this.userInfo.personType === 'police.manager') {
					getcheckaddList(threeList)
						.then((res) => {
							uni.showLoading({
								title: '正在上传中..'
							});
							setTimeout(() => {
								uni.hideLoading();
								uni.showToast({
									title: '提交成功',
									success: (res) => {
										setTimeout(() => {
											uni.switchTab({
												url: '/pages/securityCheck/securityCheck'
											});
										}, 1000);
										uni.removeStorage({key:'dailycolor'})
										uni.removeStorage({key:'dailycolorschool'})
										// 这里进行清除数据
										this.cleardailtcolour();
									}
								});
							}, 1000);
						})
						.catch(() => {});
				} else {
					uni.showToast({
						title: '无权限',
						success: (res) => {
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/securityCheck/securityCheck'
								});
							}, 1000);
						}
					});
				}
			},

			// threeColour() {
			// 	let Sum = this.daily;
			// 	this.Colour = (Sum.guarderCount + Sum.guarderCert + Sum.guarderOverAge + Sum.peakGuarderArmed + Sum
			// 		.peakProtectScheme + Sum.peakStaff) / 10
			// 	this.Colour1 = (Sum.zoneClosed + Sum.equipCount + Sum.collision) / 10
			// 	this.Colour2 = (Sum.ipcCover + Sum.alarmSystem + Sum.ipcGate + Sum.ipcRecord) / 10
			// 	this.Colour3 = (Sum.lawEducation + Sum.conflict) / 10
			// 	this.Colour4 = (Sum.guarderScheme + Sum.buildingScheme + Sum.fireScheme + Sum.dangerousScheme + Sum
			// 		.conflictScheme + Sum.guarderPMIScheme + Sum.securityServiceScheme + Sum.criminalCase) / 10

			// 	Object.keys(this.starRating).forEach((item, index) => {
			// 		switch (index) {
			// 			case 0:
			// 				this.starRating[index].score = 20 - this.Colour
			// 				break;
			// 			case 1:
			// 				this.starRating[index].score = 20 - this.Colour1
			// 				break;
			// 			case 2:
			// 				this.starRating[index].score = 30 - this.Colour2
			// 				break;
			// 			case 3:
			// 				this.starRating[index].score = 10 - this.Colour3
			// 				break;
			// 			case 4:
			// 				this.starRating[index].score = 20 - this.Colour4
			// 				break;
			// 		}
			// 	})
			// 	Sum.markColor = this.starRating.map(item => item.score).reduce((a, b) => a + b)

			// }
		}
	};
</script>

<style scoped lang="scss">
	.userinform {
		// height: 100vh;
		width: 100%;
		background-color: #e9eef4;

		// overflow: hidden;
		.userinformItem {
			background-color: #fff;
			// height: 94vh;
			margin-top: 20rpx;

			.signaITtem {
				display: flex;
				align-items: center;
				justify-content: space-around;
				color: #666666;
				margin: 20rpx 0;
			}
		}

		.queryTrich {
			margin: 20rpx 40rpx;
		}

		.exit {
			height: 100rpx;
			line-height: 40px;
			border-bottom: solid 0.5px #ebebf7;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.exitItem {
				display: flex;
				align-items: center;
			}

			.iconoscope {
				z-index: 9999;
				width: 8px;
				height: 8px;
				display: inline-block;
				border: solid 2px #c2c2c2;
				margin-left: 10px;
				transform: rotate(45deg);
				border-bottom: white;
				border-left: white;
			}
		}

		/deep/ .u-button {
			width: 280rpx;
			height: 50rpx;
			line-height: 22px;
			font-size: 12px;
			margin: 0;
			color: #fff;
			border: none;
			border: 1px solid #4e87ff;
			background-color: #4e87ff;
		}

		/deep/ .u-form-item__body__left {
			margin-left: 28rpx;

		}

		/deep/.u-form-item__body__left__content__label {
			color: #666666;
		}
	}
</style>