|
|
@@ -356,7 +356,7 @@ function createNewUser(query: string) {
|
|
|
mobile: '',
|
|
|
isNew: true // 标记为新创建的用户
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// 添加到用户列表
|
|
|
allUserList.value.unshift(newUser);
|
|
|
filteredUserList.value = allUserList.value;
|
|
|
@@ -514,8 +514,8 @@ const form = ref({
|
|
|
external_borrower_phone:"",
|
|
|
emergency_contact: '111',
|
|
|
emergency_phone: '11111',
|
|
|
- app_user_borrower: null,
|
|
|
- admin_borrower: null,
|
|
|
+ app_user_borrower: null as number | null,
|
|
|
+ admin_borrower: null as number | null,
|
|
|
team_type: 0,
|
|
|
team_members_count: 2,
|
|
|
team_members: '',
|
|
|
@@ -532,6 +532,7 @@ const form = ref({
|
|
|
attachments:'',
|
|
|
user_code: '',
|
|
|
mobile: '',
|
|
|
+ mode: '' as 'add' | 'edit' | 'view' | '',
|
|
|
});
|
|
|
const showSelectDeviceDialog = ref(false);
|
|
|
|
|
|
@@ -579,7 +580,6 @@ onMounted(() => {
|
|
|
form.value.external_borrower_name = userInfo.username || '';
|
|
|
form.value.app_user_borrower = null;/* Number(userInfo.dept_info?.dept_id )|| */
|
|
|
form.value.external_borrower_phone = userInfo.mobile || '';
|
|
|
- form.value.borrower_dept = userInfo.dept_info?.dept_name || '';
|
|
|
}
|
|
|
} catch (e) {
|
|
|
/* empty */
|
|
|
@@ -631,7 +631,52 @@ watch(() => form.value.app_user_borrower, (newValue) => {
|
|
|
if (selectedUser) {
|
|
|
form.value.user_code = selectedUser.user_code || '';
|
|
|
form.value.mobile = selectedUser.mobile || '';
|
|
|
-
|
|
|
+ // 根据用户类型动态设置借用部门:
|
|
|
+ // 学生(user_type===0):学院/专业/班级;教师或领导(user_type===1或3):学院
|
|
|
+ let deptName: string = '';
|
|
|
+ const orgDetail: any = (selectedUser as any).organization_detail || {};
|
|
|
+ const parentChain: any[] = Array.isArray(orgDetail.parent_chain) ? orgDetail.parent_chain : [];
|
|
|
+ const isValid = (val: any) => {
|
|
|
+ const s = String(val).trim();
|
|
|
+ return val !== null && val !== undefined && s !== '' && s.toLowerCase() !== 'nan' && !Number.isNaN(val);
|
|
|
+ };
|
|
|
+ if ((selectedUser as any).user_type === 0) {
|
|
|
+ // 学生:优先按 parent_chain 顺序拼接“学院/专业/班级”,过滤掉“学校”层级
|
|
|
+ const chainNames: string[] = parentChain
|
|
|
+ .filter((n: any) => Number(n?.type) !== 1) // 1=学校,过滤
|
|
|
+ .map((n: any) => n?.name)
|
|
|
+ .filter((n: any) => isValid(n));
|
|
|
+ // 取前3级:学院(0)/专业(1)/班级(2)
|
|
|
+ const college = chainNames[1] || '';
|
|
|
+ const major = chainNames[2] || (selectedUser as any).sub_organization || '';
|
|
|
+ const clazz = orgDetail.name || (selectedUser as any).class_or_group || '';
|
|
|
+ const parts = [college, major, clazz].filter((p) => isValid(p));
|
|
|
+ deptName = parts.join('/');
|
|
|
+ if (!deptName) {
|
|
|
+ // 兜底:若 parent_chain 不可用,则使用已有汇总字段但尽量去掉“学校/”前缀
|
|
|
+ const full = (selectedUser as any).full_organization_name || '';
|
|
|
+ deptName = full.replace(/^学校\s*\/\s*/,'');
|
|
|
+ // 兜底后继续清洗 'nan' 与空白段
|
|
|
+ deptName = deptName
|
|
|
+ .split('/')
|
|
|
+ .map((s: string) => s.trim())
|
|
|
+ .filter((s: string) => isValid(s))
|
|
|
+ .join('/');
|
|
|
+ }
|
|
|
+ // 最终统一清洗,避免出现重复斜杠或 'nan'
|
|
|
+ deptName = deptName
|
|
|
+ .split('/')
|
|
|
+ .map((s: string) => s.trim())
|
|
|
+ .filter((s: string) => isValid(s))
|
|
|
+ .join('/');
|
|
|
+ } else if ((selectedUser as any).user_type === 1 || (selectedUser as any).user_type === 3) {
|
|
|
+ // 教师或学院领导:显示学院名称
|
|
|
+ deptName = orgDetail?.name || (selectedUser as any).organization || (selectedUser as any).full_organization_name || '';
|
|
|
+ } else {
|
|
|
+ // 其他类型兜底
|
|
|
+ deptName = (selectedUser as any).full_organization_name || '';
|
|
|
+ }
|
|
|
+ form.value.borrower_dept = isValid(deptName)?deptName:'';
|
|
|
// 如果是新创建的用户,提示用户填写完整信息
|
|
|
if (selectedUser.isNew) {
|
|
|
ElMessage.info('请为新用户填写学号/工号和联系电话');
|