<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="事件类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventCategory">
              <a-input v-model="model.eventCategory" placeholder="事件类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="唯一标识一次发生的事件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logId">
              <a-input v-model="model.logId" placeholder="请输入唯一标识一次发生的事件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="0：瞬时事件，保存；1：事件开始，
保存；2：事件结束，更新结束时间； 3：事件脉冲，客户端和服务器使用，
CMS 不用；4：事件更新，联动结果更
新" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventState">
              <a-input-number v-model="model.eventState" placeholder="请输入0：瞬时事件，保存；1：事件开始，
保存；2：事件结束，更新结束时间； 3：事件脉冲，客户端和服务器使用，
CMS 不用；4：事件更新，联动结果更
新" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="0：普通事件；1：低级报警；2：中级
报警；3：高级报警" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventLevel">
              <a-input-number v-model="model.eventLevel" placeholder="请输入0：普通事件；1：低级报警；2：中级
报警；3：高级报警" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="控制中心编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitIdx">
              <a-input v-model="model.unitIdx" placeholder="请输入控制中心编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventType">
              <a-input-number v-model="model.eventType" placeholder="请输入事件类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件类型名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventTypeName">
              <a-input v-model="model.eventTypeName" placeholder="请输入事件类型名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件所属子系统类型.废弃，事件整改，没有子系统属性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subSysType">
              <a-input-number v-model="model.subSysType" placeholder="请输入事件所属子系统类型.废弃，事件整改，没有子系统属性" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventName">
              <a-input v-model="model.eventName" placeholder="请输入事件名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <j-date placeholder="请选择事件开始时间" v-model="model.startTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stopTime">
              <j-date placeholder="请选择事件结束时间" v-model="model.stopTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件源编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceIdx">
              <a-input v-model="model.sourceIdx" placeholder="请输入事件源编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件源类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceType">
              <a-input-number v-model="model.sourceType" placeholder="请输入事件源类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件源名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceName">
              <a-input v-model="model.sourceName" placeholder="请输入事件源名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件描述信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logTxt">
              <a-textarea v-model="model.logTxt" rows="4" placeholder="请输入事件描述信息" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件源区域编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regionIdx">
              <a-input v-model="model.regionIdx" placeholder="请输入事件源区域编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件拓展信息:
各个子系统根据子系统的消息结构体
定义解析,下文主要介绍事件中此字
段含义" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="extInfo">
              <a-textarea v-model="model.extInfo" rows="4" placeholder="请输入事件拓展信息:
各个子系统根据子系统的消息结构体
定义解析,下文主要介绍事件中此字
段含义" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事件处理结果:当 event_state 为更新时使用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rsltMsg">
              <a-textarea v-model="model.rsltMsg" rows="4" placeholder="请输入事件处理结果:当 event_state 为更新时使用" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联动信息:目前包含客户端联动、预
案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trigInfo">
              <a-textarea v-model="model.trigInfo" rows="4" placeholder="请输入联动信息:目前包含客户端联动、预
案" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'PmEventInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/pm/pmEventInfo/add",
          edit: "/pm/pmEventInfo/edit",
          queryById: "/pm/pmEventInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>