diff --git a/src/components/contract.vue b/src/components/contract.vue
index dc1c6e6..97a85d3 100644
--- a/src/components/contract.vue
+++ b/src/components/contract.vue
@@ -503,7 +503,7 @@ const canDeleteRow = (row) => {
关闭
- { const d = currentDetail; closeDetail(); editContract(d) })()" v-if="userInfo.employee_id === currentDetail?.employee_id">编辑
+ { const d = currentDetail; closeDetail(); editContract(d) })()" v-if="canUpdate && userInfo.employee_id === currentDetail?.employee_id">编辑
diff --git a/src/components/employee.vue b/src/components/employee.vue
index ec9814e..ea6a326 100644
--- a/src/components/employee.vue
+++ b/src/components/employee.vue
@@ -14,7 +14,7 @@ import {
import { hasPermission, getUserInfo } from '../store/user'
import { formatDateTime, formatDate } from '../utils/date'
import { createUser } from '../api/user'
-import { DEPARTMENT_NAME_LIST } from '../constants/departments'
+import { DEPARTMENT_NAME_LIST, DEPARTMENT_LIST } from '../constants/departments'
const form = reactive({
name: '',
@@ -34,6 +34,7 @@ const form = reactive({
const search = ref('')
const select = ref('1')
const filterStatus = ref('')
+const filterDepartment = ref('')
const searchResults = ref([])
const showSearchResults = ref(false)
const showAddForm = ref(false)
@@ -52,6 +53,7 @@ const totalPages = ref(0)
// 新增用户相关状态
const showCreateUserForm = ref(false)
const justCreatedEmployee = ref(null)
+const linkedEmployeeId = ref(null) // 独立 ref 追踪关联员工 ID
const userForm = reactive({
username: '',
password: '',
@@ -73,7 +75,7 @@ const paginatedData = computed(() => searchResults.value)
// onMounted 已在下方合并(同时加载部门列表)
// 监听筛选变化
-watch([filterStatus], () => {
+watch([filterStatus, filterDepartment], () => {
currentPage.value = 1
handleSearch()
})
@@ -118,15 +120,14 @@ const handleSearch = async () => {
const params = {
page: 1,
pageSize: pageSize.value,
- status: filterStatus.value !== '' ? filterStatus.value : undefined
+ status: filterStatus.value !== '' ? filterStatus.value : undefined,
+ department: filterDepartment.value || undefined
}
if (search.value) {
if (select.value === '1') {
params.id = Number(search.value)
} else if (select.value === '2') {
params.name = search.value
- } else if (select.value === '3') {
- params.department = search.value
}
}
const res = await getEmployeeList(params)
@@ -148,6 +149,7 @@ const handleSearch = async () => {
const resetSearch = () => {
search.value = ''
filterStatus.value = ''
+ filterDepartment.value = ''
showSearchResults.value = false
showAddForm.value = false
currentPage.value = 1
@@ -241,11 +243,17 @@ const saveEmployee = async () => {
cancelButtonText: '暂不创建',
type: 'info'
}
- ).then(() => {
- // 确认:进入用户创建表单
- openUserForm(res.data)
+ ).then((action) => {
+ if (action === 'confirm') {
+ // 确认:进入用户创建表单
+ openUserForm(res.data)
+ } else {
+ // 取消:返回列表
+ cancelAdd()
+ fetchData()
+ }
}).catch(() => {
- // 取消:返回列表
+ // 用户点击了关闭按钮(X):返回列表
cancelAdd()
fetchData()
})
@@ -298,15 +306,25 @@ const handleCurrentChange = (val) => {
}
// 打开用户创建表单(从员工新增后调用)
-const openUserForm = (employee) => {
+const openUserForm = (emp) => {
+ // 兼容 res.data 嵌套:res.data 可能是 { data: {...} } 或直接 {...}
+ const employee = emp?.data || emp
+ if (!employee || !employee.id) {
+ console.error('[openUserForm] 员工数据异常:', emp)
+ ElMessage.error('员工信息获取失败,请重试')
+ return
+ }
showAddForm.value = false
showSearchResults.value = false
showCreateUserForm.value = true
- // 自动填充员工信息
+ // 用独立 ref 保存员工 ID,避免 reactive 对象异步问题
+ linkedEmployeeId.value = employee.id
+ // 自动填充员工信息,部门与员工一致
+ const deptMatch = DEPARTMENT_LIST.find(d => d.description === employee.department)
userForm.username = ''
userForm.password = ''
- userForm.name = employee.name
- userForm.department_id = 2
+ userForm.name = employee.name || ''
+ userForm.department_id = deptMatch ? deptMatch.id : 2
userForm.is_active = 1
userForm.employee_id = employee.id
}
@@ -330,22 +348,29 @@ const saveUserFromEmployee = async () => {
ElMessage.warning('请输入密码')
return
}
- await createUser({
- username: userForm.username,
- password: userForm.password,
- department_id: userForm.department_id,
- employee_id: userForm.employee_id,
- is_active: userForm.is_active
- })
- ElMessage.success('用户创建成功')
- cancelCreateUser()
- fetchData()
+ try {
+ const empId = linkedEmployeeId.value || userForm.employee_id
+ const payload = {
+ username: userForm.username,
+ password: userForm.password,
+ department_id: userForm.department_id,
+ employee_id: empId,
+ is_active: userForm.is_active
+ }
+ await createUser(payload)
+ ElMessage.success('用户创建成功')
+ cancelCreateUser()
+ fetchData()
+ } catch (e) {
+ ElMessage.error(e?.response?.data?.message || e?.message || '用户创建失败')
+ }
}
// 取消创建用户
const cancelCreateUser = () => {
showCreateUserForm.value = false
justCreatedEmployee.value = null
+ linkedEmployeeId.value = null
userForm.username = ''
userForm.password = ''
userForm.name = ''
@@ -375,7 +400,6 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
-
@@ -391,6 +415,9 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
筛选条件:
+
+
+
@@ -506,6 +533,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
+ 修改部门将同步更新关联用户的部门
@@ -522,7 +550,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
-
+
@@ -566,7 +594,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
-
+
@@ -592,13 +620,8 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
-
-
-
-
-
-
-
+
+
@@ -632,7 +655,7 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g
{{ currentDetail.education }}
{{ currentDetail.department }}
{{ currentDetail.position }}
-
+
¥{{ currentDetail.salary?.toLocaleString() }}
{{ formatDate(currentDetail.entry_date) }}
@@ -659,6 +682,13 @@ const showSalary = computed(() => ['总经理办公室', '财务部'].includes(g