<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="serverName">
              <a-input v-model="model.serverName" placeholder="请输入上传服务器名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="传感器ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sensorId">
              <a-input v-model="model.sensorId" placeholder="请输入传感器ID"  ></a-input>
            </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="请输入状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警字段名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="statusname">
              <a-textarea v-model="model.statusname" rows="4" placeholder="请输入报警字段名" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="采集时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="acqTime">
              <a-input v-model="model.acqTime" placeholder="请输入采集时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="emCode">
              <a-input v-model="model.emCode" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运行状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="emRunState">
              <a-input-number v-model="model.emRunState" placeholder="请输入运行状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="emErrorCode">
              <a-input v-model="model.emErrorCode" placeholder="请输入故障信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="接触网电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="catenaryvoltage">
              <a-input-number v-model="model.catenaryvoltage" placeholder="请输入接触网电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引蓄电池电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tractionbatteryvoltage">
              <a-input-number v-model="model.tractionbatteryvoltage" placeholder="请输入牵引蓄电池电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="traction">
              <a-input-number v-model="model.traction" placeholder="请输入牵引力" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制动力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brakingforce">
              <a-input-number v-model="model.brakingforce" placeholder="请输入制动力" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="speedperhour">
              <a-input-number v-model="model.speedperhour" placeholder="请输入时速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="均衡风缸风压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equalizingreservoirairpressure">
              <a-input-number v-model="model.equalizingreservoirairpressure" placeholder="请输入均衡风缸风压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="里程数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mileage">
              <a-input-number v-model="model.mileage" placeholder="请输入里程数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架1中间直流—电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bogieintermediatecurrent1">
              <a-input-number v-model="model.bogieintermediatecurrent1" placeholder="请输入转向架1中间直流—电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架1中间直流—电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bogieintermediatevoltage1">
              <a-input-number v-model="model.bogieintermediatevoltage1" placeholder="请输入转向架1中间直流—电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架2中间直流—电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bogieintermediatecurrent2">
              <a-input-number v-model="model.bogieintermediatecurrent2" placeholder="请输入转向架2中间直流—电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架2中间直流—电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bogieintermediatevoltage2">
              <a-input-number v-model="model.bogieintermediatevoltage2" placeholder="请输入转向架2中间直流—电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引蓄电池充电机—电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tractionbatterymotorvoltage">
              <a-input-number v-model="model.tractionbatterymotorvoltage" placeholder="请输入牵引蓄电池充电机—电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引蓄电池充电机—电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tractionbatterymotorcurrent">
              <a-input-number v-model="model.tractionbatterymotorcurrent" placeholder="请输入牵引蓄电池充电机—电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机1温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureoftractionmotor1">
              <a-input-number v-model="model.temperatureoftractionmotor1" placeholder="请输入牵引电机1温度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机1转速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="speedoftractionmotor1">
              <a-input-number v-model="model.speedoftractionmotor1" placeholder="请输入牵引电机1转速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机2温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureoftractionmotor2">
              <a-input-number v-model="model.temperatureoftractionmotor2" placeholder="请输入牵引电机2温度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机2转速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="speedoftractionmotor2">
              <a-input-number v-model="model.speedoftractionmotor2" placeholder="请输入牵引电机2转速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机3温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureoftractionmotor3">
              <a-input-number v-model="model.temperatureoftractionmotor3" placeholder="请输入牵引电机3温度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机3转速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="speedoftractionmotor3">
              <a-input-number v-model="model.speedoftractionmotor3" placeholder="请输入牵引电机3转速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机4温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureoftractionmotor4">
              <a-input-number v-model="model.temperatureoftractionmotor4" placeholder="请输入牵引电机4温度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引电机4转速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="speedoftractionmotor4">
              <a-input-number v-model="model.speedoftractionmotor4" placeholder="请输入牵引电机4转速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="牵引蓄电池温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tractionbatterytemperature">
              <a-input-number v-model="model.tractionbatterytemperature" placeholder="请输入牵引蓄电池温度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架1实际力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualforceofbogie1">
              <a-input-number v-model="model.actualforceofbogie1" placeholder="请输入转向架1实际力" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转向架2实际力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualforceofbogie2">
              <a-input-number v-model="model.actualforceofbogie2" placeholder="请输入转向架2实际力" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="充电状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chargestate">
              <a-input-number v-model="model.chargestate" placeholder="请输入充电状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池输入电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batteryinputvoltage">
              <a-input-number v-model="model.batteryinputvoltage" placeholder="请输入蓄电池输入电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池输出电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batteryoutputvoltage">
              <a-input-number v-model="model.batteryoutputvoltage" placeholder="请输入蓄电池输出电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池输出总电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totaloutputcurrentofbattery">
              <a-input-number v-model="model.totaloutputcurrentofbattery" placeholder="请输入蓄电池输出总电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池充电电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batterychargecurrent">
              <a-input-number v-model="model.batterychargecurrent" placeholder="请输入蓄电池充电电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池温度1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureofbattery1">
              <a-input-number v-model="model.temperatureofbattery1" placeholder="请输入蓄电池温度1" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蓄电池温度2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureofbattery2">
              <a-input-number v-model="model.temperatureofbattery2" placeholder="请输入蓄电池温度2" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间戳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ts">
              <j-date placeholder="请选择时间戳" v-model="model.ts"  style="width: 100%" />
            </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: 'BuZyXdcgccOnlineForm',
    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: "/xudiancgcc/buZyXdcgccOnline/add",
          edit: "/xudiancgcc/buZyXdcgccOnline/edit",
          queryById: "/xudiancgcc/buZyXdcgccOnline/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>