|
|
@@ -586,6 +586,65 @@ onMounted(() => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+// —— 按学号/工号回显借用人信息(防抖,不影响现有交互) ——
|
|
|
+let userCodeDebounceTimer: any = null;
|
|
|
+async function queryUserByCode(userCode: string) {
|
|
|
+ try {
|
|
|
+ // 先在已加载的全量列表中查找,避免重复请求
|
|
|
+ if (allUserList.value && allUserList.value.length > 0) {
|
|
|
+ const local = allUserList.value.find((u: any) => String(u.user_code || '').trim() === String(userCode).trim());
|
|
|
+ if (local) {
|
|
|
+ form.value.app_user_borrower = Number(local.id);
|
|
|
+ form.value.user_code = local.user_code || '';
|
|
|
+ form.value.mobile = local.mobile || '';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 远端查询:尽量使用通用查询参数,兼容不同实现
|
|
|
+ const tryParamsList = [
|
|
|
+ { user_code: userCode, page: 1, limit: 20 },
|
|
|
+ { search: userCode, page: 1, limit: 20 },
|
|
|
+ { code: userCode, page: 1, limit: 20 },
|
|
|
+ ];
|
|
|
+
|
|
|
+ let found: any = null;
|
|
|
+ for (const params of tryParamsList) {
|
|
|
+ const res: any = await api.GetAllUser(params);
|
|
|
+ if (res && (res.code === 2000 || res.status === 200) && Array.isArray(res.data) && res.data.length > 0) {
|
|
|
+ found = res.data.find((u: any) => String(u.user_code || '').trim() === String(userCode).trim()) || res.data[0];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (found) {
|
|
|
+ form.value.app_user_borrower = Number(found.id);
|
|
|
+ form.value.user_code = found.user_code || '';
|
|
|
+ form.value.mobile = found.mobile || '';
|
|
|
+ // 部门信息将由现有的 app_user_borrower 监听逻辑自动回填
|
|
|
+ } else {
|
|
|
+ // 未找到时不覆盖已有填写,给出轻提示
|
|
|
+ ElMessage.warning('未找到匹配的借用人');
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ /* empty */
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function scheduleQueryUserByCode(userCode: string) {
|
|
|
+ if (userCodeDebounceTimer) clearTimeout(userCodeDebounceTimer);
|
|
|
+ userCodeDebounceTimer = setTimeout(() => {
|
|
|
+ if (!userCode || String(userCode).trim().length < 2) return;
|
|
|
+ if (form.value.borrower_type === 2) return; // 外部用户不查
|
|
|
+ if (isView.value) return; // 查看态不查
|
|
|
+ queryUserByCode(String(userCode).trim());
|
|
|
+ }, 300);
|
|
|
+}
|
|
|
+
|
|
|
+watch(() => form.value.user_code, (nv) => {
|
|
|
+ scheduleQueryUserByCode(nv as any);
|
|
|
+});
|
|
|
+
|
|
|
watch(
|
|
|
() => props.visible,
|
|
|
(v) => (visible.value = v)
|