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_MANAGER } from '@/utils/user';
import { useModel } from '@/store';
import { getIssueStatus } from '@/utils/biz';

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

export default (props) => {
  const router = Taro.useRouter();
  const { title, bizStatus = '', mine = '' } = router.params;

  React.useMemo(() => {
    if (title) {
      Taro.setNavigationBarTitle({ title });
    } else {
      Taro.setNavigationBarTitle({ title: '问题列表' });
    }
  }, [title]);

  const { user } = useModel('user');

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

  return (
    <Page>
      <Tabs sticky>
        <Tab title="督查员" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ bizStatus, mine, sourceType: 'inspector' }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
        <Tab title="市民" style={tabStyle}>
          <PowerList
            request={getTaIssue}
            params={{ bizStatus, mine, sourceType: 'feedback' }}
            renderItem={(item) => (
              <Card key={item.issueId} issue={item} onClick={() => onClick(item)} />
            )}
          />
        </Tab>
      </Tabs>
    </Page>
  )
}
