<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="800px" @close="close">
    <el-form ref="form" :model="form" :rules="rules" label-width="170px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="编码" prop="id"><el-input placeholder="请输入" :disabled="idAdd" 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="companyid"><el-input placeholder="请输入" class="inputs" v-model.trim="form.companyid" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="名称" prop="name"><el-input placeholder="请输入"class="inputs" v-model.trim="form.name" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="别名" prop="aname"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.windcapacity" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="风电容量单位" prop="windcapacityunit"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.windquantity" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="光伏装机容量" prop="capacity"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.capacityunit" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="光伏装机数量集中" prop="quantityjz"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.quantityzc" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="接入风电装机容量2" prop="jrwindcapacity"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.jrwindcapacityunit" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="接入风电装机数量2" prop="jrwindquantity"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.jrcapacity" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="接入光伏容量单位2" prop="jrcapacityunit"><el-input placeholder="请输入" 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 placeholder="请输入" class="inputs" v-model.trim="form.jrquantityjz" autocomplete="off"></el-input></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="接入光伏装机数量组串" prop="jrquantityzc"><el-input placeholder="请输入" class="inputs" v-model.trim="form.jrquantityzc" autocomplete="off"></el-input></el-form-item>
        </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'
export default {
  name: 'TableEdit',
  props: {
    options: {
      type: Array,
      default: []
    },
  },
  data() {
    return {
      form: {
        id: '',
        companyid:'',
        name:'',
        aname:'',
        windcapacity:'',
        windcapacityunit:'',
        windquantity:'',
        capacity:'',
        capacityunit:'',
        quantityjz:'',
        quantityzc:'',
        jrwindcapacity:'',
        jrwindcapacityunit:'',
        jrwindquantity:'',
        jrcapacity:'',
        jrcapacityunit:'',
        jrquantityjz:'',
        jrquantityzc:'',
      },
      rules: {
        id: [{ required: true, trigger: 'blur', message: '请输入' }],
        companyid: [{ 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 = false
      } else {
        this.title = '编辑'
        this.idAdd = true
        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) {
          if(this.title === "添加"){
            api.addSave(this.form).then(res => {
              if (res.data) {
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.$emit('save-success');
                this.dialogFormVisible = false
              }
            })
          } else {
            api.editSave(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>
