<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="编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">-->
<!--              <a-input-number v-model="model.code" placeholder="请输入编号" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="U相电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="udl">
              <a-input-number v-model="model.udl" placeholder="请输入U相电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="V相电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vdl">
              <a-input-number v-model="model.vdl" placeholder="请输入V相电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="W相电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wdl">
              <a-input-number v-model="model.wdl" placeholder="请输入W相电流" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="U相电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="udy">
              <a-input-number v-model="model.udy" placeholder="请输入U相电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="V相电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vdy">
              <a-input-number v-model="model.vdy" placeholder="请输入V相电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="W相电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wdy">
              <a-input-number v-model="model.wdy" placeholder="请输入W相电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="UV线电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="uvDy">
              <a-input-number v-model="model.uvDy" placeholder="请输入UV线电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="VW线电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vwDy">
              <a-input-number v-model="model.vwDy" placeholder="请输入VW线电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="WU线电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wuDy">
              <a-input-number v-model="model.wuDy" placeholder="请输入WU线电压" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="U相有功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activePowerU">
              <a-input-number v-model="model.activePowerU" placeholder="请输入U相有功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="V相有功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activePowerV">
              <a-input-number v-model="model.activePowerV" placeholder="请输入V相有功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="W相有功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activePowerW">
              <a-input-number v-model="model.activePowerW" placeholder="请输入W相有功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总有功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activePower">
              <a-input-number v-model="model.activePower" placeholder="请输入总有功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="U相无功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reactivePowerU">
              <a-input-number v-model="model.reactivePowerU" placeholder="请输入U相无功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="V相无功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reactivePowerV">
              <a-input-number v-model="model.reactivePowerV" placeholder="请输入V相无功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="W相无功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reactivePowerW">
              <a-input-number v-model="model.reactivePowerW" placeholder="请输入W相无功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="U功率因数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apparentPowerU">
              <a-input-number v-model="model.apparentPowerU" placeholder="请输入U功率因数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总无功功率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reactivePower">
              <a-input-number v-model="model.reactivePower" placeholder="请输入总无功功率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="U功率因数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="powerFactorU">
              <a-input-number v-model="model.powerFactorU" placeholder="请输入U功率因数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="V功率因数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="powerFactorV">
              <a-input-number v-model="model.powerFactorV" placeholder="请输入V功率因数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="W功率因数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="powerFactorW">
              <a-input-number v-model="model.powerFactorW" placeholder="请输入W功率因数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总功率因数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="powerFactor">
              <a-input-number v-model="model.powerFactor" placeholder="请输入总功率因数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="频率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="frequency">
              <a-input-number v-model="model.frequency" placeholder="请输入频率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="零序电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zeroCurrent">-->
<!--              <a-input-number v-model="model.zeroCurrent" placeholder="请输入零序电流" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="总电能" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eng">
              <a-input-number v-model="model.eng" placeholder="请输入总电能" 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: 'BuElectricForm',
    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: "/energy/buElectric/add",
          edit: "/energy/buElectric/edit",
          queryById: "/energy/buElectric/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>