import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Button, Space } from "antd";
import Page from "zy-react-library/components/Page";
import Search from "zy-react-library/components/Search";
import Table from "zy-react-library/components/Table";
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
import useTable from "zy-react-library/hooks/useTable";
import { NS_VEHICLE_APPLY } from "~/enumerate/namespace";


function List(props) {
  const query = useGetUrlQuery();
  const [form] = Search.useForm();
  const { tableProps, getData } = useTable(props["vehicleApplyList"], {
    form,
    params: { vehicleCorpId: query.id, vehicleBelongType: 5 },
  });

  return (
    <Page headerTitle="车辆列表">
      <Search
        labelCol={{ span: 4 }}
        options={[
          { name: "licenceNo", label: "车牌号" },
        ]}
        onFinish={getData}
        form={form}
      />
      <Table
        columns={[
          { title: "车辆类型", dataIndex: "vehicleTypeName" },
          { title: "车牌类型", dataIndex: "licenceTypeName" },
          { title: "车牌号", dataIndex: "licenceNo" },
          { title: "驾驶人姓名", dataIndex: "employeeVehicleUserName" },
          { title: "驾驶人手机号", dataIndex: "lsUserPhone" },
          {
            title: "口门权限",
            dataIndex: "gateLevelAuthArea",
            render:(_,record) =>{
              const authorizationArea = typeof record.gateLevelAuthArea === "string"
                ? JSON.parse(record.gateLevelAuthArea)
                : record.gateLevelAuthArea;
              console.log(Array.isArray(authorizationArea?.area));
              return Array.isArray(authorizationArea?.area)
                ? authorizationArea.area.map(item => item.value).filter(Boolean).join("\u3001") || "-"
                : "-";
            } ,
          },
          {
            title: "操作",
            width: 200,
            fixed: "right",
            render: (_, record) => (
              <Space>
                <Button
                  type="link"
                  onClick={() => {
                    props.history.push(`./inAndOutRecords?licenceNo=${record.licenceNo}`);
                  }}
                >
                  车辆进出记录
                </Button>
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

export default Connect([NS_VEHICLE_APPLY], true)(List);
