<template>
	<view class="userinform">
		<view class="userItem">
			<u-collapse :value="item.index" accordion v-for="(item, index) in TechnicalEnumdata" :key="item.index">
				<u-collapse-item :name="item.index" :title="item.name">
					<view class="singleChoice" v-if="item.index == 0">
						<u-checkbox-group v-model="form[item.key]"  placement="column" @change="(arr)=>addgroups(arr,item.index)">
							<u-checkbox  v-for="(items,indexs) in item.dataList" :key="indexs"  :customStyle="{marginBottom: '8px'}"
								iconPlacement="left" size="40" labelSize="24" :label="items.name"
								:name="items.value"></u-checkbox>
						</u-checkbox-group>
					</view>
					
					<view class="singleChoice" v-else>
						<u-radio-group  v-model="form[item.key]"  placement="column" @change="(arr)=>addgroup(arr,item.index)">
							<u-radio :customStyle="{marginBottom: '8px'}" v-for="(items, indexs) in item.dataList"
								iconPlacement="left" size="40" labelSize="24" :key="index" :label="items.name" :name="items.value" >
							</u-radio>
						</u-radio-group>
					</view>
				</u-collapse-item>
			</u-collapse>
		</view>
	</view>
</template>

<script>
	import {
		TechnicalEnum
	} from './enum.js';
	import {
		mapMutations,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				TechnicalEnumdata: TechnicalEnum,
				form: {
					ipcCoverValue: undefined,
					ipcCover: 0,
                    ipcCoverDetail: undefined,
					alarmValue:0,
					alarmSystem:0,
					alarmSystemDetail:undefined,
					ipcGateValue:0,
					ipcGate:0,
					ipcGateDetail:undefined,
					ipcRecordValue:0,
					ipcRecord:0,
					ipcRecordDetail:undefined
				},

			};
		},
		created() {
			this.form = this.daily
		},
		computed: {
			// 取数据/
			...mapGetters({
				// 三色预警数据
			  daily: 'daily/getdailyinspection',
			})
		},
		mounted() {},
		methods: {
			// 存vuex数据
			...mapMutations({
				dailyinspectionList: 'daily/dailyinspectionList'
			}),
			addgroup(arr, index) {
				console.log(arr,index);
				let names = '';
				let conuts = 0;
				if (arr && arr != 0) {
					const dataLists = this.TechnicalEnumdata[index].dataList
					const _list = dataLists.filter(item => arr == item.value)
					names = _list.map(e => e.name).join(',')
					conuts = _list.map(e => e.num).reduce((a, b) => a + b)
				}
				switch (index) {
					case 1:
						this.form.alarmSystemDetail = names;
						this.form.alarmSystem = conuts;
						break;
					case 2:
						this.form.collisionDetail = names;
						this.form.collision = conuts;
						break;
					case 3:
						this.form.ipcRecordDetail = names;
						this.form.ipcRecord = conuts;
						break;
				}
				this.dailyinspectionList(this.form)
			},
			addgroups(arr,index){
				console.log(arr,index);
				 let  names = '';
				 let  conuts = 0;
				 if(arr && arr.length > 0){
				 	const dataLists = this.TechnicalEnumdata[index].dataList
				 	const _list =  dataLists.filter(item =>  arr.includes(item.value))
					console.log(_list,'44');
				 	names = _list.map(e => e.name).join(',')
				 	conuts = _list.map(e => e.num).reduce((a, b) => a + b)
				 }
				 switch (index) {	
				 	case 0:
					console.log(index)
				 	this.form.ipcCoverDetail = names;
				 	this.form.ipcCover = conuts;
				 }
				 this.dailyinspectionList(this.form)
			}
		}
	};
</script>

<style scoped lang="scss">
	.userinform {
		height: 100%;
		width: 100%;
	}

	.userItem {
		color: #7b7b7b;
		font-size: 14px;
		margin-bottom: 8px;

		.textIndex {
			margin-left: 20rpx;
		}
	}

	.text {
		width: 96%;
	}

	.singleChoice {
		width: 90%;
	}

	.label {
		margin: 0 20px;
	}

	/deep/ .u-radio-group--row {
		display: flex;
		flex-direction: row;
		text-align: center;
		align-content: center;
		justify-content: space-evenly;
	}
</style>