<template>
  <div>
    <a-form-model ref="form" :model="formData" :rules="rules" class="from-table">
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div>项目名称</div>
        </a-col>
        <a-col :span="20">
          {{formData.projName}}
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div>项目编号</div>
        </a-col>
        <a-col :span="20">
          {{formData.projNo}}
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div class="required">评分</div>
        </a-col>
        <a-col :span="20">
          <a-form-model-item ref="gradeScore" prop="gradeScore">
            <a-input-number v-model="formData.gradeScore" :min="1" :max="100" @change="scoreChange" style="width: 100px" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div>备注</div>
        </a-col>
        <a-col :span="20">
          <a-form-model-item ref="remark" prop="remark">
            <a-input v-model="formData.remark" style="width: 80%" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="24" style="text-align:center;">
          <a-button type="primary" size="small" @click="submit">提交</a-button>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>

<script>
import { isEmptyParams } from "@/views/utils/common"

export default {
  name: "evaluationView",
  props: {
    value: {
      type: String,
      default: () => {
        return null;
      },
    },
  },
  data () {
    return {
      formData: { id: null, projId: null, expertId: null, expertName: "", gradeScore: 0, remark: "", projName: "", projNo: "", },
      rules: {
        gradeScore: { required: true, message: '请填写评分', trigger: 'blur' },
        remark: { required: false, message: '' }
      },
    };
  },
  created () {
    this.getAssignExpertById()
  },
  computed: {
    gradeScoreVal () {
      return function (value) {
        if (value == null) return "未评分"
        else return value
      };
    },
  },
  methods: {
    getAssignExpertById () {
      let pars = { id: this.value }
      this.$api.projectAssign.getAssignExpertById(pars).then(({ data = {} }) => {
        if (data) {
          this.formData = data
        }
      }).catch(() => { })
    },
    scoreChange (value) {
      this.formData.gradeScore = value
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          let pars = isEmptyParams(this.formData)
          let par = { ...pars }
          this.$api.projectAssign.expertEvaluation(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('提交成功')
              this.$emit('close')
            } else
              this.$message.success('提交失败，请稍后再试！')
          }).catch(() => {
            this.$message.success('提交失败，请稍后再试！')
          })
        }
      })
    },
  },
};
</script>
