/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2025-04-15 15:07:50
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-04-15 15:48:45
 * @FilePath: /pfmBackMana/mock/emp.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// mock/employees.js

// 模拟的所有人员数据
const allEmployees = [
  { id: 32, code: '0000032', name: '张晓艺' },
  { id: 33, code: '0000033', name: '王芬芬' },
  { id: 34, code: '0000034', name: '杨梦怡' },
  { id: 35, code: '0000035', name: '刘欣蓉' },
  { id: 36, code: '0000036', name: '张东霞' },
  { id: 37, code: '0000037', name: '李天薇' },
  { id: 38, code: '0000038', name: '王盼盼' },
  { id: 39, code: '0000039', name: '王明明' },
  { id: 40, code: '0000040', name: '柳飘飘' },
  { id: 41, code: '0000041', name: '李俊' },
  // 可根据需要增加更多数据用于分页
];

export default {
  // 定义 GET 请求，路径为 /api/employees
  'GET /api/manager/Employee/getEmpList': (req, res) => {
    const { page = 1, pageSize = 10, keywords = '' } = req.query;
    const pageNumber = parseInt(page, 10);
    const pageSizeNumber = parseInt(pageSize, 10);

    // 根据关键词过滤人员数据
    const filteredEmployees = allEmployees.filter((emp) => {
      return (
        emp.name.indexOf(keywords) !== -1 || emp.code.indexOf(keywords) !== -1
      );
    });

    const totalCount = filteredEmployees.length;
    const totalPage = Math.ceil(totalCount / pageSizeNumber);
    const startIndex = (pageNumber - 1) * pageSizeNumber;
    const list = filteredEmployees.slice(
      startIndex,
      startIndex + pageSizeNumber,
    );

    // 返回接口数据结构与前端预期一致
    res.json({
      status: 200,
      msg: 'success',
      data: {
        totalCount,
        pageSize: pageSizeNumber,
        totalPage,
        currPage: pageNumber,
        list,
      },
    });
  },
};
