<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="900px" @close="close">
    <el-form ref="form" :model="form" :rules="rules">
    <el-row>
      <el-col :span="12">
        <el-form-item :disabled="!idAdd?true:false" label="id" prop="id"><el-input class="inputs" v-model.trim="form.id" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item   label="公司名称" prop="name"><el-input class="inputs" v-model.trim="form.name" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="别名" prop="aname"><el-input class="inputs" v-model.trim="form.aname" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="风电装机容量" prop="windcapacity"><el-input class="inputs" v-model.trim="form.windcapacity" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="风电容量单位" prop="windcapacityUnit"><el-input class="inputs" v-model.trim="form.windcapacityunit" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="风电装机数量" prop="windquantity"><el-input class="inputs" v-model.trim="form.windquantity" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="光伏装机容量" prop="capacity"><el-input class="inputs" v-model.trim="form.capacity" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="光伏容量单位" prop="capacityUnit"><el-input class="inputs" v-model.trim="form.capacityunit" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="光伏装机数量集中" prop="quantityjz"><el-input class="inputs" v-model.trim="form.quantityjz" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="光伏装机数量组串" prop="quantityzc"><el-input class="inputs" v-model.trim="form.quantityzc" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="接入风电装机容量2" prop="jrwindcapacity"><el-input class="inputs" v-model.trim="form.jrwindcapacity" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="接入风电容量单位2" prop="jrwindcapacityUnit"><el-input class="inputs" v-model.trim="form.jrwindcapacityunit" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="接入风电装机数量2" prop="jrwindquantity"><el-input class="inputs" v-model.trim="form.jrwindquantity" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="接入光伏装机容量2" prop="jrcapacity"><el-input class="inputs" v-model.trim="form.jrcapacity" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item  label="接入光伏容量单位2" prop="jrcapacityUnit"><el-input class="inputs" v-model.trim="form.jrcapacityunit" autocomplete="off"></el-input></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item  label="接入光伏装机数量集中" prop="jrquantityjz"><el-input class="inputs" v-model.trim="form.jrquantityjz" autocomplete="off"></el-input></el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12"><el-form-item  label="接入光伏装机数量组串" prop="jrquantityzc"><el-input class="inputs" v-model.trim="form.jrquantityzc" autocomplete="off"></el-input></el-form-item></el-col>
      <el-col :span="12"></el-col>
    </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import api from '@/api/station'
import axios from "axios";
export default {
  name: 'TableEdit',
  props: {
    options: {
      type: Array,
      default: []
    },
  },
  data() {
    return {
      form: {
        id: '',
        name: '',
        aname: '',
        windcapacity: '',
        windcapacityunit: '',
        windquantity: '',
        capacity: '',
        capacityunit: '',
        quantityjz: '',
        quantityzc: '',
        jrwindcapacity: '',
        jrwindcapacityunit: '',
        jrwindquantity: '',
        jrcapacity: '',
        jrcapacityunit: '',
        jrquantityjz: '',
        jrquantityzc: '',
      },
      rules: {
        id: [{ required: true, trigger: 'blur', message: '请输入' }],
        name: [{ required: true, trigger: 'blur', message: '请输入' }],
        aname: [{ required: true, trigger: 'blur', message: '请输入' }],
        windcapacity: [{ required: true, trigger: 'blur', message: '请输入' }],
        windcapacityunit: [{ required: true, trigger: 'blur', message: '请输入' }],
        windquantity: [{ required: true, trigger: 'blur', message: '请输入' }],
        capacity: [{ required: true, trigger: 'blur', message: '请输入' }],
        capacityunit: [{ required: true, trigger: 'blur', message: '请输入' }],
        quantityjz: [{ required: true, trigger: 'blur', message: '请输入' }],
        quantityzc: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrwindcapacity: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrwindcapacityunit: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrwindquantity: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrcapacity: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrcapacityunit: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrquantityjz: [{ required: true, trigger: 'blur', message: '请输入' }],
        jrquantityzc: [{ required: true, trigger: 'blur', message: '请输入' }],
      },
      title: '',
      dialogFormVisible: false,
      idAdd: true,
    }
  },
  created() { },
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '添加'
        this.idAdd = true
      } else {
        this.title = '编辑'
        this.idAdd = false
        this.form = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
      this.$emit('fetch-data')
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          api.addCompanys(this.form).then(res => {
            if (res.data) {
              this.$message({
                type: 'success',
                message: '添加成功!'
              });
              this.$emit('save-success');
              this.dialogFormVisible = false
            }
          })
        } else {
          return false
        }
      })
    },
    handleChange() {
    },
  },
}
</script>
<style lang="less" scoped>
.inputs {
  width: 200px;
}
</style>
