<template>
	<el-dialog :title="titleMap[mode]" :visible.sync="visible" width="500px" destroy-on-close @closed="$emit('closed')">
		<el-form ref="dialogForm" :model="form"  :rules="rules" label-width="80px">
		        <!--el-form-item label="项目编码" prop="parCode">
		          <el-input v-model="form.parCode" placeholder="请输入编码" />
		        </el-form-item-->
		        <!--el-form-item label="项目名称" prop="parName">
		          <el-input v-model="form.parName" placeholder="请输入名称" />
		        </el-form-item-->
		        <el-form-item label="无故障持续时间" prop="parValue" label-width="120px">
		          <el-input v-model="form.parValue" placeholder="请输入值" />
		        </el-form-item>
		        <el-form-item label="计量单位" prop="parUnit" label-width="120px">
				  <el-select
				    v-model="form.parUnit"
				    placeholder="计量单位"
				    clearable
				  >
				    <el-option
				      v-for="dict in dict.type.pdm_maintenance_time" 
				      :key="dict.value"
				      :label="dict.label"
				      :value="dict.value"
				    />
					<el-option
					  v-for="dict in dict.type.repeat_power_failure" 
					  :key="dict.value"
					  :label="dict.label"
					  :value="dict.value"
					/>
				  </el-select>
				    </el-form-item>
				  <el-form-item label="奖励金额" prop="parField" label-width="120px">
				    <el-input-number
				      v-model="form.parField"
				      controls-position="left"
				      :min="0"
				    />/元
		        </el-form-item>
				<el-form-item label="状态" prop="status" label-width="120px">
					 <template>
						<el-switch v-model="form.status"  active-value="1" inactive-value="0"></el-switch>
					 </template>
				</el-form-item>
		        <el-form-item label="备注" prop="remark" label-width="120px">
		          <el-input  type="textarea" v-model="form.remark" placeholder="请输入备注" />
		        </el-form-item>
		      </el-form>
		      <div slot="footer" class="dialog-footer">
		        <el-button type="primary" @click="submit" :loading="isSaveing">确 定</el-button>
		        <el-button  @click="visible=false" >取 消</el-button>
		      </div>
	</el-dialog>
</template>

<script>
import { addPar, updatePar } from "@/api/powerdistribution/par";	 
	export default {
		emits: ['success', 'closed'],
		dicts: ["pdm_maintenance_time"],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增配置',
					edit: '编辑配置'
				},
				visible: false,
				isSaveing: false,
				form: {
					id:'',  
					parCode:"",
					parName: "停电超时长",
					parValue: "",
					parUnit: "",
					parType: "2",
					remark: "",
					parField: 0,
					status: ""
				},
				rules: {
					parValue: [
						{required: true, message: '请输入值'}
					],
					parUnit: [
						{required: true, message: '请选择计量单位'}
					],
					parField: [
						{required: true, message: '请输入奖励'}
					],
				},
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res
						
						if(this.mode=="add")
						{
							addPar(this.form).then(response => {
						      this.$emit('success', this.form, this.mode)
							  this.$message.success("操作成功")
							  this.visible = false;
							});
						}else
						{
							updatePar(this.form).then(response => {
							   this.$message.success("操作成功")
							   this.$emit('success', this.form, this.mode)
							   this.visible = false;
							});
						}
						this.isSaveing = false;
						
					}
				})
			},
			//表单注入数据
			setData(data){
				Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
</style>
