<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="联锁总表id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="summaryid">
              <a-input v-model="model.summaryid" placeholder="请输入联锁总表id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockname">
              <a-input v-model="model.interlockname" placeholder="请输入联锁名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁条件值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockCondition">
              <a-input v-model="model.interlockCondition" placeholder="请输入联锁条件值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁条件点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockConditionTag">
              <a-input v-model="model.interlockConditionTag" placeholder="请输入联锁条件点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
              <a-input v-model="model.description" placeholder="请输入描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceId">
              <a-input v-model="model.deviceId" placeholder="请输入设备id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模块名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moduleName">
              <a-input v-model="model.moduleName" placeholder="请输入模块名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仪表状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatus">
              <a-input v-model="model.instrumentStatus" placeholder="请输入仪表状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仪表状态判断方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatusJuge">
              <j-dict-select-tag type="list" v-model="model.instrumentStatusJuge" dictCode="instrument_status_juge" placeholder="请选择仪表状态判断方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仪表状态点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatusTag">
              <a-input v-model="model.instrumentStatusTag" placeholder="请输入仪表状态点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="仪表状态值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentStatusValue">
              <a-input v-model="model.instrumentStatusValue" placeholder="请输入仪表状态值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原始模拟量位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ysmnlTag">
              <a-input v-model="model.ysmnlTag" placeholder="请输入原始模拟量位号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原始模拟量值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ysmnlValue">
              <a-input v-model="model.ysmnlValue" placeholder="请输入原始模拟量值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="高限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upperLimit">
              <a-input v-model="model.upperLimit" placeholder="请输入高限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="低限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lowerLimit">
              <a-input v-model="model.lowerLimit" placeholder="请输入低限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thresholdValue">
              <a-input v-model="model.thresholdValue" placeholder="请输入阈值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thresholdTime">
              <a-input v-model="model.thresholdTime" placeholder="请输入时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thresholdTimeUnit">
              <a-input v-model="model.thresholdTimeUnit" placeholder="请输入时间单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁设定值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockSetValue">
              <a-input v-model="model.interlockSetValue" placeholder="请输入联锁设定值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联锁设定值点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interlockSetTag">
              <a-input v-model="model.interlockSetTag" placeholder="请输入联锁设定值点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentValue">
              <a-input v-model="model.currentValue" placeholder="请输入当前值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前值位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentValueTag">
              <a-input v-model="model.currentValueTag" placeholder="请输入当前值位号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否旁路" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ifBypass">
              <a-input v-model="model.ifBypass" placeholder="请输入是否旁路"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="旁路状态点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ifBypassTag">
              <a-input v-model="model.ifBypassTag" placeholder="请输入旁路状态点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="输入卡件状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inputStatus">
              <a-input v-model="model.inputStatus" placeholder="请输入输入卡件状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="输入卡件状态点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inputStatusTag">
              <a-input v-model="model.inputStatusTag" placeholder="请输入输入卡件状态点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="输出卡件状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outputStatus">
              <a-input v-model="model.outputStatus" placeholder="请输入输出卡件状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="输出卡件状态点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outputStatusTag">
              <a-input v-model="model.outputStatusTag" placeholder="请输入输出卡件状态点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="MP状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpStatus">
              <a-input v-model="model.mpStatus" placeholder="请输入MP状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpStatusTag">
              <a-input v-model="model.mpStatusTag" placeholder="请输入状态点位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" 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: 'InterlockDetailForm',
    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: "/detail/interlockDetail/add",
          edit: "/detail/interlockDetail/edit",
          queryById: "/detail/interlockDetail/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>