evaluationEdit.vue 3.49 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="onSNumberChange" />
          </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="submitEvaluate">提交</a-button>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>

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

export default {
  name: 'EvaluateEdit',
  props: {
    value: {
      type: String,
      default: () => {
        return null
      },
    },
    editType: {
      type: String,
      default: () => {
        return 'edit'
      }
    }
  },
  data() {
    return {
      formData: {
        id: null,
        name: null,
        score: 1,
        remark: ''
      },
      rules: {
        score: { required: true, message: '请填写评审总分', trigger: 'blur' },
        name: { required: true, message: '请填写评审表名称', trigger: 'blur' },
        remark: { required: false },
      },
    };
  },
  created() {
    if (this.editType === 'add') {
      this.formData = {
        id: null,
        name: null,
        score: 1,
        remark: ''
      }
    } else {
      this.getEvaluationById()
    }
  },
  methods: {
    moment,
    getEvaluationById() {
      let par = { id: this.value }
      this.$api.systemManage.getEvaluationById(par).then(({ data = {} }) => {
        if (data) {
          this.formData = data
          //this.formData.evalRange = [data.startTime, data.endTime]
        }
      }).catch(() => {})
    },
    onSNumberChange(value) {
      this.formData.batchId = value
    },
    submitEvaluate() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.editType === 'add') {
            let pars = isEmptyParams(this.formData)
            let par = { ...pars }
            this.$api.systemManage.insertEvaluation(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.updateEvaluation(par).then(({ data = {} }) => {
              if (data) {
                this.$message.info(data)
                this.$emit('close')
              }
            }).catch(() => {})
          }
        }
      })
    },
    evalDateChange(dates, dateStrings) {
      if (dateStrings[0] != '' && dateStrings[1] != '') {
        this.formData.startTime = dateStrings[0]
        this.formData.endTime = dateStrings[1]
      }
    },
  }
};
</script>