<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" draggable destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="right">
			<el-form-item label="部件SN/Sp" prop="component_serial_no">
				<el-input class="input" v-model="form.component_serial_no" placeholder="部件SN/Se"></el-input>
			</el-form-item>
			<el-form-item label="部件厂商" prop="component_manufacturer">
				<el-input class="input" v-model="form.component_manufacturer" type="text" placeholder="请输入部件厂商"></el-input>
			</el-form-item>
			<el-form-item label="部件型号" prop="component_model">
				<el-input class="input" v-model="form.component_model" type="text" placeholder="请输入部件型号"></el-input>
			</el-form-item>
			<el-form-item label="部件PN/Sp" prop="component_pn">
				<el-input class="input" v-model="form.component_pn" type="text" placeholder="请输入部件SN/Sp"></el-input>
			</el-form-item>
<!--			<el-form-item label="SLA截止时间" prop="sla_expiration">-->
<!--				<el-date-picker class="input" v-model="form.sla_expiration" type="date" value-format="YYYY-MM-DD" placeholder="请选择SLA截止时间" style="width: 100%"></el-date-picker>-->
<!--			</el-form-item>-->
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSave" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增部件信息',
					edit: '编辑部件信息',
				},
				visible: false,
				isSave: false,
				//表单数据
				form: {
					component_serial_no:"",
					component_manufacturer:"",
					component_model:"",
					component_pn:""
				},
				rules:{},
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.$emit('success', this.form, this.mode);
						this.visible = false;

						// this.isSave = true;
						// const res = await this.$API.system.role.add.post(this.form);
						// this.isSave = false;
						// if(res.code == 200){
						// 	this.$message.success("操作成功")
						// }
					}
				})
			},
			//表单注入数据
			setData(data){
				if(data.id){
					this.form.id = data.id;
				}else{
					this.form.num = data.num;
				}
				this.form.component_serial_no = data.component_serial_no;
				this.form.component_manufacturer = data.component_manufacturer;
				this.form.component_model = data.component_model;
				this.form.component_pn = data.component_pn;
			}
		}
	}
</script>

<style scoped lang="scss">

</style>
