import React from 'react';
import Taro from '@tarojs/taro';
import { View } from '@tarojs/components';
import { Tab, Tabs } from '@antmjs/vantui';
import Page from '@/layouts/index';
import PowerList from '@/components/PowerList';
import Card from '@/components/IssueCard';
import { getTaIssue } from '@/services/taissue';
import { ROLE_INSPECTOR, ROLE_MANAGER } from '@/utils/user';
import { getIssueStatus, PROCESS_ASSIGNED, PROCESS_END, PROCESS_START } from '@/utils/biz';

const tabStyle = {
  overflow: 'hidden',
  height: 'calc(100vh - 45px)',
  overflow: 'hidden',
}

// 只有督查员能看到当前页面
export default (props) => {
  // const { user } = useModel('user');

  const router = Taro.useRouter();
  const { mine = '' } = router.params;

  const onClick = (item) => {
    Taro.navigateTo({
      url: `/pages/issue/edit/index?id=${item.issueId}`
    })
  }

  return (
    <Page roles={[ROLE_INSPECTOR]}>
      <Tabs sticky>
        <Tab title="全部" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="未交办" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine, bizStatus: PROCESS_START }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="已交办" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine, bizStatus: PROCESS_ASSIGNED }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="已办结" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine, bizStatus: PROCESS_END }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="已逾期" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine, bizStatus: 'expired' }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="已打回" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ mine, bizStatus: 'reject' }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
      </Tabs>
    </Page>
  )
}
