import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { message } from "antd";
import FormBuilder from "zy-react-library/components/FormBuilder";
import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
import { NS_ENCLOSED_AREA_VEHICLE_APPLY } from "~/enumerate/namespace";
import ViewPage from "~/pages/Container/Supervision/EnclosedArea/Apply/Vehicle/View";

function Review(props) {
  const query = useGetUrlQuery();
  const [form] = FormBuilder.useForm();

  const onSubmit = async (values) => {
    const { success } = await props["enclosedAreaVehicleApplyReviewSubmit"]({
      ...values,
      id: query.id,
    });
    if (success) {
      message.success("提交成功");
      props.history.goBack();
    }
  };

  return (
    <ViewPage
      headerTitle="审核"
      entrance={query.entrance}
      isShowFooter={false}
      {...props}
    >
      <FormBuilder
        style={{ marginTop: 20 }}
        span={24}
        onFinish={onSubmit}
        values={{
          auditFlag: "2",
        }}
        loading={props.enclosedAreaVehicleApply.enclosedAreaVehicleApplyLoading}
        options={[
          {
            name: "auditFlag",
            label: "是否通过审核",
            render: FORM_ITEM_RENDER_ENUM.RADIO,
            items: [{ bianma: "2", name: "是" }, { bianma: "3", name: "否" }],
          },
          {
            name: "refusalReason",
            label: "驳回原因",
            render: FORM_ITEM_RENDER_ENUM.TEXTAREA,
            dependencies: ["auditFlag"],
            hidden: formValues => !(formValues.auditFlag === "3"),
          },
        ]}
        form={form}
      />
    </ViewPage>
  );
}

export default Connect([NS_ENCLOSED_AREA_VEHICLE_APPLY], true)(Review);
