<template>
  <el-dialog title="处置" :visible.sync="dealOpen" width="500px" append-to-body destroy-on-close :close-on-click-modal="false">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="报警原因" prop="reason">
        <el-select
          v-model="form.reason"
          placeholder="请选择处置原因"
          style="width: 100%"
        >
          <el-option
            v-for="dict in $parent.reasonOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="parseInt(dict.dictValue)"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="处置结果" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { getAlarm, updateAlarm, } from "@/api/gasdata/alarm";
  export default {
    name: "deal",
    data(){
        return{
          dealOpen: false,
          rules:{
            reason: [
              { required: true, message: "请选择处置原因", trigger: "change" }
            ],
            remark: [
              { required: true, message: "处置结果不能为空", trigger: "blur" }
            ],
          },
          form:{
            reason: null,
            remark: null
          }
        }
    },
    methods:{
      openDeal(id){
        this.form.id = id;
        this.getDealInfo(id);
      },
      getDealInfo(id){
        getAlarm(id).then(res =>{
          if(res.code == 200){
            this.form.reason = res.data.reason == 0 ? null : res.data.reason ;
            this.form.number = res.data.number;
            this.form.type = res.data.type;
            this.form.remark = res.data.remark;
            this.dealOpen = true;
          }
        })
      },
      submitForm(){
        this.$refs["form"].validate(valid => {
          if (valid) {
            updateAlarm(this.form).then(response => {
              this.msgSuccess("处置成功");
              this.dealOpen = false;
              this.$parent.getList();
            });
          }
        });
      },
      cancel(){
        this.dealOpen = false;
        this.resetForm("form");
      },
    }
  }
</script>

<style scoped>

</style>
