Ver código fonte

员工绑定

xw 1 mês atrás
pai
commit
84abbaf26c

+ 9 - 0
src/api/company/companyUser.js

@@ -352,6 +352,15 @@ export function queryFsUserByPhone(phone) {
   })
 }
 
+// 根据用户ID查询fs_user(完全匹配)
+export function queryFsUserByUserId(userId) {
+  return request({
+    url: '/company/user/fsUser/queryByUserId',
+    method: 'get',
+    params: { userId: userId }
+  })
+}
+
 // 批量绑定用户到员工
 export function batchBindCompanyUserId(data) {
   return request({

+ 55 - 15
src/views/company/companyUser/index.vue

@@ -643,6 +643,17 @@
             <el-button slot="append" icon="el-icon-search" @click="queryFsUserByPhone">查询</el-button>
           </el-input>
         </el-form-item>
+        <el-form-item label="用户ID">
+          <el-input
+            v-model="bindUserForm.userId"
+            placeholder="请输入用户 ID(完全匹配)"
+            clearable
+            style="width: 300px;"
+            @keyup.enter.native="queryFsUserByUserId"
+          >
+            <el-button slot="append" icon="el-icon-search" @click="queryFsUserByUserId">查询</el-button>
+          </el-input>
+        </el-form-item>
       </el-form>
 
       <!-- 已绑定用户信息 -->
@@ -671,7 +682,7 @@
           <el-table-column prop="phone" label="电话" align="center"></el-table-column>
         </el-table>
       </div>
-      <div v-else-if="bindUserForm.phone && !bindUserLoading" style="text-align: center; padding: 20px; color: #909399;">
+      <div v-else-if="(bindUserForm.phone || bindUserForm.userId) && !bindUserLoading" style="text-align: center; padding: 20px; color: #909399;">
         暂无查询结果
       </div>
       <div v-if="bindUserLoading" style="text-align: center; padding: 20px;">
@@ -704,6 +715,7 @@ import {
   updateCompanyUserAreaList,
   isAllowedAllRegister, unBindDoctorId, bindDoctorId,updateBatchUserRoles,
   queryFsUserByPhone,
+  queryFsUserByUserId,
   batchBindCompanyUserId,
   getBoundUsers
 } from "@/api/company/companyUser";
@@ -938,6 +950,7 @@ export default {
       },
       bindUserForm: {
         phone: '',
+        userId: '',
         companyUserId: null
       },
       fsUserList: [],
@@ -1714,6 +1727,7 @@ export default {
     handleBindUser(row) {
       this.bindUserForm.companyUserId = row.userId;
       this.bindUserForm.phone = '';
+      this.bindUserForm.userId = '';
       this.fsUserList = [];
       this.selectedFsUserIds = [];
       this.boundUsersList = [];
@@ -1750,27 +1764,52 @@ export default {
 
       this.bindUserLoading = true;
       queryFsUserByPhone(this.bindUserForm.phone).then(response => {
+        this.handleBindUserQueryResponse(response);
+      }).catch(() => {
         this.bindUserLoading = false;
-        if (response.code === 200) {
-          if (response.data) {
-            // 如果返回的是单个对象,转换为数组
-            this.fsUserList = Array.isArray(response.data) ? response.data : [response.data];
-            if (this.fsUserList.length === 0) {
-              this.$message.info('未找到匹配的用户');
-            }
-          } else {
-            this.fsUserList = [];
+        this.fsUserList = [];
+        this.$message.error('查询失败');
+      });
+    },
+    /** 根据用户ID查询fs_user */
+    queryFsUserByUserId() {
+      const userId = Number(this.bindUserForm.userId);
+      if (!this.bindUserForm.userId) {
+        this.$message.warning('请输入用户ID');
+        return;
+      }
+      if (!Number.isInteger(userId) || userId <= 0) {
+        this.$message.error('请输入大于0的用户ID');
+        return;
+      }
+
+      this.bindUserLoading = true;
+      queryFsUserByUserId(userId).then(response => {
+        this.handleBindUserQueryResponse(response);
+      }).catch(() => {
+        this.bindUserLoading = false;
+        this.fsUserList = [];
+        this.$message.error('查询失败');
+      });
+    },
+    /** 处理绑定用户查询响应 */
+    handleBindUserQueryResponse(response) {
+      this.bindUserLoading = false;
+      if (response.code === 200) {
+        if (response.data) {
+          // 如果返回的是单个对象,转换为数组
+          this.fsUserList = Array.isArray(response.data) ? response.data : [response.data];
+          if (this.fsUserList.length === 0) {
             this.$message.info('未找到匹配的用户');
           }
         } else {
           this.fsUserList = [];
-          this.$message.error(response.msg || '查询失败');
+          this.$message.info('未找到匹配的用户');
         }
-      }).catch(error => {
-        this.bindUserLoading = false;
+      } else {
         this.fsUserList = [];
-        this.$message.error('查询失败');
-      });
+        this.$message.error(response.msg || '查询失败');
+      }
     },
     /** 处理fs_user选择变化 */
     handleFsUserSelectionChange(selection) {
@@ -1804,6 +1843,7 @@ export default {
     resetBindUserForm() {
       this.bindUserForm = {
         phone: '',
+        userId: '',
         companyUserId: null
       };
       this.fsUserList = [];