<template>
	<el-form label-width="80px" size="mini" :inline="inline">
		<span v-for="(va, key) in value" :key="key">
			<all v-if="includes(va, 'Object')" :value="va" :keys="keys[key] || {}"></all>
			<div v-else-if="includes(va, 'Array') && keys[key]">
				<component :is="va | arrayType" :value="va" :keys="keys[key]" :headers="value['tabHeader'] || []" @change="change" :changeData="changeData"></component>
			</div>
			<template v-else>
				<el-form-item :label="keys[key] || key" v-if="keys[key] && key != '_caveat'">
					<el-input v-model="value[key]" type="textarea"></el-input>
				</el-form-item>
				<el-alert
					v-if="key == '_caveat'"
				    :title="value[key]"
				    type="error"
				    effect="dark"
					:closable="false">
				  </el-alert>
			</template>
		</span>
	</el-form>
</template>

<script>
import tplArray from './dataTypeTpl/array1Obj.vue';
import array2Obj from './dataTypeTpl/array2Obj.vue';
export default {
	name:"All",
	components: {
		tplArray,
		array2Obj
	},
	props: {
		value: {
			type: Object,
			default() {
				return {};
			}
		},
		keys: {
			type: Object,
			default() {
				return {};
			}
		},
		inline:{
			type:Boolean,
			default:false
		}
	},
	data(){
		return {
			//表头变化
			changeData:{}
		}
	},
	//检测数组 - 对应数据结构类型
	filters:{
		arrayType(value){
			return value.length?(Array.isArray(value[0])?'array2Obj':'tplArray'):'tplArray';
		}
	},
	methods:{
		change(data){
			this.changeData = data;
		}
	}
};
</script>
