• wangxl's avatar
    555 · fa609b49
    wangxl authored
    fa609b49
personEdit.vue 4.97 KB
<template>
  <div>
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <a-form-model ref="form" :model="formData" :rules="rules" class="from-table">
        <a-row>
          <a-col :span="4" class="bg-gray">
            <div class="required">证件号</div>
          </a-col>
          <a-col :span="20">
            <a-form-model-item ref="certId" prop="certId">
              {{formData.certId}}
              <!-- <a-input v-model="formData.certId" @blur="() => { $refs.certId.onFieldBlur();}" disabled style="width: 180px" /> -->
            </a-form-model-item>
          </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="personName" prop="personName">
              <a-input v-model="formData.personName" @blur="() => {$refs.personName.onFieldBlur(); }" style="width: 180px" />
            </a-form-model-item>
          </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="email" prop="email">
              <a-input v-model="formData.email" @blur="() => {$refs.email.onFieldBlur();}" style="width: 180px" />
            </a-form-model-item>
          </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="education" prop="education">
              <para-select v-model="formData.education" :typeId="8" :width="180" />
            </a-form-model-item>
          </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="title" prop="title" :label-col="{ span: 3 }" :wrapper-col="{ span: 21 }">
              <para-multi-select v-model="formData.title" :typeId="7" />
            </a-form-model-item>
          </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="spec" prop="spec" >
              <cascader-select v-model="formData.spec" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24" style="text-align:center;">
            <a-button type="primary" style="margin-right:50px;" @click="submit">保存</a-button>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </div>
</template>

<script>
import { isEmptyParams, getCardInfo } from "@/views/utils/common"
import { isIdentityId } from '@/views/utils/validate'
import moment from 'moment'
import cascaderSelect from '@/views/components/common/cascaderSelect'


export default {
  name: "personEdit",
  components: {
    cascaderSelect
  },
  data () {
    return {
      formData: {
        id: null, certId: null, sex: null, birthday: null, mobile: null, email: null, title: null, unitId: null, education: null, spec: null, address: null
      },
      rules: {
        personName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
        title: [{ required: true, message: '请选择职称', trigger: 'change' }],
        unitId: [{ required: true, message: '请选择单位', trigger: 'change' }],
        education: [{ required: true, message: '请选择学历', trigger: 'change' }],
        spec: [{ required: true, message: '请选择专业', trigger: 'change' }],
      },
      loading: false,
    }
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    },
    obj: {
      type: Object
    }
  },
  created () {
    this.getPersonById()
  },
  methods: {
    moment,
    getPersonById () {
      this.loading = true
      this.$api.person.getPersonById({ id: this.value }).then(({ data = {} }) => {
        if (data) {
          this.formData = data
        }
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    onBirthdayChange (date, dateString) {
      this.formData.birthday = dateString;
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          let pars = isEmptyParams(this.formData)
          let par = { ...pars }
          this.$api.person.updatePerson(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('成功!')
              this.$emit('close', 'edit')
            }
            this.loading = false
          }).catch(() => { this.loading = false })
        } else {
          this.$message.info('信息未填写完整!')
          return false
        }
      })
    }
  }
}
</script>