<template>
  <div>
    <el-dialog :title="title" :visible.sync="isOpen" width="500px" append-to-body @close="cancel"
               :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="模型评价id" prop="id">
          <el-input v-model="form.id" placeholder="请输入模型评价id"/>
        </el-form-item>
        <el-form-item label="模型名称" prop="evaluateName">
          <el-input v-model="form.evaluateName" placeholder="请输入模型名称"/>
        </el-form-item>
        <el-form-item label="版本号" prop="evaluateVersion">
          <el-input v-model="form.evaluateVersion" placeholder="请输入版本号"/>
        </el-form-item>
        <el-form-item label="验证样本总数" prop="sampleAll">
          <el-input v-model="form.sampleAll" placeholder="请输入验证样本总数"/>
        </el-form-item>
        <el-form-item label="处理速度" prop="processSpeed">
          <el-input v-model="form.processSpeed" placeholder="请输入处理速度"/>
        </el-form-item>
        <el-form-item label="内存占用" prop="memoryUsage">
          <el-input v-model="form.memoryUsage" placeholder="请输入内存占用"/>
        </el-form-item>
        <el-form-item label="环境条件" prop="enviroConditions">
          <el-input v-model="form.enviroConditions" placeholder="请输入环境条件"/>
        </el-form-item>
        <el-form-item label="准确率" prop="accuracyRate">
          <el-input v-model="form.accuracyRate" placeholder="请输入准确率"/>
        </el-form-item>
        <el-form-item label="召回率" prop="recallRate">
          <el-input v-model="form.recallRate" placeholder="请输入召回率"/>
        </el-form-item>
        <el-form-item label="精确率" prop="accurateRate">
          <el-input v-model="form.accurateRate" placeholder="请输入精确率"/>
        </el-form-item>
        <el-form-item label="F1分数" prop="fGrade">
          <el-input v-model="form.fGrade" placeholder="请输入F1分数"/>
        </el-form-item>
        <el-form-item label="备注" prop="remart">
          <el-input v-model="form.remart" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="是否删除" prop="isActive">
          <el-input v-model="form.isActive" placeholder="请输入是否删除"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="uploading" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getEvaluate, addEvaluate, updateEvaluate } from '@/api/dataCenter/evaluate'

export default {
  props: {
    open: { type: Boolean, required: true },
    getList: { type: Function, required: true },
    title: { type: String, required: true },
    id: { type: [Number, null], default: 0 }
  },
  computed: {
    isOpen: {
      get() {
        return this.open
      },
      set(value) {
        this.$emit('dialog-cancel')
      }
    }
  },
  data() {
    return {
      form: {},
      rules: {}
    }
  },
  watch: {
    isOpen(newVal) {
      if (newVal) {
        if (this.id) {
          getEvaluate(this.id).then(response => {
            this.form = response.data
          })
        }
      }
    }
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEvaluate(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addEvaluate(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    cancel() {
      this.isOpen = false
      this.resetForm()
    },
    resetForm() {
      this.form = {}
    }
  }
}
</script>

<style scoped lang="scss"></style>
