<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="1200" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main style="padding:0 20px 20px 20px">
				<sc-form ref="formref" :config="config" v-model="info" :loading="loading"> </sc-form>
			</el-main>
			<el-footer>
				<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
				<el-button @click="visible=false">取消</el-button>
			</el-footer>
		</el-container>
	</el-drawer> 
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				loading: false,
				visible: false,
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑'
				},
				info:{},
				config:{}
			}
		},
		mounted() {

		},
		methods: {
			submit(){
				this.$refs.formref.validate((valid, obj) => {
					if (valid) {
						console.log(this.info)
						alert('submit!')
					}else{
						this.$refs.formref.scrollToField(Object.keys(obj)[0])
						return false
					}
				})
			},
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			setConfig(){
				var that = this;
				this.$API.app.apartment.config.get().then((res) => {
					console.log(res)
					that.config = res.data;	
				});
				return this;
			},
			//表单注入数据
			setData(data){
				this.loading = true
				const params = {
					id: data.id,
					uniqid: data.uniqid,
				}
				setTimeout(async ()=>{
					var res = await this.$API.app.apartment.info.get(params)
					if (res.code==200) {
						this.loading = false
						this.info = res.data.info;
						return ;
					}

					this.$message.warning(res.message)
					this.visible = false;
				},400)

			},
			
		}
	}
</script>

<style>
</style>
