<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="stationName">
              <a-input v-model="model.stationName" placeholder="请输入电站名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regionInfo">
              <a-input v-model="model.regionInfo" placeholder="请输入地区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city">
              <a-input v-model="model.city" placeholder="请输入城市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="调度编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dispatchNumber">
              <a-input v-model="model.dispatchNumber" placeholder="请输入调度编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="光照强度(w/m^2)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="irradiationLevel">
              <a-input v-model="model.irradiationLevel" placeholder="请输入光照强度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="装机容量(MW)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="capacity">
              <a-input v-model="model.capacity" placeholder="请输入装机容量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实时功率(kW)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dayPower">
              <a-input v-model="model.dayPower" placeholder="请输入实时功率"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总功率(kW)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalPower">
              <a-input v-model="model.totalPower" placeholder="请输入总功率"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当日电量(kWh)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dayElectricity">
              <a-input v-model="model.dayElectricity" placeholder="请输入当日电量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总电量(kWh)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalElectricity">
              <a-input v-model="model.totalElectricity" placeholder="请输入总电量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="安装角度(°)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="installAngle">
              <a-input v-model="model.installAngle" placeholder="请输入安装角度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="布线方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="assembleType">
              <a-input v-model="model.assembleType" placeholder="请输入布线方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="占地面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area">
              <a-input v-model="model.area" placeholder="请输入占地面积"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="海拔高度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="altitude">
              <a-input v-model="model.altitude" placeholder="请输入海拔高度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运行时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="runTime">
              <j-date placeholder="请选择运行时间"  v-model="model.runTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投产时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionTime">
              <j-date placeholder="请选择投产时间"  v-model="model.productionTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partitionInfo">
              <a-input v-model="model.partitionInfo" placeholder="请输入分区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="气象检测仪id，备用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meteorologicalInstrumentId">
              <a-input-number v-model="model.meteorologicalInstrumentId" placeholder="请输入气象检测仪id，备用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" 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: 'PowerStationInfoForm',
    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: "/station/powerStationInfo/add",
          edit: "/station/powerStationInfo/edit",
          queryById: "/station/powerStationInfo/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>