import React, { useState } from "react";
import Taro from "@tarojs/taro";
import { Tab, Tabs, Search } from "@antmjs/vantui";
import Page from "@/layouts/index";
import PowerList from "@/components/PowerList";
import Card from "@/components/IssueCard";
import { getTaOrgIssue } from "@/services/taorgissue";
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",
};

const sid1 = Math.random().toString(36).substring(2, 8);
const sid2 = Math.random().toString(36).substring(2, 8);

export default (props) => {
  const router = Taro.useRouter();
  const { title, bizStatus, color } = router.params;
  const [issueId, setIssueId] = useState("");

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

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

  const [param1, param2] = React.useMemo(() => {
    return [
      { bizStatus, sourceType: "inspector" ,issueId},
      { bizStatus, sourceType: "feedback" },
    ];
  }, [bizStatus, issueId]);

  const onClick = (item) => {
    Taro.navigateTo({
      url: `/pages/org/issue/detail/index?id=${item.issueId}`,
    });
  };
  const onSearch = (e) => {
    const {value}=e.target
    console.log(value)
    setIssueId(value)
  };
  // const searchAction = (e) => {
  //   console.log("搜索");
  //   console.log(e)
  //   // setIssueId(e.target.value)
  // };
  return (
    <Page>
      <Search
        // onChange={(e) => setIssueId(e.detail)}
        placeholder="请输入问题单号"
        onSearch={onSearch}
        clearable
      />
      <Tabs sticky>
        <Tab title="督查员" style={tabStyle}>
          <PowerList
            sid={sid1}
            request={getTaOrgIssue}
            params={param1}
            renderItem={(item) => (
              <Card
                key={item.issueId}
                issue={item}
                stText={title}
                color={color}
                onClick={() => onClick(item)}
              />
            )}
          />
        </Tab>
        <Tab title="市民" style={tabStyle}>
          <PowerList
            sid={sid2}
            request={getTaOrgIssue}
            params={param2}
            renderItem={(item) => (
              <Card
                key={item.issueId}
                issue={item}
                stText={title}
                color={color}
                onClick={() => onClick(item)}
              />
            )}
          />
        </Tab>
      </Tabs>
    </Page>
  );
};
