zhang_nuo
7 天以前 d420578cb8bc076be2f0c7dd5a4dbfca335d7cdb
src/views/personnelManagement/employeeRecord/components/BasicInfoSection.vue
@@ -79,12 +79,14 @@
            placeholder="请选择"
            style="width: 100%"
            clearable
            @change="handleBirthDateChange"
          />
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="年龄" prop="age">
          <el-input-number
              disabled
            v-model="form.age"
            :min="0"
            :max="150"
@@ -158,6 +160,7 @@
<script setup>
import { toRefs } from "vue";
import dayjs from "dayjs";
const props = defineProps({
  form: { type: Object, required: true },
@@ -166,6 +169,21 @@
});
const { form, operationType, roleOptions } = toRefs(props);
const calcAge = (birth) => {
  if (!birth) return undefined;
  const birthDay = dayjs(birth);
  const now = dayjs();
  let age = now.year() - birthDay.year();
  if (now.month() < birthDay.month() || (now.month() === birthDay.month() && now.date() < birthDay.date())) {
    age--;
  }
  return age;
};
const handleBirthDateChange = (val) => {
  form.value.age = calcAge(val);
};
</script>
<style scoped>