index.jsx 14 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5
import DraggableDialog from "@/components/DraggableDialog";
import ImportExcel from "@/components/ImportExcel";
import InitForm from "@/components/InitForm";
import PremButton from "@/components/PremButton";
import ShopProductLoadingCard from "@/components/ProductCard/loading";
wuhao's avatar
wuhao committed
6
import ShopProductCard from "@/components/ProductCard/sxcard";
wuhao's avatar
wuhao committed
7 8 9
import { doFetch } from "@/utils/doFetch";
import PRODUCTS from "@/_mock/products";
import { Box, Container, Grid, Stack, Typography } from "@mui/material";
wuhao's avatar
wuhao committed
10 11 12
import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel";
import FormGroup from "@mui/material/FormGroup";
wuhao's avatar
wuhao committed
13
import { useRequest } from "ahooks";
wuhao's avatar
wuhao committed
14
import { Empty, Input, message } from "antd";
wuhao's avatar
wuhao committed
15 16 17 18 19 20 21 22 23 24
import { useMemo, useState } from "react";
import "./index.less";

function Lessons() {
  const [dialogprops, setdialogprops] = useState({
    open: false,
  });
  const [params, setparams] = useState({
    trainName: "",
    status: null,
wuhao's avatar
wuhao committed
25
    typeList: ["1", "2", "3", "4", "5"],
wuhao's avatar
wuhao committed
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
  });

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

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, parames) => {
      if (res?.code == "0000") {
        handleClose();
        message.success("操作成功");
        datalist?.refresh();
      }
    },
  });

  const datalist = useRequest(
    async () => {
      let res = await doFetch({ url: "/busTrain/list", params });
      return res?.data?.dataList;
    },
    {
      debounceWait: 400,
wuhao's avatar
wuhao committed
53
      refreshDeps: [params],
wuhao's avatar
wuhao committed
54 55 56 57 58 59 60 61 62 63 64
    }
  );

  const edit = (row) => {
    setdialogprops({
      open: true,
      defaultFormValue: { ...row },
      title: "编辑",
    });
  };

wuhao's avatar
wuhao committed
65
  const authorized = (row, ifs) => {
wuhao's avatar
wuhao committed
66
    doFetch({
wuhao's avatar
wuhao committed
67 68
      url: "/trainStudent/queryRelationStudent",
      params: { trainId: row?.id },
wuhao's avatar
wuhao committed
69 70 71 72 73 74
    }).then((res) => {
      if (res.code === "0000") {
        setdialogprops({
          open: true,
          maxWidth: "xl",
          defaultFormValue: { ...row },
wuhao's avatar
wuhao committed
75
          studentIdList: res?.data?.dataList,
wuhao's avatar
wuhao committed
76
          title: "授权",
wuhao's avatar
wuhao committed
77
          disabled: !ifs,
wuhao's avatar
wuhao committed
78 79 80 81 82
        });
      }
    });
  };

wuhao's avatar
wuhao committed
83
  const tauthorized = (row, ifs) => {
wuhao's avatar
wuhao committed
84 85 86 87 88 89 90 91 92 93 94
    doFetch({
      url: "/busTrainTeacher/queryRelationTeacher",
      params: { trainId: row?.id },
    }).then((res) => {
      if (res.code === "0000") {
        setdialogprops({
          open: true,
          maxWidth: "xl",
          defaultFormValue: { ...row },
          teacherIdList: res?.data?.dataList,
          title: "协作教师",
wuhao's avatar
wuhao committed
95
          disabled: !ifs,
wuhao's avatar
wuhao committed
96 97 98 99 100
        });
      }
    });
  };

wuhao's avatar
wuhao committed
101 102 103 104 105 106 107 108 109 110 111
  const remove = (row) => {
    runAsync({
      url: "/busTrain/delete",
      params: { id: row.id },
    });
  };

  const publish = (row, params) => {
    const type = row?.type === 1 ? 2 : row?.type === 2 ? 1 : null;
    const extra = params ?? { type };
    runAsync({
wuhao's avatar
wuhao committed
112
      url: "/busTrain/updateType",
wuhao's avatar
wuhao committed
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
      params: { id: row.id, ...extra },
    });
  };

  const columns = useMemo(
    () => [
      {
        title: "课程",
        dataIndex: "courseId",
        key: "courseId",
        valueType: "select",
        options: {
          path: "/sysCourse/getLoginTeacherCourseSection",
          params: {},
        },
        colProps: {
          span: 24,
        },
      },
      { title: "实训名称", dataIndex: "trainName", key: "trainName" },
      {
        title: "截止日期",
        dataIndex: "deadline",
        key: "deadline",
        valueType: "date",
      },
      {
        title: "实训封面",
        dataIndex: "pic",
        key: "pic",
        valueType: "uploadImage",
        fieldProps: {
          limit: 1,
        },
        colProps: {
          span: 24,
        },
      },
    ],
    []
  );

  return (
    <Container maxWidth={false}>
      <DraggableDialog
        handleClose={handleClose}
        loading={loading}
        dialogprops={dialogprops}
        maxWidth={dialogprops?.maxWidth ?? "xs"}
      >
wuhao's avatar
wuhao committed
163
        {dialogprops?.title === "编辑" || dialogprops?.title === "新增实训" ? (
wuhao's avatar
wuhao committed
164 165 166
          <InitForm
            fields={columns}
            defaultFormValue={dialogprops?.defaultFormValue}
wuhao's avatar
wuhao committed
167 168 169 170 171 172 173 174 175
            onValuesChange={async (changedValues, allValues, formRef) => {
              if (Object.keys(changedValues)[0] === "courseId") {
                let id = Object.values(changedValues)?.[0] ?? null;
                let res = await doFetch({
                  url: "/sysCourse/detail",
                  params: { id },
                });
                let pic = res?.data?.data?.pic ?? [];
                formRef?.current?.setFieldsValue({
wuhao's avatar
wuhao committed
176
                  pic,
wuhao's avatar
wuhao committed
177 178 179
                });
              }
            }}
wuhao's avatar
wuhao committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
            onFinish={(val, extra) => {
              let postdata = { ...val },
                url = "/busTrain/saveOrUpdate";
              switch (dialogprops?.title) {
                case "编辑":
                  postdata = {
                    ...val,
                    id: dialogprops?.defaultFormValue?.id,
                  };
                  break;
                default:
                  break;
              }
              runAsync({
                url,
                params: postdata,
              });
            }}
          ></InitForm>
wuhao's avatar
wuhao committed
199 200 201 202 203 204 205 206
        ) : dialogprops?.title === "协作教师" ? (
          <InitForm
            defaultFormValue={{
              teacherIdList: dialogprops?.teacherIdList,
            }}
            fields={[
              {
                rowKey: "id",
wuhao's avatar
wuhao committed
207
                rowName: "name",
wuhao's avatar
wuhao committed
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
                valueType: "FormSelectList",
                dataIndex: "teacherIdList",
                colProps: {
                  span: 24,
                },
                columns: [
                  {
                    title: "账号",
                    key: "userAccount",
                    dataIndex: "userAccount",
                    editable: false,
                  },
                  {
                    title: "教师姓名",
                    key: "name",
                    dataIndex: "name",
                    editable: false,
                  },
                  {
                    title: "学校名称",
                    key: "schoolId",
                    dataIndex: "schoolName",
                    valueType: "select",
                    search: false,
                    editable: false,
                  },
                  {
                    title: "院系名称",
                    key: "departmentName",
                    dataIndex: "departmentName",
                    editable: false,
                  },
                ],
                path: "/user/getAllTeacherByCurrentTeacherSchool",
                params: {
                  type: "",
                },
              },
            ]}
            onFinish={(val) => {
              const teacherIdList = val?.teacherIdList?.map((it) => it?.id);
              runAsync({
                url: "/busTrainTeacher/relationTrainTeacher",
                params: {
                  teacherIdList,
                  trainId: dialogprops?.defaultFormValue?.id,
                },
              });
            }}
          />
wuhao's avatar
wuhao committed
258 259 260
        ) : (
          <InitForm
            defaultFormValue={{
wuhao's avatar
wuhao committed
261
              studentIdList: dialogprops?.studentIdList,
wuhao's avatar
wuhao committed
262 263 264 265
            }}
            fields={[
              {
                rowKey: "id",
wuhao's avatar
wuhao committed
266
                rowName: "name",
wuhao's avatar
wuhao committed
267
                valueType: "FormSelectList",
wuhao's avatar
wuhao committed
268
                dataIndex: "studentIdList",
wuhao's avatar
wuhao committed
269 270 271 272 273 274 275 276
                colProps: {
                  span: 24,
                },
                columns: [
                  {
                    title: "账号",
                    key: "userAccount",
                    dataIndex: "userAccount",
wuhao's avatar
wuhao committed
277
                    editable: false,
wuhao's avatar
wuhao committed
278 279
                  },
                  {
wuhao's avatar
wuhao committed
280
                    title: "学生姓名",
wuhao's avatar
wuhao committed
281 282
                    key: "name",
                    dataIndex: "name",
wuhao's avatar
wuhao committed
283
                    editable: false,
wuhao's avatar
wuhao committed
284 285 286
                  },
                  {
                    title: "学校名称",
wuhao's avatar
wuhao committed
287
                    key: "schoolId",
wuhao's avatar
wuhao committed
288
                    dataIndex: "schoolName",
wuhao's avatar
wuhao committed
289 290 291
                    valueType: "select",
                    search: false,
                    editable: false,
wuhao's avatar
wuhao committed
292 293 294 295 296
                  },
                  {
                    title: "院系名称",
                    key: "departmentName",
                    dataIndex: "departmentName",
wuhao's avatar
wuhao committed
297 298 299 300 301 302 303
                    editable: false,
                  },
                  {
                    title: "班级名称",
                    key: "className",
                    dataIndex: "className",
                    editable: false,
wuhao's avatar
wuhao committed
304 305
                  },
                ],
wuhao's avatar
wuhao committed
306
                path: "/user/getAllStudentByCurrentTeacherSchool",
wuhao's avatar
wuhao committed
307
                params: {
wuhao's avatar
wuhao committed
308
                  type: "3",
wuhao's avatar
wuhao committed
309 310 311 312
                },
              },
            ]}
            onFinish={(val) => {
wuhao's avatar
wuhao committed
313
              const studentIdList = val?.studentIdList?.map((it) => it?.id);
wuhao's avatar
wuhao committed
314
              runAsync({
wuhao's avatar
wuhao committed
315
                url: "/trainStudent/relationTrainStudent",
wuhao's avatar
wuhao committed
316
                params: {
wuhao's avatar
wuhao committed
317 318
                  studentIdList,
                  trainId: dialogprops?.defaultFormValue?.id,
wuhao's avatar
wuhao committed
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
                },
              });
            }}
          />
        )}
      </DraggableDialog>
      <Box
        display={"flex"}
        justifyContent={"space-between"}
        alignItems={"center"}
        sx={{ mb: 2.5 }}
        mt={0}
      >
        <Typography variant="h5">实训管理</Typography>
        <Stack spacing={2} direction="row">
wuhao's avatar
wuhao committed
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
          <FormControlLabel
            control={
              <Checkbox
                checked={params?.typeList?.length === 5}
                indeterminate={
                  params?.typeList?.length > 0 && params?.typeList?.length < 5
                }
              />
            }
            label="全部"
            onChange={(e) => {
              setparams((s) => {
                let news = [];
                if (e.target.checked) {
                  news = ["1", "2", "3", "4", "5"];
                }
                return {
                  ...s,
                  typeList: news,
                };
              });
            }}
          />
          <FormGroup
            row
            value={params?.typeList ?? []}
            onChange={(e) => {
              let val = e.target.value;
              setparams((s) => {
                let news = [...s?.typeList];
                if (news.includes(val)) {
                  news = news.filter((it) => it !== val);
                } else {
                  news = [...news, val];
                }
                return {
                  ...s,
                  typeList: news,
                };
              });
            }}
          >
            <FormControlLabel
              control={
                <Checkbox
                  checked={params?.typeList?.includes("1")}
                  color={"warning"}
                />
              }
              label="待发布"
              value={1}
            />
            <FormControlLabel
              control={
                <Checkbox
                  checked={params?.typeList?.includes("2")}
                  color={"info"}
                />
              }
              label="已发布"
              value={2}
            />
            <FormControlLabel
              control={
                <Checkbox
                  checked={params?.typeList?.includes("3")}
                  color={"default"}
                />
              }
              label="已发布(暂停)"
              value={3}
            />
            <FormControlLabel
              control={
                <Checkbox
                  checked={params?.typeList?.includes("4")}
                  color={"default"}
                />
              }
              label="已结束"
              value={4}
            />
            <FormControlLabel
              control={
                <Checkbox
                  checked={params?.typeList?.includes("5")}
                  color={"default"}
                />
              }
              label="已关闭"
              value={5}
            />
          </FormGroup>
          <Input
            placeholder="请输入课程名称"
            style={{ width: 200 }}
            value={params?.trainName}
            onChange={(e) => {
              setparams((s) => ({
                ...s,
                trainName: e.target.value,
              }));
            }}
          ></Input>
wuhao's avatar
wuhao committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
          <ImportExcel></ImportExcel>
          <PremButton
            btn={{
              variant: "contained",
              onClick: (e) => {
                e.stopPropagation();
                setdialogprops({
                  open: true,
                  defaultFormValue: {},
                  title: "新增实训",
                });
              },
            }}
          >
            新增实训
          </PremButton>
        </Stack>
      </Box>

      <Box mt={2.5}>
        <Grid container spacing={3}>
          {datalist?.loading && !datalist?.data ? (
            PRODUCTS?.map((product, i) => {
              return (
wuhao's avatar
wuhao committed
462 463 464 465 466 467 468 469 470
                <Grid
                  key={product.id}
                  item
                  xs={12}
                  sm={6}
                  md={4}
                  lg={3}
                  xl={2.4}
                >
wuhao's avatar
wuhao committed
471 472 473 474 475 476 477 478 479 480
                  <ShopProductLoadingCard product={product} />
                </Grid>
              );
            })
          ) : datalist?.data?.length === 0 ? (
            <Grid xs={12} mt={12}>
              <Empty></Empty>
            </Grid>
          ) : (
            datalist?.data?.map?.((product) => (
wuhao's avatar
wuhao committed
481
              <Grid key={product.id} item xs={12} sm={6} md={4} lg={3} xl={2.4}>
wuhao's avatar
wuhao committed
482 483 484 485 486 487 488
                <ShopProductCard
                  product={product}
                  loading={datalist?.loading}
                  edit={edit}
                  remove={remove}
                  publish={publish}
                  authorized={authorized}
wuhao's avatar
wuhao committed
489
                  tauthorized={tauthorized}
wuhao's avatar
wuhao committed
490 491 492 493 494 495 496 497 498 499 500
                />
              </Grid>
            ))
          )}
        </Grid>
      </Box>
    </Container>
  );
}

export default Lessons;