<template>
  <div class="rule-type">
    <DialogCom
      title="告警处置"
      :visible.sync="isShow"
      @close="onHide"
      width="800px"
    >
      <div class="page-body">
        <el-descriptions class="margin-top" :column="2" size="medium" border :label-style="labelStyle" :contentStyle="content_style">
        <el-descriptions-item labelClassName="gx_info_label" label="机构名称">
          {{alarmData.orgName}}
        </el-descriptions-item>
        <el-descriptions-item labelClassName="gx_info_label" label="告警分类" >
          {{dataTypeText()}}
        </el-descriptions-item>
        <el-descriptions-item labelClassName="gx_info_label" label="告警类型" >
          {{alarmData.sourceTypeDes}}
        </el-descriptions-item>
        <el-descriptions-item labelClassName="gx_info_label" label="告警开始时间" >
          {{alarmData.time}}
        </el-descriptions-item>          
        <el-descriptions-item labelClassName="gx_info_label" label="告警结束时间" >
          {{alarmData.endTime}}
        </el-descriptions-item>
        <el-descriptions-item labelClassName="gx_info_label" label="告警值" >
          {{valueText()}}
        </el-descriptions-item>
        <el-descriptions-item labelClassName="gx_info_label" label="告警内容" >
          {{alarmData.content}}
        </el-descriptions-item>
      </el-descriptions>
        <el-form
          :model="formData"
          :rules="formDataRules"
          size="small"
          ref="form"
          label-position="right"
          label-width="150px"
          label-prefix=":"
        >
          <!-- <el-form-item label="所属机构" prop="orgId">         
            {{formData.orgName}} 
          </el-form-item> -->
          <el-form-item label="处置类型" prop="doType">
            <el-select
              label="处置类型"
              v-model="formData.doType"
              placeholder="请选择告警处置类型"
              clearable
              style="width: 100%;"
            >
            <el-option
                    v-for="dict in dict.type.alarm_deal_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                  ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="doContent" label="处置内容:">
            <el-input
              v-model="formData.doContent"
              :maxlength="50"
              name="doContent"
              placeholder="请输入处置内容"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSubmit">确定</el-button>
        <el-button @click="isShow = false">取消</el-button>
      </div>
    </DialogCom>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from "vuex";
import {detail,dealAlarm} from "@/api/iot/alarmRule";
import { listIdName } from "@/api/system/device";
export default {
  dicts: ["alarm_deal_type"],
  data() {
    return {
      id: null,
      isShow: false,
      alarmData:null,
      formData: this.reset(),
      formDataRules: {
        doType: [{ required: true, message: "请选择处置类型" }],
        doContent: [{ required: true, message: "请输入处置内容" }],
      },
    };
  },
  props: {},
  watch: {
    // "formData.orgId":{
    //   handler(v){
    //     console.info("formData.orgId",v)
    //   }
    // }
  },
  computed: {
    ...mapGetters(["orgId"]),
  },
  methods: {
    ...mapMutations([]),
    reset() {
      return {
        id: null,
        doType:null,
        doContent:null,
      };
    },
    async refresh(id, other) {
      this.alarmData = id ? (await detail(id)).data : this.reset(other);
      this.formData.id=id;
    },
    async show(id, other = {}) {
      this.id = id;
      await this.refresh(id, other);
      this.isShow = true;
    },
    valueText() {
        if (!this.alarmData || this.alarmData.valueText == null) {
          return ''
        }
        return `${this.alarmData.valueText}${this.alarmData.alarmValue ? this.alarmData.alarmValue : ''}`
      },
    dataTypeText() {
      if (!this.alarmData || this.alarmData.dataType == null) {
        return ''
      }

      if (this.alarmData.dataType == '0') {
        return '动环类告警'
      } else if (this.alarmData.dataType == '1') {
        return '视频类告警'
      } else {
        return '未知'
      }
    },
    // 事件
    onHide() {
      this.$refs.form.resetFields();
      this.formData = this.reset();
    },
    onSubmit() {
      this.$refs.form.validate(async (isValidate) => {
        if (!isValidate) return;
        await dealAlarm(this.formData);
        this.$emit("success");
        this.isShow = false;
      });
    },
  },
  created() {},
  mounted() {},
  components: { },
};
</script>

<style lang="scss" scoped>
.brand_info {
  .el-form {
    width: 600px;
    padding-top: 40px;
  }
}
</style>
