evaluationContentEdit.vue 4.39 KB
<template>
  <div>
    <a-form-model ref="form" :model="formData" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item ref="name" label="评审内容名称" prop="name">
            <a-input v-model="formData.name" style="width:350px" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item ref="score" label="总分" prop="score">
            <a-input-number v-model="formData.score" :min="1" :max="100" @change="onScoreNumberChange" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item ref="showIndex" label="排序号" prop="showIndex">
            <a-input-number v-model="formData.showIndex" :min="1" :max="200" @change="onShowIndexNumberChange" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item ref="remark" label="备注" prop="remark">
            <a-textarea v-model="formData.remark" style="width:350px;" :rows="3" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24" style="text-align: center">
          <a-button type="primary" size="small" @click="submitEvaluateContent">提交</a-button>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>

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

export default {
  name: 'EvaluateContentEdit',
  props: {
    value: {
      type: String,
      default: () => {
        return null
      },
    },
    evaluationId: {
      type: String,
      default: () => {
        return null
      },
    },
    totalCount: {
      type: Number,
      default: () => {
        return 1
      },
    },
    totalScore: {
      type: Number,
      default: () => {
        return 0
      },
    },
    currentScore: {
      type: Number,
      default: () => {
        return 0
      },
    },
    editType: {
      type: String,
      default: () => {
        return 'edit'
      }
    }
  },
  data() {
    return {
      formData: {
        id: null,
        evaluationId: null, 
        name: '',
        score: 1,
        showIndex: 1,
        remark: ''
      },
      rules: {
        name: { required: true, message: '请填写评审内容名称', trigger: 'blur' },
        score: { required: true, message: '请填写评审内容分数', trigger: 'blur' },
        showIndex: { required: true, message: '请填写评审内容排序号', trigger: 'blur' },
        remark: { required: false },
      }
    }
  },
  created() {
    if (this.editType === 'add') {
      this.formData = {
        id: null,
        evaluationId: null,
        name: '',
        score: 1,
        showIndex: this.totalCount,
        hasSubitem: false,
        valueType: 1,
        remark: ''
      }
    } else {
      this.getEvaluationContentById()
    }
  },
  methods: {
    getEvaluationContentById() {
      let par = { id: this.value }
      this.$api.systemManage.getEvaluationContentById(par).then(({ data = {} }) => {
        if (data) {
          this.formData = data
        }
      }).catch(() => {})
    },
    onScoreNumberChange(value) {
      this.formData.score = value
    },
    onShowIndexNumberChange(value) {
      this.formData.showIndex = value
    },
    calculateTotalScore() {
      this.formData.score + this.totalScore
    },
    submitEvaluateContent() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.editType === 'add') {
            this.formData.evaluationId = this.evaluationId
            let pars = isEmptyParams(this.formData)
            let par = { ...pars }
            this.$api.systemManage.insertEvaluationContent(par).then(({ data = {} }) => {
              if (data) {
                this.$message.info(data)
                this.$emit('close')
              }
            }).catch(() => {})
          } else {
            let pars = isEmptyParams(this.formData)
            let par = { ...pars }
            this.$api.systemManage.updateEvaluationContent(par).then(({ data = {} }) => {
              if (data) {
                this.$message.info(data)
                this.$emit('close')
              }
            }).catch(() => {})
          }
        }
      })
    }
  }
}
</script>