import React from 'react';
import { LocaleProvider } from 'antd';
import { Redirect, Route, routerRedux, Switch } from 'dva/router';
import dynamic from 'dva/dynamic';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import App from './routes/app';

const { ConnectedRouter } = routerRedux;


const Routers = ({ history, app }) => {
  const error = dynamic({
    app,
    component: () => import('./routes/common/error/404'),
  });
  const routes = [{
    path: '/login',
    models: () => [import('./models/common/login')],
    component: () => import('./routes/common/login/'),
  }, {
    path: '/600',
    component: () => import('./routes/common/error/600'),
  }, {
    path: '/dashboard',
    models: () => [import('./models/common/dashboard')],
    component: () => import('./routes/dashboard/'),
  }, {
    path: '/forgetPW',
    models: () => [import('./models/common/forgetPW')],
    component: () => import('./routes/common/password/forgetPW'),
  }, {
    path: '/manual',
    models: () => [],
    component: () => import('./routes/common/faq/manual'),
  }, {
    path: '/changePW',
    models: () => [import('./models/common/changePW')],
    component: () => import('./routes/common/password/changePW'),
  }, {
    path: '/changeInfo',
    models: () => [import('./models/common/changeInfo')],
    component: () => import('./routes/common/personal/changeInfo'),
  }, {
    path: '/register',
    models: () => [import('./models/common/register')],
    component: () => import('./routes/common/register'),
  }, {
    path: '/sys/users',
    models: () => [
      import('./models/sys/users'),
      import('./models/sys/users/suppUser'),
      import('./models/sys/users/entUser'),
      import('./models/sys/users/dpowerModalModel')],
    component: () => import('./routes/sys/users'),
  }, {
    path: '/sys/roles',
    models: () => [import('./models/sys/roles')],
    component: () => import('./routes/sys/roles'),
  }, {
    path: '/sys/udcs',
    models: () => [import('./models/sys/udcs'), import('./models/sys/udcItems')],
    component: () => import('./routes/sys/udcs'),
  }, {
    path: '/sys/reminders',
    models: () => [import('./models/sys/reminders')],
    component: () => import('./routes/sys/reminders'),
  }, {
    path: '/sys/logs',
    models: () => [import('./models/sys/logs')],
    component: () => import('./routes/sys/logs'),
  }, {
    path: '/sys/definitions',
    models: () => [import('./models/sys/definitions')],
    component: () => import('./routes/sys/definitions'),
  }, {
    path: '/sys/instances',
    models: () => [import('./models/sys/instances')],
    component: () => import('./routes/sys/instances'),
  }, {
    path: '/sys/bpm-roles',
    models: () => [import('./models/sys/bpmRoles')],
    component: () => import('./routes/sys/bpmRoles'),
  }, {
    path: '/sys/bpm-faults',
    models: () => [import('./models/sys/bpmFaults')],
    component: () => import('./routes/sys/bpmFaults'),
  }, {
    path: '/mdata/ou',
    models: () => [import('./models/mdata/operationUnit')],
    component: () => import('./routes/mdata/operationUnit'),
  }, {
    path: '/mdata/org',
    models: () => [import('./models/mdata/organization')],
    component: () => import('./routes/mdata/organization'),
  }, {
    path: '/mdata/emp',
    models: () => [import('./models/mdata/employee')],
    component: () => import('./routes/mdata/employee'),
  }, {
    path: '/cooperate/finance/soa',
    models: () => [import('./models/cooperate/finance/account')],
    component: () => import('./routes/cooperate/finance/account'),
  }, {
    path: '/cooperate/finance/soa/:id',
    models: () => [import('./models/cooperate/finance/accountBillList'), import('./models/cooperate/finance/accountDetails')],
    component: () => import('./routes/cooperate/finance/page'),
  }, {
    path: '/cooperate/finance/s-invoice',
    models: () => [import('./models/cooperate/finance/pfInvoice')],
    component: () => import('./routes/cooperate/finance/pfInvoice'),
  }, {
    path: '/cooperate/finance/s-invoice/:id',
    models: () => [import('./models/cooperate/finance/pfInvoiceDetails'),import('./models/cooperate/finance/invoiceModal')],
    component: () => import('./routes/cooperate/finance/pfInvoiceDetails'),
  }, {
    path: '/cooperate/finance/offi-invoice',
    models: () => [import('./models/cooperate/finance/invoice')],
    component: () => import('./routes/cooperate/finance/invoice'),
  }, {
    path: '/cooperate/finance/offi-invoice/:id',
    models: () => [import('./models/cooperate/finance/invoiceDetails')],
    component: () => import('./routes/cooperate/finance/invoiceDetails'),
  }, {
    path: '/cooperate/finance/payable',
    models: () => [import('./models/cooperate/finance/payable')],
    component: () => import('./routes/cooperate/finance/payable'),
  }, {
    path: '/cooperate/finance/payable/:id',
    models: () => [import('./models/cooperate/finance/payableDetails')],
    component: () => import('./routes/cooperate/finance/payableDetails'),
  }, {
    path: '/item-mgmt/items',
    models: () => [import('./models/item/items')],
    component: () => import('./routes/item/items'),
  }, {
    path: '/item-mgmt/itemAccess',
    models: () => [import('./models/item/itemAccess')],
    component: () => import('./routes/item/itemAccess/index'),
  }, {
    path: '/item-mgmt/itemAccess/trial',
    models: () => [import('./models/item/itemAccess')],
    component: () => import('./routes/item/itemAccess/trial'),
  }, {
    path: '/item-mgmt/items/:id',
    models: () => [import('./models/item/itemDetail')],
    component: () => import('./routes/item/itemDetail'),
  }, {
    path: '/item-mgmt/itemTrial/:id',
    models: () => [import('./models/item/itemTrial')],
    component: () => import('./routes/item/itemTrial/page'),
    // }, {
    //   path: '/item-mgmt/prices',
    //   models: () => [import('./models/item/prices')],
    //   component: () => import('./routes/item/prices'),
    // }, {
    //   path: '/item-mgmt/referprices',
    //   models: () => [import('./models/item/prices')],
    //   component: () => import('./routes/item/referprices'),
    // }, {
    //   path: '/item-mgmt/prices/:id',
    //   models: () => [import('./models/item/priceHistory')],
    //   component: () => import('./routes/item/priceHistory'),
  }, {
    path: '/price-mgmt/prices',
    models: () => [import('./models/item/prices')],
    component: () => import('./routes/item/prices'),
  }, {
    path: '/price-mgmt/referprices',
    models: () => [import('./models/item/referprices')],
    component: () => import('./routes/item/referprices'),
  }, {
    path: '/price-mgmt/prices/:id',
    models: () => [import('./models/item/priceHistory')],
    component: () => import('./routes/item/priceHistory'),
  }, {
    path: '/lifecycle/supp-mgmt',
    models: () => [import('./models/supplier/suppliers')],
    component: () => import('./routes/supplier/suppliers'),
  }, {
    path: '/lifecycle/supp-mgmt-flow',
    models: () => [import('./models/supplier/supplierDetail')],
    component: () => import('./routes/supplier/supplierDetail/flow'),
  }, {
    path: '/lifecycle/supp-mgmt/:id',
    models: () => [import('./models/supplier/supplierDetail')],
    component: () => import('./routes/supplier/supplierDetail'),
  }, {
    path: '/lifecycle/supp-mgmt/adjust/:id',
    models: () => [import('./models/supplier/supplierAdjust')],
    component: () => import('./routes/supplier/supplierDetail/supplierAdjust'),
  }, {
    path: '/lifecycle/inviteSupp',
    models: () => [import('./models/supplier/inviteSupp')],
    component: () => import('./routes/supplier/supplierDetail/inviteSupp'),
  }, {
    path: '/lifecycle/qualify/:id',
    models: () => [import('./models/supplier/qualify')],
    component: () => import('./routes/supplier/supplierDetail/qualify'),
  }, {
    path: '/lifecycle/supp-performance',
    models: () => [import('./models/supplier/performances')],
    component: () => import('./routes/supplier/performances/list'),
  }, {
    path: '/lifecycle/supp-performance/:id',
    models: () => [import('./models/supplier/performanceDetail')],
    component: () => import('./routes/supplier/performances/detail'),
  }, {
    path: '/supps/performances',
    models: () => [import('./models/supplier/supplierLifeStyle')],
    component: () => import('./routes/supplier/supplierLifeStyle/list'),
  }, {
    path: '/supps/performances/:id',
    models: () => [import('./models/supplier/supplierLifeStyleDetail')],
    component: () => import('./routes/supplier/supplierLifeStyle/detail'),
  },{
    path: '/cooperate/quality/co',
    models: () => [import('./models/quality/co/claimOrders')],
    component: () => import('./routes/quality/co/claimOrders'),
  }, {
    path: '/cooperate/quality/co/:id',
    models: () => [import('./models/quality/co/detail')],
    component: () => import('./routes/quality/co/detail'),
  }, {
    path: '/quality/edo',
    models: () => [import('./models/quality/ed/ed')],
    component: () => import('./routes/quality/ed/ed'),
  }, {
    path: '/source-mgmt/qo/iqo',
    models: () => [import('./models/source/inquiry/inquiry')],
    component: () => import('./routes/source/inquiry/inquiry'),
  }, {
    path: '/source-mgmt/qo/iqo/:id',
    models: () => [import('./models/source/inquiry/inquiryDetails')],
    component: () => import('./routes/source/inquiry/inquiryDetails'),
  }, {
    path: '/source-mgmt/qo/qo/items',
    models: () => [import('./models/source/quote/quoteItems')],
    component: () => import('./routes/source/quote/quoteItems'),
  }, {
    path: '/source-mgmt/qo/qo',
    models: () => [import('./models/source/quote/quote')],
    component: () => import('./routes/source/quote/quote'),
  }, {
    path: '/source-mgmt/qo/price',
    models: () => [import('./models/source/quote/quoteDetails')],
    component: () => import('./routes/source/quote/quoteDetails'),
  }, {
    path: '/source-mgmt/qo/compare/audit',
    models: () => [import('./models/source/compare/compareAudit')],
    component: () => import('./routes/source/compare/compareAudit'),
  }, {
    path: '/source-mgmt/qo/compare/detail',
    models: () => [import('./models/source/compare/compareDetail')],
    component: () => import('./routes/source/compare/compareDetail'),
  }, {
    path: '/source-mgmt/bid-mgmt/tenders/tenders',
    models: () => [import('./models/source/tender/tenders')],
    component: () => import('./routes/source/tender/tenders'),
  }, {
    path: '/source-mgmt/bid-mgmt/tenders/tenders/:id',
    models: () => [import('./models/source/tender/tendersDetails'), import('./models/source/tender/tendersDetailsSupp')],
    component: () => import('./routes/source/tender/tendersDetails'),
  }, {
    path: '/source-mgmt/bid-mgmt/bids/bids',
    models: () => [import('./models/source/bid/bids')],
    component: () => import('./routes/source/bid/bids'),
  }, {
    path: '/source-mgmt/bid-mgmt/bidGroup',
    models: () => [import('./models/source/bidGroup/bidGroup')],
    component: () => import('./routes/source/bidGroup/bidGroup'),
  }, {
    path: '/source-mgmt/bid-mgmt/bidGroup/:id',
    models: () => [import('./models/source/bidGroup/bidGroupDetail')],
    component: () => import('./routes/source/bidGroup/bidGroupDetail'),
  }, {
    path: '/source-mgmt/bid-mgmt/bids/bids/:id',
    models: () => [import('./models/source/bid/bidsDetails')],
    component: () => import('./routes/source/bid/bidsDetails'),
  }, {
    path: '/source-mgmt/bid-mgmt/exam',
    models: () => [import('./models/source/exam/exams')],
    component: () => import('./routes/source/exam/exams'),
  }, {
    path: '/source-mgmt/bid-mgmt/exam/:id',
    models: () => [import('./models/source/exam/examsDetails')],
    component: () => import('./routes/source/exam/examsDetails'),
  }, {
    // 评标审核
    path: '/source-mgmt/bid-mgmt/tender-review/:id',
    models: () => [import('./models/source/tender-review/review')],
    component: () => import('./routes/source/tender-review/review'),
  }, {
    // 评标结果
    path: '/source-mgmt/bid-mgmt/tender-result/:id',
    models: () => [import('./models/source/tender-review/result')],
    component: () => import('./routes/source/tender-review/result'),
  }, {
    path: '/reports/total',
    models: () => [import('./models/reports/purchaseTotalFee')],
    component: () => import('./routes/reports/purchaseTotalFee/'),
  }, {
    path: '/reports/counts',
    models: () => [import('./models/reports/purchaseTotal')],
    component: () => import('./routes/reports/purchaseTotal/'),
  }, {
    path: '/reports/prices',
    models: () => [import('./models/reports/priceCompare')],
    component: () => import('./routes/reports/priceCompare/'),
  }, {
    path: '/reports/timings',
    models: () => [import('./models/reports/deliver')],
    component: () => import('./routes/reports/deliver/'),
  }, {
    path: '/reports/faults',
    models: () => [import('./models/reports/defective')],
    component: () => import('./routes/reports/defective/'),
  }, {
    path: '/messages/public',
    models: () => [import('./models/message/public')],
    component: () => import('./routes/message/public/'),
  }, {
    path: '/messages/notification',
    models: () => [import('./models/message/notification')],
    component: () => import('./routes/message/notification/'),
  }, {
    path: '/messages/advise',
    component: () => import('./routes/message/advise/'),
  }, {
    path: '/plan-mgmt/requirement-mgmt',
    models: () => [import('./models/plan/requirement')],
    component: () => import('./routes/plan/'),
  }, {
    path: '/cooperate/order/po',
    models: () => [import('./models/cooperate/order/purchasingOrder')],
    component: () => import('./routes/cooperate/order/purchasingOrder'),
  }, {
    path: '/cooperate/order/po/:id',
    models: () => [import('./models/cooperate/order/purchasingOrderDetails')],
    component: () => import('./routes/cooperate/order/purchasingOrderDetails'),
  }, {
    path: '/cooperate/order/sio',
    models: () => [import('./models/cooperate/order/stockInOrder')],
    component: () => import('./routes/cooperate/order/stockInOrder'),
  }, {
    //   path: '/cooperate/order/sio/:id',
    //   models: () => [import('./models/cooperate/order/stockInOrderDetails')],
    //   component: () => import('./routes/cooperate/order/stockInOrderDetails'),
    // }, {
    path: '/cooperate/order/ro',
    models: () => [import('./models/cooperate/order/returnOrder')],
    component: () => import('./routes/cooperate/order/returnOrder'),
  }, {
    path: '/cooperate/order/ro/:id',
    models: () => [import('./models/cooperate/order/returnOrderDetails')],
    component: () => import('./routes/cooperate/order/returnOrderDetails'),
  }, {
    path: '/cooperate/order/ppo',
    models: () => [import('./models/cooperate/order/prepayorder/list')],
    component: () => import('./routes/cooperate/order/prepayorder/list'),
  }, {
    path: '/cooperate/order/ppo/:id',
    models: () => [import('./models/cooperate/order/prepayorder/detail')],
    component: () => import('./routes/cooperate/order/prepayorder/detail'),
  }, {
    path: '/cooperate/order/pyo',
    models: () => [import('./models/cooperate/order/payorder/list')],
    component: () => import('./routes/cooperate/order/payorder/list'),
  }, {
    path: '/cooperate/order/pyo/:id',
    models: () => [import('./models/cooperate/order/payorder/detail')],
    component: () => import('./routes/cooperate/order/payorder/detail'),
  }, {
    path: '/contract-mgmt/contracts',
    models: () => [import('./models/contract-mgmt/contracts/contracts')],
    component: () => import('./routes/contract-mgmt/contracts/contracts'),
  }, {
    path: '/contract-mgmt/contracts/:id',
    models: () => [import('./models/contract-mgmt/contracts/contractDetail')],
    component: () => import('./routes/contract-mgmt/contracts/contractDetail'),
  }, {
    path: '/contract-mgmt/contract-tmpls',
    models: () => [import('./models/contract-mgmt/contract-tmpls/contractTmpls')],
    component: () => import('./routes/contract-mgmt/contract-tmpls/contractTmpls'),
  }, {
    path: '/contract-mgmt/contract-tmpls/:id',
    models: () => [import('./models/contract-mgmt/contract-tmpls/contractTmplDetail')],
    component: () => import('./routes/contract-mgmt/contract-tmpls/contractTmplDetail'),
  }, {
    path: '/quality/edo/:id',
    models: () => [import('./models/quality/ed/edDetail')],
    component: () => import('./routes/quality/ed/detail'),
  }, {
    path: '/dev',
    // models: () => [import('./models/quality/ed/edDetail')],
    component: () => import('./routes/dev/index'),
  }, {
    path: '/dev/components',
    models: () => [import('./models/dev/components')],
    component: () => import('./routes/dev/components'),
  }, {
    path: '/dev/form',
    models: () => [import('./models/dev/form')],
    component: () => import('./routes/dev/page'),
  }, {
    path: '/deploy',
    models: () => [import('./models/deploy/account/account')],
    component: () => import('./routes/deploy/index'),
  }, {
    path: '/price-mgmt/adjust',
    models: () => [import('./models/item/priceList')],
    component: () => import('./routes/item/priceAdjust/index'),
  }, {
    path: '/price-mgmt/adjust/:id',
    models: () => [import('./models/item/priceAdjust')],
    component: () => import('./routes/item/priceAdjust/page'),
  }, {
    path: '/report/itemprice',
    models: () => [import('./models/reports/itemprice')],
    component: () => import('./routes/reports/itemprice/'),
  }, {
    path: '/report/priceanalyse',
    models: () => [import('./models/reports/priceanalyse')],
    component: () => import('./routes/reports/priceanalyse/'),
  }, {
    path: '/report/recpstatistics',
    models: () => [import('./models/reports/recpstatistics')],
    component: () => import('./routes/reports/recpstatistics/'),
  }, {
    path: '/report/accreceivable',
    models: () => [import('./models/reports/accreceivable')],
    component: () => import('./routes/reports/accreceivable/'),
  }, {
    path: '/report/supplist',
    models: () => [import('./models/reports/supplist')],
    component: () => import('./routes/reports/supplist/'),
  }];

  return (
    <ConnectedRouter history={history}>
      <LocaleProvider locale={zh_CN}>
        <App>
          <Switch>
            <Route exact={true} path="/" render={() => (<Redirect to="/dashboard"/>)}/>
            {
              routes.map(({ path, ...dynamics }, key) => (
                <Route
                  key={key}
                  exact={true}
                  path={path}
                  component={dynamic({
                    app,
                    ...dynamics,
                  })}
                />
              ))}
            <Route component={error}/>
          </Switch>
        </App>
      </LocaleProvider>
    </ConnectedRouter>
  );
};


export default Routers;
