// 模拟静态数据
const mockPosts = [
  { postId: 1, postName: '总经理', postCode: 'CEO', postSort: 1, status: '0', createTime: '2023-01-01' },
  { postId: 2, postName: '技术总监', postCode: 'CTO', postSort: 2, status: '0', createTime: '2023-01-02' }
];

// 查询岗位列表
export function listPost(query) {
  const { pageNum, pageSize, postName, postCode, status } = query;
  let filteredPosts = [...mockPosts];
  
  if (postName) {
    filteredPosts = filteredPosts.filter(post => post.postName.includes(postName));
  }
  if (postCode) {
    filteredPosts = filteredPosts.filter(post => post.postCode.includes(postCode));
  }
  if (status) {
    filteredPosts = filteredPosts.filter(post => post.status === status);
  }
  
  const total = filteredPosts.length;
  const start = (pageNum - 1) * pageSize;
  const end = start + pageSize;
  const list = filteredPosts.slice(start, end);
  
  return Promise.resolve({
    total,
    rows: list
  });
}

// 查询岗位详细
export function getPost(postId) {
  const post = mockPosts.find(p => p.postId === parseInt(postId));
  return Promise.resolve(post || {});
}

// 新增岗位
export function addPost(data) {
  const newPost = {
    postId: mockPosts.length + 1,
    ...data,
    createTime: new Date().toISOString().split('T')[0]
  };
  mockPosts.push(newPost);
  return Promise.resolve({ code: 200, msg: '新增成功' });
}

// 修改岗位
export function updatePost(data) {
  const index = mockPosts.findIndex(p => p.postId === data.postId);
  if (index !== -1) {
    mockPosts[index] = { ...mockPosts[index], ...data };
  }
  return Promise.resolve({ code: 200, msg: '修改成功' });
}

// 删除岗位
export function delPost(postId) {
  const index = mockPosts.findIndex(p => p.postId === parseInt(postId));
  if (index !== -1) {
    mockPosts.splice(index, 1);
  }
  return Promise.resolve({ code: 200, msg: '删除成功' });
}
