import { getUrlParams } from "./utils";

const titles = [
  "Alipay",
  "Angular",
  "Ant Design",
  "Ant Design Pro",
  "Bootstrap",
  "React",
  "Vue",
  "Webpack"
];
const avatars = [
  "https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png", // Alipay
  "https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png", // Angular
  "https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png", // Ant Design
  "https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png", // Ant Design Pro
  "https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png", // Bootstrap
  "https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png", // React
  "https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png", // Vue
  "https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png" // Webpack
];
const covers = [
  "https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png",
  "https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png",
  "https://gw.alipayobjects.com/zos/rmsportal/uVZonEtjWwmUZPBQfycs.png",
  "https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png"
];
const desc = [
  "那是一种内在的东西， 他们到达不了，也无法触及的",
  "希望是一个好东西，也许是最好的，好东西是不会消亡的",
  "生命就像一盒巧克力，结果往往出人意料",
  "城镇中有那么多的酒馆，她却偏偏走进了我的酒馆",
  "那时候我只会想自己想要什么，从不想自己拥有什么"
];

const user = [
  "付小小",
  "曲丽丽",
  "林东东",
  "周星星",
  "吴加好",
  "朱偏右",
  "鱼酱",
  "乐哥",
  "谭小仪",
  "仲尼"
];

export function fakeList(count) {
  const list = [];
  for (let i = 0; i < count; i += 1) {
    list.push({
      id: `fake-list-${i}`,
      owner: user[i % 10],
      title: titles[i % 8],
      avatar: avatars[i % 8],
      cover: parseInt(i / 4, 10) % 2 === 0 ? covers[i % 4] : covers[3 - i % 4],
      status: ["active", "exception", "normal"][i % 3],
      percent: Math.ceil(Math.random() * 50) + 50,
      logo: avatars[i % 8],
      href: "https://ant.design",
      updatedAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
      createdAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
      subDescription: desc[i % 5],
      description:
        "在中台产品的研发过程中，会出现不同的设计规范和实现方式，但其中往往存在很多类似的页面和组件，这些类似的组件会被抽离成一套标准规范。",
      activeUser: Math.ceil(Math.random() * 100000) + 100000,
      newUser: Math.ceil(Math.random() * 1000) + 1000,
      star: Math.ceil(Math.random() * 100) + 100,
      like: Math.ceil(Math.random() * 100) + 100,
      message: Math.ceil(Math.random() * 10) + 10,
      content:
        "段落示意：蚂蚁金服设计平台 ant.design，用最小的工作量，无缝接入蚂蚁金服生态，提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design，用最小的工作量，无缝接入蚂蚁金服生态，提供跨越设计与开发的体验解决方案。",
      members: [
        {
          avatar:
            "https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png",
          name: "曲丽丽"
        },
        {
          avatar:
            "https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png",
          name: "王昭君"
        },
        {
          avatar:
            "https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png",
          name: "董娜娜"
        }
      ]
    });
  }

  return list;
}

export function getFakeList(req, res, u) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }

  const params = getUrlParams(url);

  const count = params.count * 1 || 20;

  const result = fakeList(count);

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
}

export const getNotice = [
  {
    id: "xxx1",
    title: titles[0],
    logo: avatars[0],
    description: "那是一种内在的东西，他们到达不了，也无法触及的",
    updatedAt: new Date(),
    member: "科学搬砖组",
    href: "",
    memberLink: ""
  },
  {
    id: "xxx2",
    title: titles[1],
    logo: avatars[1],
    description: "希望是一个好东西，也许是最好的，好东西是不会消亡的",
    updatedAt: new Date("2017-07-24"),
    member: "全组都是吴彦祖",
    href: "",
    memberLink: ""
  },
  {
    id: "xxx3",
    title: titles[2],
    logo: avatars[2],
    description: "城镇中有那么多的酒馆，她却偏偏走进了我的酒馆",
    updatedAt: new Date(),
    member: "中二少女团",
    href: "",
    memberLink: ""
  },
  {
    id: "xxx4",
    title: titles[3],
    logo: avatars[3],
    description: "那时候我只会想自己想要什么，从不想自己拥有什么",
    updatedAt: new Date("2017-07-23"),
    member: "程序员日常",
    href: "",
    memberLink: ""
  },
  {
    id: "xxx5",
    title: titles[4],
    logo: avatars[4],
    description: "凛冬将至",
    updatedAt: new Date("2017-07-23"),
    member: "高逼格设计天团",
    href: "",
    memberLink: ""
  },
  {
    id: "xxx6",
    title: titles[5],
    logo: avatars[5],
    description: "生命就像一盒巧克力，结果往往出人意料",
    updatedAt: new Date("2017-07-23"),
    member: "骗你来学计算机",
    href: "",
    memberLink: ""
  }
];

export const getActivities = [
  {
    id: "trend-1",
    updatedAt: new Date(),
    user: {
      name: "林东东",
      avatar: avatars[0]
    },
    group: {
      name: "高逼格设计天团",
      link: "http://github.com/"
    },
    project: {
      name: "六月迭代",
      link: "http://github.com/"
    },
    template: "在 @{group} 新建项目 @{project}"
  },
  {
    id: "trend-2",
    updatedAt: new Date(),
    user: {
      name: "付小小",
      avatar: avatars[1]
    },
    group: {
      name: "高逼格设计天团",
      link: "http://github.com/"
    },
    project: {
      name: "六月迭代",
      link: "http://github.com/"
    },
    template: "在 @{group} 新建项目 @{project}"
  },
  {
    id: "trend-3",
    updatedAt: new Date(),
    user: {
      name: "曲丽丽",
      avatar: avatars[2]
    },
    group: {
      name: "中二少女团",
      link: "http://github.com/"
    },
    project: {
      name: "六月迭代",
      link: "http://github.com/"
    },
    template: "在 @{group} 新建项目 @{project}"
  },
  {
    id: "trend-4",
    updatedAt: new Date(),
    user: {
      name: "周星星",
      avatar: avatars[3]
    },
    project: {
      name: "5 月日常迭代",
      link: "http://github.com/"
    },
    template: "将 @{project} 更新至已发布状态"
  },
  {
    id: "trend-5",
    updatedAt: new Date(),
    user: {
      name: "朱偏右",
      avatar: avatars[4]
    },
    project: {
      name: "工程效能",
      link: "http://github.com/"
    },
    comment: {
      name: "留言",
      link: "http://github.com/"
    },
    template: "在 @{project} 发布了 @{comment}"
  },
  {
    id: "trend-6",
    updatedAt: new Date(),
    user: {
      name: "乐哥",
      avatar: avatars[5]
    },
    group: {
      name: "程序员日常",
      link: "http://github.com/"
    },
    project: {
      name: "品牌迭代",
      link: "http://github.com/"
    },
    template: "在 @{group} 新建项目 @{project}"
  }
];

const orderData = {
  result: 1,
  msg: "查询成功",
  errorCode: null,
  data: [
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111008",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "04",
      poTypeName: "资源采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 16:48:23",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 2,
      totalAmount: 5,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "f5a4e11b-c728-4b3f-a449-3fd405ba54a7",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111007",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "05",
      poTypeName: "饰品采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: "饰品直送",
      orderDate: "2018-01-11 16:15:26",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 2,
      totalAmount: 11,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "59679ed9-f0cb-461c-aad2-b7b5ae8a7e52",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111006",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "04",
      poTypeName: "资源采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 16:03:55",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 3,
      totalAmount: 11,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "2dadc763-5faf-429e-a116-e3b567e98f26",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111005",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "04",
      poTypeName: "资源采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 16:03:07",
      billStatusCode: "03",
      billStatusName: "已审核",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 3,
      totalAmount: 11,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "b9f8ad0d-87bc-40f7-b5c5-803057947b71",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111004",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "04",
      poTypeName: "资源采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 16:00:58",
      billStatusCode: "03",
      billStatusName: "已审核",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 3,
      totalAmount: 11,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "df0f6e82-5564-4e9b-976d-de22eced0e1e",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111002",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "05",
      poTypeName: "饰品采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 15:52:00",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 7,
      totalAmount: 37,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "dadbe2cc-d0e6-4e98-a5e1-e11b8b4aeeb1",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180111001",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "01",
      poTypeName: "常规采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-11 15:51:25",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 2,
      totalAmount: 1120,
      totalVolume: 8.9,
      totalWeight: 444,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "cb10c21c-15c0-44e9-9a6a-082fe23e6a06",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180110001",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "05",
      poTypeName: "饰品采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-10 09:40:04",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 5,
      totalAmount: 27,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "da10e220-99b4-4eab-a1bb-539768082564",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180109016",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "05",
      poTypeName: "饰品采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-09 16:49:06",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 5,
      totalAmount: 27,
      totalVolume: 0,
      totalWeight: 0,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    },
    {
      id: "5eca085b-58b4-4c7f-a0ad-e75b5f9cb079",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      orderCode: "PO1001346180109014",
      businessAccountId: null,
      businessAccountCode: null,
      businessAccountName: null,
      poTypeCode: "01",
      poTypeName: "常规采购订单",
      receiveAddressId: null,
      receiveAddressName: null,
      demandDeliveryDate: null,
      billMakerId: null,
      billMakerName: null,
      remark: null,
      orderDate: "2018-01-09 15:55:44",
      billStatusCode: "05",
      billStatusName: "已完成",
      orderDateStart: null,
      orderDateEnd: null,
      reqDeliveryDate: null,
      defaultDelyDate: null,
      totalQuantity: 1,
      totalAmount: 560,
      totalVolume: 4.45,
      totalWeight: 222,
      distributorId: null,
      distributorCode: null,
      distributorName: null,
      transportModeCode: null,
      transportModeName: "整车",
      purchaseOrderItems: null
    }
  ],
  total: 15,
  pageIndex: 1,
  pageSize: 10
};

export const orderList = (req, res, u) => {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }
  const params = getUrlParams(url);
  let dataSource = [...orderData.data];

  if (params.sorter) {
    const s = params.sorter.split("_");
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === "descend") {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.page) {
    dataSource = dataSource.filter(data => data.page.indexOf(params.page) > -1);
  }

  const result = {
    list: dataSource,
    pagination: {
      total: orderData.total,
      pageSize: orderData.pageSize,
      pageIndex: parseInt(orderData.pageIndex, 10) || 1
    }
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
};
/* 商品 */
const goodsData = {
  result: 1,
  msg: "查询成功",
  errorCode: null,
  data: [
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      productCode: "PO1001346180111001",
      name: "女装",
      specName: "90",
      shortName: "女装",
      productGroupCode: "008",
      productGroupCode: "服装",
      remark: "备注"
    },
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      productCode: "PO1001346180111002",
      name: "女装",
      specName: "90",
      shortName: "女装",
      productGroupCode: "008",
      productGroupCode: "服装",
      remark: "备注"
    },
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      productCode: "PO1001346180111003",
      name: "男装",
      specName: "90",
      shortName: "男装",
      productGroupCode: "008",
      productGroupCode: "服装",
      remark: "备注"
    },
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      transportModeId: "8b150dff-6143-4e54-aba1-9ce34183cdcf",
      productCode: "PO1001346180111004",
      name: "女装",
      specName: "90",
      shortName: "女装",
      productGroupCode: "008",
      productGroupCode: "服装",
      remark: "备注"
    }
  ],
  total: 15,
  pageIndex: 1,
  pageSize: 10
};

export const goodsList = (req, res, u) => {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }
  const params = getUrlParams(url);
  let dataSource = [...goodsData.data];

  if (params.sorter) {
    const s = params.sorter.split("_");
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === "descend") {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.page) {
    dataSource = dataSource.filter(data => data.page.indexOf(params.page) > -1);
  }

  const result = {
    list: dataSource,
    pagination: {
      total: goodsData.total,
      pageSize: goodsData.pageSize,
      pageIndex: parseInt(goodsData.pageIndex, 10) || 1
    }
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
};
/* 退货入库 */
const returnTreasuryData = {
  result: 1,
  msg: "查询成功",
  errorCode: null,
  data: [
    {
      id: "6a7c905e-c962-4cb4-9436-afe11d27366b",
      persistStatus: null,
      accountTypeId: null,
      billNo: "001",
      sourceNo: "0001",
      sourceType: "采购订单",
      stockinType: "退货入库",
      carrier: "甲",
      shipmentDate: "1992-11-11",
      exDeliveryDate: "1992-11-11",
      warehouseId: "仓库id",
      distributorId: "经销商ID",
      status: "未完成",
      comments: "备注",
      stockinCargos: "货品清单明细"
    }
  ],
  total: 15,
  pageIndex: 1,
  pageSize: 10
};

export const returnTreasuryList = (req, res, u) => {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }
  const params = getUrlParams(url);
  let dataSource = [...returnTreasuryData.data];

  if (params.sorter) {
    const s = params.sorter.split("_");
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === "descend") {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.page) {
    dataSource = dataSource.filter(data => data.page.indexOf(params.page) > -1);
  }

  const result = {
    list: dataSource,
    pagination: {
      total: returnTreasuryData.total,
      pageSize: returnTreasuryData.pageSize,
      pageIndex: parseInt(returnTreasuryData.pageIndex, 10) || 1
    }
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
};
// 调拨入库
export const allocatingStorageList = (req, res, u) => {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }
  const params = getUrlParams(url);
  let dataSource = [...returnTreasuryData.data];

  if (params.sorter) {
    const s = params.sorter.split("_");
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === "descend") {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.page) {
    dataSource = dataSource.filter(data => data.page.indexOf(params.page) > -1);
  }

  const result = {
    list: dataSource,
    pagination: {
      total: returnTreasuryData.total,
      pageSize: returnTreasuryData.pageSize,
      pageIndex: parseInt(returnTreasuryData.pageIndex, 10) || 1
    }
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
};
/* 调拨 */
const allocatingData = {
  result: 1,
  msg: "查询成功",
  errorCode: null,
  data: [
    {
      allotDate: null,
      allotDetails: [
        {
          actualQuantity: "5",
          allotCode: "33",
          allotId: "111",
          allotName: "法国",
          communityCode: "55",
          communityId: "66",
          communityName: "刚刚",
          creationTime: null,
          creator: "zz",
          dr: 0,
          id: "6hthth",
          modifiedTime: null,
          modifier: "a",
          quantity: "34343",
          ts: 0
        }
      ],
      billNo: "1232323",
      billStatus: 0,
      creationTime: "string",
      creator: "string",
      dr: 0,
      finishDate: "string",
      id: "34343",
      modifiedTime: "string",
      modifier: "string",
      ts: 0,
      warehouseCode: "string",
      warehouseId: "string",
      warehouseName: "string"
    },
    {
      allotDate: null,
      allotDetails: [
        {
          actualQuantity: "5",
          allotCode: "33",
          allotId: "111",
          allotName: "法国",
          communityCode: "55",
          communityId: "66",
          communityName: "刚刚",
          creationTime: null,
          creator: "zz",
          dr: 0,
          id: "6hthth",
          modifiedTime: null,
          modifier: "a",
          quantity: "34343",
          ts: 0
        }
      ],
      billNo: "4444444",
      billStatus: 0,
      creationTime: "string",
      creator: "string",
      dr: 0,
      finishDate: "string",
      id: "ddd",
      modifiedTime: "string",
      modifier: "string",
      ts: 0,
      warehouseCode: "string",
      warehouseId: "string",
      warehouseName: "string"
    }
  ],
  total: 2,
  pageIndex: 1,
  pageSize: 10
};
// 调拨
export const allocatingList = (req, res, u) => {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== "[object String]") {
    url = req.url; // eslint-disable-line
  }
  const params = getUrlParams(url);
  let dataSource = [...allocatingData.data];

  if (params.sorter) {
    const s = params.sorter.split("_");
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === "descend") {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.page) {
    dataSource = dataSource.filter(data => data.page.indexOf(params.page) > -1);
  }

  const result = {
    list: dataSource,
    pagination: {
      total: allocatingData.total,
      pageSize: allocatingData.pageSize,
      pageIndex: parseInt(allocatingData.pageIndex, 10) || 1
    }
  };

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
};
export default {
  getNotice,
  getActivities,
  getFakeList,
  orderList,
  goodsList,
  returnTreasuryList,
  allocatingStorageList,
  allocatingList
};
