| | |
| | | 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" |
| | |
| | | |
| | | <script setup> |
| | | import { toRefs } from "vue"; |
| | | import dayjs from "dayjs"; |
| | | |
| | | const props = defineProps({ |
| | | form: { type: Object, required: true }, |
| | |
| | | }); |
| | | |
| | | 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> |