feat(personnel,production): 新增年龄自动计算及工单数量支持小数
- 员工档案模块新增年龄根据出生日期自动计算功能,涉及列表
展示、新增/编辑表单、基本信息组件,年龄字段设为只读
- 统一各组件的年龄计算逻辑,基于 dayjs 实现周岁计算
- 调整员工档案列表页代码缩进格式,移除调试日志
- 工单管理模块生产合格数量和报废数量支持三位小数输入,
移除整数校验及取整逻辑,适配小数业务场景
| | |
| | | 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> |
| | |
| | | onMounted, |
| | | getCurrentInstance, |
| | | nextTick, |
| | | computed, |
| | | } from "vue"; |
| | | import dayjs from "dayjs"; |
| | | import FormDialog from "@/components/Dialog/FormDialog.vue"; |
| | | import { findPostOptions } from "@/api/system/post.js"; |
| | | import { deptTreeSelect, getUser } from "@/api/system/user.js"; |
| | |
| | | const { form, rules, postOptions, deptOptions } = toRefs(state); |
| | | const roleOptions = ref([]); |
| | | |
| | | 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 resetForm = () => { |
| | | Object.assign(form.value, createDefaultForm()); |
| | | nextTick(() => { |
| | |
| | | if (form.value.sysDeptId === 0) { |
| | | form.value.sysDeptId = undefined; |
| | | } |
| | | form.value.age = calcAge(form.value.birthDate); |
| | | }); |
| | | } |
| | | }; |
| | |
| | | <template #positiveDate="{ row }"> |
| | | <span :class="getPositiveDateClass(row.positiveDate)">{{ row.positiveDate }}</span> |
| | | </template> |
| | | <template #age="{ row }"> |
| | | <span>{{ calcAge(row.birthDate) }}</span> |
| | | </template> |
| | | </PIMTable> |
| | | </div> |
| | | <show-form-dia ref="formDia" @close="handleQuery"></show-form-dia> |
| | |
| | | |
| | | <script setup> |
| | | import { Search, UploadFilled } from "@element-plus/icons-vue"; |
| | | import {onMounted, ref} from "vue"; |
| | | import {onMounted, ref, reactive, toRefs, nextTick, getCurrentInstance} from "vue"; |
| | | import {ElMessageBox} from "element-plus"; |
| | | import { deptTreeSelect } from "@/api/system/user.js"; |
| | | import {batchDeleteStaffOnJobs, staffOnJobListPage} from "@/api/personnelManagement/staffOnJob.js"; |
| | |
| | | const data = reactive({ |
| | | searchForm: { |
| | | staffName: "", |
| | | sysDeptId: undefined, |
| | | contractStartTime: undefined, |
| | | entryDate: undefined, // 录入日期 |
| | | entryDateStart: undefined, |
| | | entryDateEnd: undefined, |
| | |
| | | { |
| | | label: "年龄", |
| | | prop: "age", |
| | | dataType: "slot", |
| | | slot: "age" |
| | | }, |
| | | { |
| | | label: "籍贯", |
| | |
| | | url: import.meta.env.VITE_APP_BASE_API + "/staff/staffOnJob/import" |
| | | }) |
| | | |
| | | /** |
| | | * 根据出生日期字符串计算周岁 |
| | | * @param {String} birth YYYY‑MM‑DD |
| | | * @returns {string|number} |
| | | */ |
| | | const calcAge = (birth) => { |
| | | if (!birth) return "-"; |
| | | 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; |
| | | }; |
| | | |
| | | // 判断转正日期是否在7天内 |
| | | const getPositiveDateClass = (positiveDate) => { |
| | | if (!positiveDate) return ''; |
| | |
| | | |
| | | const fetchDeptOptions = () => { |
| | | deptTreeSelect().then(response => { |
| | | console.log(response.data) |
| | | deptOptions.value = filterDisabledDept( |
| | | JSON.parse(JSON.stringify(response.data)) |
| | | ); |
| | |
| | | <el-input v-model.number="reportForm.quantity" |
| | | type="number" |
| | | min="0" |
| | | step="1" |
| | | step="0.001" |
| | | style="width: 300px" |
| | | placeholder="请输入生产合格数量" |
| | | @input="handleQuantityInput" /> |
| | |
| | | } |
| | | const num = Number(value); |
| | | // 整数且大于等于1 |
| | | if (isNaN(num) || !Number.isInteger(num) || num < 0) { |
| | | if (isNaN(num) || num < 0) { |
| | | callback(new Error("生产合格数量必须大于等于0")); |
| | | return; |
| | | } |
| | |
| | | } |
| | | const num = Number(value); |
| | | // 整数且大于等于0 |
| | | if (isNaN(num) || !Number.isInteger(num) || num < 0) { |
| | | if (isNaN(num) || num < 0) { |
| | | callback(new Error("报废数量必须大于等于0")); |
| | | return; |
| | | } |
| | |
| | | // 如果小于1,清除 |
| | | if (num < 0) { |
| | | reportForm.quantity = null; |
| | | return; |
| | | } |
| | | // 如果是小数取整数部分 |
| | | if (!Number.isInteger(num)) { |
| | | const intValue = Math.floor(num); |
| | | // 如果取整后小于1,清除 |
| | | if (intValue < 0) { |
| | | reportForm.quantity = null; |
| | | return; |
| | | } |
| | | reportForm.quantity = intValue; |
| | | return; |
| | | } |
| | | reportForm.quantity = num; |