import Mock from 'mockjs'

function fakeSuccess() {
  return {code: 200, success: true, msg: '操作成功'};
}
let Random = Mock.Random;

export default ({mock}) => {
  if (!mock) return;
  //获取表格数据
  Mock.mock(/\/api\/jobslink-system\/insure\/list[.]*?/, 'get', () => {
    const json = {code: 200, success: true, msg: '操作成功'};
    const list = [];
    for (let i = 0; i < 5; i++) {
      list.push(Mock.mock({
        insureName: '@increment',
        insureNo: '@increment',
        companyName: Mock.mock('@cname'),
        manager: Mock.mock('@cname'),
        'quantity|1-99': 1,
        'percent|0.1-99': 0.1,
        'status|0-1': 1,
        'orderStatus|0-1': 1,
        payOrderId: i % 2 ? undefined : 1,
        stime: Random.datetime(''),
        etime: Random.datetime('yyyy-MM-dd')
      }))
    }
    list.push(Mock.mock({
      insureName: '@increment',
      insureNo: '@increment',
      companyName: Mock.mock('@cname'),
      manager: Mock.mock('@cname'),
      'quantity|1-99': 1,
      'percent|0.1-99': 0.1,
      'status|0-1': 1,
      'orderStatus|0-1': 1,
      payOrderId: 1,
      stime: '1999-1-1',
      etime: '2099-1-1'
    }))
    list.push(Mock.mock({
      insureName: '@increment',
      insureNo: '@increment',
      companyName: Mock.mock('@cname'),
      manager: Mock.mock('@cname'),
      'quantity|1-99': 1,
      'percent|0.1-99': 0.1,
      'status|0-1': 1,
      'orderStatus|0-1': 1,
      payOrderId: 1,
      stime: '2999-1-1',
      etime: '3099-1-1'
    }))
    list.push(Mock.mock({
      insureName: '@increment',
      insureNo: '@increment',
      companyName: Mock.mock('@cname'),
      manager: Mock.mock('@cname'),
      'quantity|1-99': 1,
      'percent|0.1-99': 0.1,
      'status|0-1': 1,
      'orderStatus|0-1': 1,
      payOrderId: 1,
      stime: '1999-1-1',
      etime: '1099-2-1'
    }))
    json.data = {
      total: 10,
      size: 10,
      current: 1,
      searchCount: true,
      pages: 1,
      records: list,
    };
    return json;
  })

  Mock.mock(/\/api\/jobslink-system\/insure\/detail/, 'get', () => {
    const json = {code: 200, success: true, msg: '操作成功'};

    json.data = Mock.mock({
      id: '@increment',
      stationId: '@increment',
      companyName: Mock.mock('@cname'),
      manager: Mock.mock('@cname'),
      'telphone|11': '1',
      'percent|0.1-99': 0.1,
      'status|1-4': 1,
      'companyTid|18': '2',
      masterName: Mock.mock('@cname'),
      'masterIdentity|18': '1',
      'cityId': 12,
      companyAddress: Random.county(true),
      authUrlId:
          'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1906469856,4113625838&fm=26&gp=0.jpg',
      identityUrl4Id:
          'https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2534506313,1688529724&fm=26&gp=0.jpg',
      identityUrl5Id:
          'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1035415831,1465727770&fm=26&gp=0.jpg'
    });
    return json;
  })

  Mock.mock(/\/api\/jobslink-system\/insure\/submit/, 'post', fakeSuccess);
}
