/*
 * @Author: your name
 * @Date: 2021-08-03 14:39:54
 * @LastEditTime: 2021-08-03 16:36:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /CostAccountManaSys/mock/menu.js
 */


// eslint-disable-next-line import/no-extraneous-dependencies
import moment from 'moment';
import { parse } from 'url'; // mock tableListDataSource

const genList = (current, pageSize) => {
  const tableListDataSource = [];

  for (let i = 0; i < pageSize; i += 1) {
    const index = (current - 1) * 10 + i;
    tableListDataSource.push({
      key: index,
      menuId: index,
      parentId:index,
      name: `菜单名 ${i}`,
      path: `path路径 ${i}`,
      url:`url路径 ${i}`,
      perms:`授权 ${i}`,
      type:0,
      icon:`图标 ${i}`,
      orderNum:`排序 ${i}`,
      modifyUserName:`修改人 ${i}`,
      children:[
           {
            key:`${i}${index}`,
            menuId:`${i}${index}`,
            parentId:index+1,
            name: `菜单名 ${i}`,
            path: `path路径 ${i}`,
            url:`url路径 ${i}`,
            perms:`授权 ${i}`,
            type:0,
            icon:`图标 ${i}`,
            orderNum:`排序 ${i}`,
            modifyUserName:`修改人 ${i}`,
           }
      ],
      modifyTime: moment().format('YYYY-MM-DD'),
    });
  }
  //   console.log({tableListDataSource});
  tableListDataSource.reverse();
  return tableListDataSource;
};

let tableListDataSource = genList(1, 100);

function getList(req, res, u) {
  let realUrl = u;

  if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
    realUrl = req.url;
  }

  const { current = 1, pageSize = 10 } = req.query;
  let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize);

  const result = {
    data: {
      list: dataSource,
      totalCount: tableListDataSource.length,
      pageSize: pageSize,
    },
    status: 200,
    success: true,
  };
  return res.json(result);
}

function postList(req, res, u, b) {

  const result = {
    status: 200,
    msg: '',
  };
  res.json(result);
}

function delList(req, res, u, b) {
  const { method, body } = req;
  tableListDataSource = tableListDataSource.filter((item) => !body.includes(item.roleId));
  const result = {
    status: 200,
    msg: '',
  };
  res.json(result);
}

function editList(req, res, u, b) {
  const { method, body } = req;
  const { roleId, userIds } = body;
  const result = {
    status: 200,
    msg: '',
  };
  res.json(result);
}


export default {
  'GET /api/costAccount/menu/list': getList,
  'POST /api/costAccount/menu/save': postList,
  'POST /api/costAccount/menu/edit': editList,
};
