Commit 7d600b6a35f4df823524ca8ce2cea0fc45be99ff

Authored by 张红振
1 parent e3309cb2

新增身份证获取详细信息

src/utils/tool.ts
... ... @@ -3,7 +3,7 @@ import type { EnumArrayItem } from "@/@type/module/basic"
3 3 /**
4 4 * 页面回退
5 5 */
6   - export function back() {
  6 +export function back() {
7 7 history.go(-1)
8 8 }
9 9  
... ... @@ -11,7 +11,7 @@ import type { EnumArrayItem } from "@/@type/module/basic"
11 11 * 表单重置
12 12 * @param {String} formName 表单名称
13 13 */
14   - export function resetForm(formName) {
  14 +export function resetForm(formName) {
15 15 this.$refs[formName].resetFields()
16 16 }
17 17  
... ... @@ -21,7 +21,7 @@ import type { EnumArrayItem } from "@/@type/module/basic"
21 21 * @returns {number} s 小数点两位
22 22 */
23 23  
24   - export function toDecimal2(x) {
  24 +export function toDecimal2(x) {
25 25 var f = parseFloat(x)
26 26 if (isNaN(f)) {
27 27 return false
... ... @@ -45,7 +45,7 @@ import type { EnumArrayItem } from "@/@type/module/basic"
45 45 * @param {string} cFormat 转换格式
46 46 * @returns {string | null}
47 47 */
48   - export function parseTime(time, cFormat) {
  48 +export function parseTime(time, cFormat) {
49 49 if (arguments.length === 0 || !time) {
50 50 return null
51 51 }
... ... @@ -145,8 +145,8 @@ export function formatTime(time, option) {
145 145 * @param {Array.EnumData} groupData
146 146 * @returns {string}
147 147 */
148   -export function globalFilters (value: number, groupData: EnumArrayItem[]) {
149   - if(groupData.length && (~~value === 0 || !!value)) {
  148 +export function globalFilters(value: number, groupData: EnumArrayItem[]) {
  149 + if (groupData.length && (~~value === 0 || !!value)) {
150 150 return groupData.find(item => ~~item.value === ~~value)['label']
151 151 } else {
152 152 return value
... ... @@ -158,7 +158,7 @@ export function globalFilters (value: number, groupData: EnumArrayItem[]) {
158 158 * @param {object} data
159 159 * @returns {FormData} fd
160 160 */
161   -export function formDataWrapper (data: any) {
  161 +export function formDataWrapper(data: any) {
162 162 const fd: any = new FormData()
163 163 for (let i in data) {
164 164 fd.append(i, data[i])
... ... @@ -171,11 +171,49 @@ export function formDataWrapper (data: any) {
171 171 * @param {object} data
172 172 * @returns {FormData} fd
173 173 */
174   - export function deleteEmptyParam (params: any) {
  174 +export function deleteEmptyParam(params: any) {
175 175 for (const i in params) {
176 176 if (!(params[i] + '').trim()) {
177 177 delete params[i]
178 178 }
179 179 }
180 180 return params
  181 +}
  182 +
  183 +/***
  184 + * 根据身份证获取性别
  185 + * @param { string } value 身份证号
  186 + * @return { string } 性别
  187 + */
  188 +export function getSex(value: string): string {
  189 + return parseInt(value.substr(16, 1)) % 2 == 1 ? '男' : '女'
  190 +}
  191 +/***
  192 + * 根据身份证获取年龄
  193 + * @param { string } value 身份证号
  194 + * @return { number } 年龄
  195 + */
  196 +export function getAge(value: any ): number {
  197 +
  198 + let myDate = new Date()
  199 + let month = myDate.getMonth() + 1
  200 + let day = myDate.getDate()
  201 + // let valueDate=
  202 + let age = myDate.getFullYear() - value.substring(6, 10) - 1
  203 + if (
  204 + value.substring(10, 12) < month ||
  205 + (value.substring(10, 12) == month &&
  206 + value.substring(12, 14) <= day)
  207 + ) {
  208 + age++
  209 + }
  210 + return age
  211 +}
  212 +/***
  213 + * 根据身份证获取出生日期
  214 + * @param { string } value 身份证号
  215 + * @return { string } 出生日期
  216 + */
  217 +export function getBirthDate(value: string ): string {
  218 + return `${value.substring(6, 10)}-${value.substring(10, 12)}-${value.substring(12, 14)}`
181 219 }
182 220 \ No newline at end of file
... ...
src/views/housekeeper/buildinMganager/detail.vue
... ... @@ -3,6 +3,7 @@ import { reactive, ref, getCurrentInstance, defineExpose } from &quot;vue&quot;;
3 3 import type { ElForm } from "element-plus";
4 4 import { insertOrUpdate } from "@/api/housekeeper/buildinMganager.ts";
5 5 import { validMobile, checkIdcard } from "@/utils/validate";
  6 +import { getSex, getBirthDate } from "@/utils/tool";
6 7  
7 8 const ruleFormRef = ref<InstanceType<typeof ElForm>>();
8 9 let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
... ... @@ -56,6 +57,8 @@ const checkPhone = (rules, value, callback) =&gt; {
56 57 */
57 58 const checkCard = (rules, value, callback) => {
58 59 if (checkIdcard(value)) {
  60 + props.formObj.gender= getSex(value)=="男"?1:0
  61 + props.formObj.birthdate= getBirthDate(value)
59 62 callback();
60 63 } else {
61 64 callback(new Error("请填写正确的身份证"));
... ...
src/views/serviceman/detail.vue
... ... @@ -9,7 +9,8 @@ import {
9 9 import type { ElForm } from "element-plus";
10 10 import { addOrUpdate } from "@/api/notify/serviceman.ts";
11 11 import { getTableList } from "@/api/community/residence.ts";
12   -import { validMobile, idcardEasy } from "@/utils/validate";
  12 +import { validMobile, checkIdcard } from "@/utils/validate";
  13 +import { getSex, getAge } from "@/utils/tool";
13 14  
14 15 const ruleFormRef = ref<InstanceType<typeof ElForm>>();
15 16 let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
... ... @@ -52,7 +53,9 @@ const checkPhone = (rules, value, callback) =&gt; {
52 53 * @callback checkCard~checkCallback
53 54 */
54 55 const checkCard = (rules, value, callback) => {
55   - if (idcardEasy(value)) {
  56 + if (checkIdcard(value)) {
  57 + props.formObj.sex = getSex(value);
  58 + props.formObj.age = getAge(value);
56 59 callback();
57 60 } else {
58 61 callback(new Error("请填写正确的身份证"));
... ... @@ -74,7 +77,7 @@ const rules = reactive({
74 77 message: "请输入年龄",
75 78 trigger: "blur",
76 79 },
77   - { type: "number", message: "请输入正确的年龄", max: 120,min:1 },
  80 + { type: "number", message: "请输入正确的年龄", max: 120, min: 1 },
78 81 ],
79 82 mobile: [
80 83 {
... ... @@ -139,7 +142,6 @@ let submitForm = (formEl: InstanceType&lt;typeof ElForm&gt; | undefined) =&gt; {
139 142 })
140 143 .toString();
141 144 params = Object.assign(params, { ids: ids });
142   - // console.log({ accendant: params, neighborhoodIds: ids })
143 145 addOrUpdate(params)
144 146 .then((res) => {
145 147 data.loading = false;
... ... @@ -189,12 +191,14 @@ onMounted(() =&gt; {
189 191 maxlength="10"
190 192 ></el-input>
191 193 </el-form-item>
192   - <el-form-item label="年龄:" prop="age">
  194 + <el-form-item label="身份证号:" prop="idCard">
193 195 <el-input
194   - v-model.number="props.formObj.age"
195   - placeholder="请输入年龄"
  196 + v-model="props.formObj.idCard"
  197 + placeholder="请输入身份证号"
  198 + maxlength="18"
196 199 ></el-input>
197 200 </el-form-item>
  201 +
198 202 <el-form-item label="联系电话:" prop="mobile">
199 203 <el-input
200 204 v-model="props.formObj.mobile"
... ... @@ -203,13 +207,7 @@ onMounted(() =&gt; {
203 207 :disabled="props.formObj.id"
204 208 ></el-input>
205 209 </el-form-item>
206   - <el-form-item label="身份证号:" prop="idCard">
207   - <el-input
208   - v-model="props.formObj.idCard"
209   - placeholder="请输入身份证号"
210   - maxlength="18"
211   - ></el-input>
212   - </el-form-item>
  210 +
213 211 <el-form-item label="服务小区:" prop="neighborhoods">
214 212 <el-select
215 213 v-model="props.formObj.neighborhoods"
... ... @@ -227,8 +225,16 @@ onMounted(() =&gt; {
227 225 </el-option>
228 226 </el-select>
229 227 </el-form-item>
  228 + <el-form-item label="年龄:" prop="age">
  229 + <el-input
  230 + :disabled="true"
  231 + v-model.number="props.formObj.age"
  232 + placeholder="请输入年龄"
  233 + ></el-input>
  234 + </el-form-item>
230 235 <el-form-item label="性别:" prop="sex">
231 236 <el-select
  237 + :disabled="true"
232 238 v-model="props.formObj.sex"
233 239 placeholder="请选择性别"
234 240 style="width: 100%"
... ...