// 模拟静态数据
const mockDepts = [
  { deptId: 1, parentId: 0, deptName: '总公司', orderNum: 1, leader: '张三', phone: '15888888888', status: '0', createTime: '2023-01-01' },
  { deptId: 2, parentId: 1, deptName: '研发部', orderNum: 1, leader: '李四', phone: '15666666666', status: '0', createTime: '2023-01-02' },
  { deptId: 3, parentId: 1, deptName: '市场部', orderNum: 2, leader: '王五', phone: '15555555555', status: '0', createTime: '2023-01-03' }
];

// 查询部门列表
export function listDept(query) {
  const { deptName, status } = query;
  let filteredDepts = [...mockDepts];
  
  if (deptName) {
    filteredDepts = filteredDepts.filter(dept => dept.deptName.includes(deptName));
  }
  if (status) {
    filteredDepts = filteredDepts.filter(dept => dept.status === status);
  }
  
  return Promise.resolve(filteredDepts);
}

// 查询部门列表（排除节点）
export function listDeptExcludeChild(deptId) {
  const excludeDepts = mockDepts.filter(dept => dept.deptId !== parseInt(deptId));
  return Promise.resolve(excludeDepts);
}

// 查询部门详细
export function getDept(deptId) {
  const dept = mockDepts.find(d => d.deptId === parseInt(deptId));
  return Promise.resolve(dept || {});
}

// 新增部门
export function addDept(data) {
  const newDept = {
    deptId: mockDepts.length + 1,
    ...data,
    createTime: new Date().toISOString().split('T')[0]
  };
  mockDepts.push(newDept);
  return Promise.resolve({ code: 200, msg: '新增成功' });
}

// 修改部门
export function updateDept(data) {
  const index = mockDepts.findIndex(d => d.deptId === data.deptId);
  if (index !== -1) {
    mockDepts[index] = { ...mockDepts[index], ...data };
  }
  return Promise.resolve({ code: 200, msg: '修改成功' });
}

// 删除部门
export function delDept(deptId) {
  const index = mockDepts.findIndex(d => d.deptId === parseInt(deptId));
  if (index !== -1) {
    mockDepts.splice(index, 1);
  }
  return Promise.resolve({ code: 200, msg: '删除成功' });
}