<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="800px" @close="close">
    <el-form ref="form" :model="form" :rules="rules"  label-width="80px">
      <el-form-item label="编码" prop="code">
        <el-input placeholder="请输入" class="inputs" v-model.trim="form.code" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input placeholder="请输入" class="inputs" v-model.trim="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-input placeholder="请输入" class="inputs" v-model.trim="form.model" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="统一编码" prop="uniformcode">
        <el-input placeholder="请输入" class="inputs" v-model.trim="form.uniformcode" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="场站编号" prop="windpowerstationid">
        <el-input placeholder="请输入" class="inputs" v-model.trim="form.windpowerstationid" autocomplete="off"></el-input>
      </el-form-item>
      <!-- <el-form-item label="类型" prop="type">
        <el-select class="inputs" v-model="form.type" placeholder="请选择">
          <el-option
            v-for="item in typeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item> -->
    </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/pointConfiguration'
import axios from "axios";
export default {
  name: 'TableEdit',
  props: {
    options: {
      type: Array,
      default: []
    },
  },
  data() {
    return {
      typeOptions: [
        {value: '风机计算', label:'风机计算'},
        {value: '场站计算', label:'场站计算'},
        {value: '风机基础点', label:'风机基础点'},
      ],
      form: {
        id: '',
        code: '',
        name: '',
        model: '',
        uniformcode: '',
        windpowerstationid: '',
      },
      rules: {
        code: [{ required: true, trigger: 'blur', message: '请输入' }],
        name: [{ required: true, trigger: 'blur', message: '请输入' }],
        model: [{ required: true, trigger: 'blur', message: '请输入' }],
        uniformcode: [{ required: true, trigger: 'blur', message: '请输入' }],
        windpowerstationid: [{ 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.addWindturbinetestingpointnew(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>
