<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="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="设备id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentid">
              <a-input v-model="model.equipmentid" placeholder="请输入设备id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alarmtime">
              <j-date placeholder="请选择报警时间" v-model="model.alarmtime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警类型：0通讯状态，1现场报警，2设备故障，3消防报警，4环境报警，5安全报警" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alarmtype">
              <a-input v-model="model.alarmtype" placeholder="请输入报警类型：0通讯状态，1现场报警，2设备故障，3消防报警，4环境报警，5安全报警"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警等级：0普通，1严重，2事故" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alarmlevel">
              <a-input v-model="model.alarmlevel" placeholder="请输入报警等级：0普通，1严重，2事故"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgcode">
              <a-input v-model="model.msgcode" placeholder="请输入消息码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参数编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paramcode">
              <a-input v-model="model.paramcode" placeholder="请输入参数编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参数名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paramname">
              <a-input v-model="model.paramname" placeholder="请输入参数名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nowvalue">
              <a-input-number v-model="model.nowvalue" placeholder="请输入当前值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阈值最小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vmin">
              <a-input-number v-model="model.vmin" placeholder="请输入阈值最小值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阈值最大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vmax">
              <a-input-number v-model="model.vmax" placeholder="请输入阈值最大值" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="处理人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleuser">
              <j-dict-select-tag v-model="model.handleuser" placeholder="请选择处理人" dictCode="sys_user,realname,id"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handletime">
              <j-date placeholder="请选择处理日期" showTime dateFormat="YYYY-MM-DD HH:mm:ss" v-model="model.handletime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <!-- <a-input-number v-model="model.status" placeholder="请输入状态：0待处理，1处理中，2已处理" style="width: 100%" /> -->
              <a-radio-group v-model="model.status">
                <a-radio :value="1">
                  处理中
                </a-radio>
                <a-radio :value="2">
                  已处理
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col> 
          <a-col :span="24">
            <a-form-model-item label="处理信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleremark">
              <a-textarea v-model="model.handleremark" placeholder="请输入处理信息" :auto-size="{ minRows: 2, maxRows: 3 }"></a-textarea>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="图片地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="url">
              <a-input v-model="model.url" placeholder="请输入图片地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="距离(摄像头用)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="distance">
              <a-input-number v-model="model.distance" placeholder="请输入距离(摄像头用)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方位(摄像头用)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="position">
              <a-input-number v-model="model.position" placeholder="请输入方位(摄像头用)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属年" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input-number v-model="model.year" placeholder="请输入所属年" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input-number v-model="model.month" placeholder="请输入所属月" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属周" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="week">
              <a-input-number v-model="model.week" placeholder="请输入所属周" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="day">
              <a-input v-model="model.day" placeholder="请输入日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="周几" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dayofweek">
              <a-input-number v-model="model.dayofweek" placeholder="请输入周几" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属年月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yearmonth">
              <a-input v-model="model.yearmonth" placeholder="请输入所属年月"  ></a-input>
            </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: 'MessageAlarmForm',
    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: {
           equipmentid: [
              { required: true, message: '请输入设备id!'},
           ],
           alarmtime: [
              { required: true, message: '请输入报警时间!'},
           ],
        },
        url: {
          add: "/tpmMessageAlarm/tpmMessageAlarm/add",
          edit: "/tpmMessageAlarm/tpmMessageAlarm/edit",
          queryById: "/tpmMessageAlarm/tpmMessageAlarm/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>