<template>
	<view class="yiCheckbox">
		<view class="typesname">{{chinddata.name}}:</view>
		<view class="yiCheckbox_body flex  flex-wrap">
			<!-- v-for="(value,index) in chinddata.spec_item" -->
			<!-- :class="{'cur': rSelect.indexOf(index)!=-1}" -->
			<view class="chindboxitem" :class="{'cur': chindisarr[index1]==true}"  v-for="(item, index1) in chinddata.spec_item"  :key="index1" @tap="tapInfo(item,index1)">
			<!-- {{value.name}} -->
				{{ item.name }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			//数据
			chinddata:{
				type:Object,
				default:()=>{
					return {};
				}
			},
			isindex:{
				type:Number,
				default:0,
			}
		},
		data(){
		        return{
		            rSelect:[],//选中的列表
					isdataarr:[],//选中的数据
					infoArr:[
						{name:"石霸天"},
						{name:"石1天"}
					],
					//myischildlist:[],//存储选中的状态
					//这里坑了 先这样写 赶时间 
					chindisarr:[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],
					isswitch:true,
				}
		},
		computed:{
			
		},
		methods:{
			tapInfo(item,index) {
				//设置开关 防止点击过快
				if(this.isswitch==true){
					this.isswitch = false;
					
					
					if (this.chindisarr[index] == false) {//没选 就选
						
						this.rSelect.push(item);//选中添加到数组里
						
						this.isdataarr.push(item);//选中的数据 真实的 {name:this.chinddata.spec_item[key],id:key}
						
						// let chinddata = this.chinddata;
						// chinddata.spec_item[index].ischild = true;
						
						//this.chindisarr[index] = true;
						this.$set(this.chindisarr, index, true);
						
						//this.$emit("changeSpecList",{data:chinddata,index:this.isindex,specList_item_id:this.chinddata.id});
						
					} else {
						this.rSelect.splice(index, 1); //取消
						
						this.isdataarr.splice(index, 1);
						
						//this.chindisarr[index] = false;
						
						this.$set(this.chindisarr, index, false);
						
						
						// let chinddata = this.chinddata;
						// chinddata.spec_item[index].ischild = false;
						// this.$emit("changeSpecList",{data:chinddata,index:this.isindex,specList_item_id:this.chinddata.id});
					}
					
					//把选中的值传回去
					
					
					let chlist = [];
					//重新筛选一份选中的类别 之前的有误差
					this.chinddata.spec_item.forEach((item,index)=>{
						if(this.chindisarr[index]==true){
							chlist.push(item);
						}
						
					})
					
					//this.isdataarr
					
					this.isswitch = true;//打开开关
					this.$emit("changecheckbox",{indexsz:this.isindex,child:chlist,specList_item_id:this.chinddata.id});
					
				}
				
			}
		},
		onLoad() {
			
		},
	}
</script>

<style lang="scss">
	.yiCheckbox{
		margin-top: 20upx;
	}
	.typesname{
		color:#000000;
		font-weight: bold;
		margin-bottom: 10upx;
	}
	.chindboxitem{
		padding:8upx 20upx;
		margin-right: 15upx;
		border-radius: 10upx;
		color:#FFFFFF;
		background-color: #c8c7cc;
		margin-bottom: 10upx;
	}
	.cur {
			color: white;
			border: 1px solid #e5e5e5;
			background-color: #ff5d00;
	}
</style>
