index.jsx 17.8 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
import AutoTable from "@/components/AutoTable";
import DraggableDialog from "@/components/DraggableDialog";
import ImportExcel from "@/components/ImportExcel";
import InitForm from "@/components/InitForm";
import PremButton from "@/components/PremButton";
import SplitDesc from "@/components/SplitDesc";
import { doFetch } from "@/utils/doFetch";
import { ProDescriptions } from "@ant-design/pro-components";
import { Box, Container, Stack, Typography } from "@mui/material";
import { useRequest } from "ahooks";
import { Image, message, Switch, Tabs } from "antd";
import { useMemo, useRef, useState } from "react";
import "./index.less";

function Student() {
  const actionRef = useRef(),
    actionRefs = useRef();
  const [dialogprops, setdialogprops] = useState({
    open: false,
  });
  const [active, setactive] = useState("1");

  const handleClose = () => {
    setdialogprops((s) => ({
      ...s,
      open: false,
    }));
  };

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, parames) => {
      if (res?.code == "0000") {
        handleClose();
        message.success("操作成功");
        if (active === "1") {
          actionRef?.current?.reload();
        } else {
          actionRefs?.current?.reload();
        }
      }
    },
  });

  const add = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: "是否删重置密码?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            e.stopPropagation();
            runAsync({
              url: "/user/resetUserPassword",
              params: { id: row?.id },
            });
          },
        }}
        btn={{
          size: "small",
          style: { color: "#000" },
        }}
      >
        重置密码
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: "small",
          variant: "text",
          onClick: () => {
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "编辑",
            });
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: "是否删除该学生?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
              url: "/user/delete",
              params: { id: row.id },
            });
          },
        }}
        btn={{
          size: "small",
          color: "error",
        }}
      >
        删除
      </PremButton>
    );
  };

  const audit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          disabled: row.status !== 1,
          size: "small",
          variant: "text",
          onClick: () => {
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "审批",
            });
          },
        }}
      >
        审批
      </PremButton>
    );
  };

  const columns = useMemo(
    () => [
      {
        title: "头像",
        dataIndex: "pic",
        key: "pic",
        valueType: "uploadImage",
        colProps: {
          span: 24,
        },
        fieldProps: {
          limit: 1,
        },
        width: 80,
        search: false,
        render: (text, row) => {
          return (
            <Image
              src={row?.picUrl || DEFAULT_HEAD_IMG}
              fallback={DEFAULT_HEAD_IMG}
              style={{
                width: 36,
                height: 36,
                objectFit: "cover",
                borderRadius: 200,
                overflow: "hidden",
                flexShrink: 0,
              }}
            />
          );
        },
      },
      {
        title: "账号",
        dataIndex: "userAccount",
        key: "userAccount",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "姓名",
        dataIndex: "name",
        key: "name",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "手机号",
        dataIndex: "telephone",
        key: "telephone",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      { title: "邮箱", dataIndex: "email", key: "email" },
      {
        title: "学校名称",
        dataIndex: "schoolName",
        key: "schoolId",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        valueType: "select",
        options: { path: "/organization/school/selection", params: {} },
      },
      {
        title: "院系名称",
        dataIndex: "departmentName",
        key: "departmentId",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        valueType: "select",
        options: {
          path: "/organization/department/selection",
          linkParams: { schoolId: "parentId" },
        },
      },
      {
        title: "班级名称",
        dataIndex: "className",
        key: "classId",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        valueType: "select",
        options: {
          path: "/class/selection",
          linkParams: {
            departmentId: "",
          },
        },
      },
      {
        title: "创建时间",
        dataIndex: "createTime",
        key: "createTimeRange",
        valueType: "dateRange",
        hideInForm: true,
      },
      {
        title: "启用状态",
        dataIndex: "statusName",
        key: "status",
        valueType: "select",
        options: [
          { label: "启用", value: "1" },
          { label: "禁用", value: "2" },
        ],
        hideInForm: true,
        render: (text, row) => {
          return (
            <Switch
              checkedChildren={["启用"]}
              unCheckedChildren={["禁用"]}
              defaultChecked={row.status === 1}
              onChange={(e) => {
                doFetch({
                  url: "/user/changeStatus",
                  params: { id: row.id, status: e ? 1 : 2 },
                });
              }}
            />
          );
        },
      },
    ],
    []
  );

  const detailcolumns = [
    {
      title: "申请信息",
      dataIndex: "sort",
      key: "sort",
      valueType: "split",
    },
    [
      {
        title: "账号",
        dataIndex: "userAccount",
        key: "userAccount",
      },
      {
        title: "姓名",
        dataIndex: "name",
        key: "name",
      },
      {
        title: "手机号",
        dataIndex: "telephone",
        key: "telephone",
      },
      { title: "邮箱", dataIndex: "email", key: "email" },
      {
        title: "学校名称",
        dataIndex: "schoolName",
        key: "schoolId",
      },
      {
        title: "院系名称",
        dataIndex: "departmentName",
        key: "departmentId",
      },
      {
        title: "申请时间",
        dataIndex: "applyTime",
        key: "applyTimeRange",
      },
      {
        title: "申请状态",
        dataIndex: "statusName",
        key: "status",
        valueType: "select",
        options: [
          {
            label: "待审核",
            value: "1",
          },
          {
            label: "已审核",
            value: "2",
          },
        ],
      },
    ],
    {
      title: "审核信息",
      dataIndex: "sort",
      key: "sort",
      valueType: "split",
    },
    [
      {
        title: "审批结果",
        dataIndex: "examineResultName",
        key: "examineResultName",
      },
      {
        title: "审核时间",
        dataIndex: "examineTime",
        key: "examineTime",
      },
      {
        title: "审核人",
        dataIndex: "examineUserName",
        key: "examineUserName",
      },
      {
        title: "审核意见",
        dataIndex: "examineAdvice",
        key: "examineAdvice",
        span: 3,
      },
    ],
  ];

  const columes = useMemo(() => {
    return [
      // {
      //   title: "头像",
      //   dataIndex: "pic",
      //   key: "pic",
      //   valueType: "uploadImage",
      //   colProps: {
      //     span: 24,
      //   },
      //   fieldProps: {
      //     limit: 1,
      //   },
      //   width: 80,
      //   search: false,
      //   hideInDescriptions: true,
      //   render: (text, row) => {
      //     return (
      //       <Image
      //         src={row?.picUrl || DEFAULT_HEAD_IMG}
      //         style={{
      //           width: 36,
      //           height: 36,
      //           objectFit: "cover",
      //           borderRadius: 200,
      //           overflow: "hidden",
      //           flexShrink: 0,
      //         }}
      //       />
      //     );
      //   },
      // },
      {
        title: "账号",
        dataIndex: "userAccount",
        key: "userAccount",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        render: (text, row) => {
          return (
            <a
              onClick={() => {
                setdialogprops({
                  open: true,
                  defaultFormValue: { ...row },
                  title: "详情",
                  maxWidth: "md",
                  footer: false,
                });
              }}
            >
              {text}
            </a>
          );
        },
      },
      {
        title: "姓名",
        dataIndex: "name",
        key: "name",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "手机号",
        dataIndex: "telephone",
        key: "telephone",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      { title: "邮箱", dataIndex: "email", key: "email" },
      {
        title: "学校名称",
        dataIndex: "schoolName",
        key: "schoolId",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        valueType: "select",
        options: { path: "/organization/school/selection", params: {} },
      },
      {
        title: "院系名称",
        dataIndex: "departmentName",
        key: "departmentId",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        valueType: "select",
        options: {
          path: "/organization/department/selection",
          linkParams: { schoolId: "parentId" },
        },
      },
      // {
      //   title: "班级名称",
      //   dataIndex: "className",
      //   key: "classId",
      //   formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      //   valueType: "select",
      //   options: {
      //     path: "/class/selection",
      //     linkParams: {
      //       departmentId: "",
      //     },
      //   },
      // },
      {
        title: "申请时间",
        dataIndex: "applyTime",
        key: "applyTimeRange",
        valueType: "dateRange",
        hideInDescriptions: true,
      },
      {
        title: "申请状态",
        dataIndex: "statusName",
        key: "status",
        valueType: "select",
        options: [
          {
            label: "待审核",
            value: "1",
          },
          {
            label: "已审核",
            value: "2",
          },
        ],
        hideInDescriptions: true,
      },
      {
        title: "审核结果",
        dataIndex: "examineResultName",
        key: "examineResult",
        valueType: "select",
        options: [
          {
            label: "通过",
            value: "1",
          },
          {
            label: "不通过",
            value: "2",
          },
        ],
        hideInDescriptions: true,
      },
    ];
  }, []);

  const items = [
    {
      key: "1",
      label: `正式用户`,
      children: (
        <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
          <AutoTable
            actionRef={actionRef}
            scroll={{ x: 1366 }}
            columns={[
              ...columns,
              {
                title: "操作",
                valueType: "option",
                width: 200,
                render: (text, row, _, action) => [
                  add(text, row, _, action),
                  edit(text, row, _, action),
                  remove(text, row, _, action),
                ],
              },
            ]}
            extraparams={{ type: "3" }}
            path="/user/page"
            rerendered={false}
          ></AutoTable>
        </Box>
      ),
    },
    {
      key: "2",
      label: `学生认证申请`,
      children: (
        <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
          <AutoTable
            actionRef={actionRefs}
            scroll={{ x: 1366 }}
            columns={[
              ...columes,
              {
                title: "操作",
                valueType: "option",
                width: 88,
                render: (text, row, _, action) => [audit(text, row, _, action)],
              },
            ]}
            path="/studentApply/page"
            rerendered={false}
          ></AutoTable>
        </Box>
      ),
    },
  ];

  return (
    <Container maxWidth={false}>
      <DraggableDialog
        handleClose={handleClose}
        loading={loading}
        dialogprops={dialogprops}
        maxWidth={dialogprops?.maxWidth ?? "sm"}
        formdom={
          dialogprops?.title === "审批" && (
            <InitForm
              fields={[
                {
                  title: "审核信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
                },
                {
                  title: "审批结果",
                  dataIndex: "examineResult",
                  key: "examineResult",
                  valueType: "radio",
                  options: [
                    { label: "认证通过", value: "1" },
                    { label: "驳回", value: "2" },
                  ],
                  colProps: { span: 24 },
                },
                {
                  title: "审核意见",
                  dataIndex: "examineAdvice",
                  key: "examineAdvice",
                  colProps: { span: 24 },
                  valueType: "textarea",
                },
              ]}
              defaultFormValue={{ examineResult: "1" }}
              onFinish={(val, extra) => {
                let postdata = {
                  ...val,
                  id: dialogprops?.defaultFormValue?.id,
                };
                runAsync({
                  url: "/studentApply/review",
                  params: postdata,
                });
              }}
            ></InitForm>
          )
        }
      >
        {dialogprops?.title === "审批" ? (
          <ProDescriptions
            columns={columes}
            column={2}
            style={{ marginBottom: 12 }}
            dataSource={dialogprops?.defaultFormValue}
          ></ProDescriptions>
        ) : dialogprops?.title === "详情" ? (
          <Stack
            direction={"column"}
            alignItems={"center"}
            justifyContent={"center"}
            gap={1}
          >
            {/* <Image
              src={dialogprops?.defaultFormValue?.picUrl || DEFAULT_HEAD_IMG}
              fallback={DEFAULT_HEAD_IMG}
              style={{
                width: 88,
                height: 88,
                objectFit: "cover",
                borderRadius: 200,
                overflow: "hidden",
                flexShrink: 0,
              }}
            />
            <Box height={12}></Box> */}
            <SplitDesc
              columns={detailcolumns}
              dataSource={dialogprops?.defaultFormValue}
            ></SplitDesc>
          </Stack>
        ) : (
          <InitForm
            fields={columns}
            defaultFormValue={dialogprops?.defaultFormValue}
            onFinish={(val, extra) => {
              let postdata = { ...val, type: "3" };
              switch (dialogprops?.title) {
                case "编辑":
                  postdata = {
                    ...val,
                    id: dialogprops?.defaultFormValue?.id,
                  };
                  break;
                default:
                  break;
              }
              runAsync({
                url: "/user/saveOrUpdate",
                params: postdata,
              });
            }}
          ></InitForm>
        )}
      </DraggableDialog>

      <Box
        display={"flex"}
        justifyContent={"space-between"}
        alignItems={"center"}
        sx={{ mb: 1 }}
        mt={0}
      >
        <Typography variant="h5">学生管理</Typography>
        {active === "1" ? (
          <Stack spacing={2} direction="row">
wuhao's avatar
wuhao committed
658 659 660 661 662 663 664
             <ImportExcel
              importurl="/user/studentImport"
              downloadurl="/download/学生管理数据导入模板.xlsx"
              refresh={() => {
                actionRef?.current?.reload();
              }}
            ></ImportExcel>
wuhao's avatar
wuhao committed
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
            <PremButton
              btn={{
                variant: "contained",
                onClick: (e) => {
                  e.stopPropagation();
                  setdialogprops({
                    open: true,
                    defaultFormValue: {},
                    title: "新增学生",
                  });
                },
              }}
            >
              新增学生
            </PremButton>
          </Stack>
        ) : (
          <Box height={36} />
        )}
      </Box>

      <Tabs
        activeKey={active}
        onChange={setactive}
        items={items}
        tabPosition="top"
        animated={true}
      />
    </Container>
  );
}

export default Student;