From 2a7b819fb24c6e91335a6b2c531f63ef0d9c45a6 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Tue, 16 Dec 2025 14:47:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=B3=E8=AF=B7=E6=8A=9A?= =?UTF-8?q?=E6=85=B0=E7=9A=84=E4=BA=BA=E5=91=98=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/rightsComfort/comfort.ts | 12 +++ src/utils/numberUtil.ts | 103 ++++++++++++++++++++++++++ src/views/rightsComfort/MyComfort.vue | 30 ++++++-- 3 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 src/utils/numberUtil.ts diff --git a/src/api/rightsComfort/comfort.ts b/src/api/rightsComfort/comfort.ts index ccfc326..7a1add3 100644 --- a/src/api/rightsComfort/comfort.ts +++ b/src/api/rightsComfort/comfort.ts @@ -54,4 +54,16 @@ export function comfortApprove(body) { url: `/comfort/approve`, body }); +} + + +/** + * 获取申请抚慰的申请人信息 + * @param times + */ +export function getPoliceInfo(body){ + return request.post({ + url: `/comfort/getPoliceInfo`, + body + }) } \ No newline at end of file diff --git a/src/utils/numberUtil.ts b/src/utils/numberUtil.ts new file mode 100644 index 0000000..8185be1 --- /dev/null +++ b/src/utils/numberUtil.ts @@ -0,0 +1,103 @@ +/** + * numberUtil + * 前端数值统一处理工具 + * + * 适配后端: + * int / Integer + * double / Double + * BigDecimal(序列化后通常是 string) + */ +const numberUtil = { + + /** + * 基础:转 Number + * - 支持 string / number + * - BigDecimal(JSON) -> string -> number + */ + toNumber(val) { + if (val === null || val === undefined || val === '') return null; + const n = Number(val); + return Number.isNaN(n) ? null : n; + }, + + /** + * 转 Number,空值给默认值(常用于金额) + */ + toNumberOr(val, defaultVal = 0) { + const n = this.toNumber(val); + return n === null ? defaultVal : n; + }, + + /** + * 专用于整数(int / long) + * "1.0" -> 1 + * 1.9 -> 1 + */ + toInt(val) { + const n = this.toNumber(val); + return n === null ? null : Math.trunc(n); + }, + + /** + * 专用于金额(double / BigDecimal) + * 默认保留 2 位 + */ + toDecimal(val, scale = 2) { + const n = this.toNumber(val); + if (n === null) return null; + return Number(n.toFixed(scale)); + }, + + /** + * 是否是合法数值(string / number) + */ + isNumber(val) { + if (val === null || val === undefined || val === '') return false; + return !Number.isNaN(Number(val)); + }, + + /** + * 性别归一化(int / string 都支持) + * 0 / "0" -> 0 + * 1 / "1" -> 1 + */ + normalizeSex(val) { + const n = this.toInt(val); + return n === 0 || n === 1 ? n : null; + }, + + /** + * 是 / 否 类型(radio / checkbox 常用) + * 支持:0/1, "0"/"1", true/false + */ + normalizeYesNo(val) { + if (val === true || val === 'true') return 1; + if (val === false || val === 'false') return 0; + const n = this.toInt(val); + return n === 0 || n === 1 ? n : null; + }, + + /** + * BigDecimal 场景:保证回传给后端的是 string + * 避免 JS 精度问题 + */ + toBigDecimalString(val, scale = 2) { + const n = this.toNumber(val); + if (n === null) return null; + return n.toFixed(scale); + }, + + /** + * 金额安全相加(避免 null) + */ + sum(list, field) { + if (!Array.isArray(list)) return 0; + return list.reduce((total, item) => { + const v = item?.[field]; + const n = this.toNumber(v); + return total + (n ?? 0); + }, 0); + } +}; + +export default numberUtil; diff --git a/src/views/rightsComfort/MyComfort.vue b/src/views/rightsComfort/MyComfort.vue index d3170bd..a928adb 100644 --- a/src/views/rightsComfort/MyComfort.vue +++ b/src/views/rightsComfort/MyComfort.vue @@ -408,6 +408,7 @@ clearable style="width: 300px" placeholder="请输入" + @keyup.enter="formData.idCode && onKeyEnter()" /> @@ -448,6 +449,7 @@ v-model="formData.empNo" style="width: 300px" placeholder="请输入" + @keyup.enter="formData.empNo && onKeyEnter()" /> @@ -818,12 +820,12 @@ import { BASE_PATH } from "@/api/request"; import moment from "moment"; import { - listComfortTodos, - listDone, - applyComfort, - updateComfort, - delComfort, - getDetail, + listComfortTodos, + listDone, + applyComfort, + updateComfort, + delComfort, + getDetail, getPoliceInfo, } from "@/api/rightsComfort/comfort"; import { listPolice } from "@/api/system/police"; import { listRightPersonByDepartId } from "@/api/system/rightPerson"; @@ -834,6 +836,7 @@ import feedback from "@/utils/feedback"; import useCatchStore from "@/stores/modules/catch"; import useUserStore from "@/stores/modules/user"; +import numberUtil from "@/utils/numberUtil.ts" const catchStore = useCatchStore(); const dict = catchStore.getDicts([ @@ -1073,6 +1076,21 @@ function handleSelectIsSelf() { } const resultShow = ref(true); + + +const onKeyEnter = async ()=>{ + const body = { + idCode: formData.value.idCode, + empNo: formData.value.empNo + } + const res= await getPoliceInfo(body) + formData.value.applicantEmpName = res.name; + formData.value.sex =numberUtil.normalizeSex(res.gender); + formData.value.idCode = res.idCode; + formData.value.departId = res.orgId; + formData.value.empNo = res.empNo; +} +