index.jsx 11.9 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4
import DraggableDialog from "@/components/DraggableDialog";
import InitForm from "@/components/InitForm";
import PremButton from "@/components/PremButton";
import ShopProductLoadingCard from "@/components/ProductCard/loading";
wuhao's avatar
wuhao committed
5
import ShopProductCard from "@/components/ProductCard/sxcard";
wuhao's avatar
wuhao committed
6 7 8 9
import { doFetch } from "@/utils/doFetch";
import PRODUCTS from "@/_mock/products";
import { Box, Container, Grid, Stack, Typography } from "@mui/material";
import { useRequest } from "ahooks";
wuhao's avatar
wuhao committed
10
import { Empty, Input, message, Tabs } from "antd";
wuhao's avatar
wuhao committed
11 12 13 14 15 16 17 18 19 20
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
21
    type: null,
wuhao's avatar
wuhao committed
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
  });

  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
49
      refreshDeps: [params],
wuhao's avatar
wuhao committed
50 51 52 53 54 55 56 57 58 59 60
    }
  );

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

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

wuhao's avatar
wuhao committed
79
  const tauthorized = (row, ifs) => {
wuhao's avatar
wuhao committed
80 81 82 83 84 85 86 87 88 89 90
    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
91
          disabled: !ifs,
wuhao's avatar
wuhao committed
92 93 94 95 96
        });
      }
    });
  };

wuhao's avatar
wuhao committed
97 98 99 100 101 102 103 104 105 106 107
  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
108
      url: "/busTrain/updateType",
wuhao's avatar
wuhao committed
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
      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
159
        {dialogprops?.title === "编辑" || dialogprops?.title === "新增实训" ? (
wuhao's avatar
wuhao committed
160 161 162
          <InitForm
            fields={columns}
            defaultFormValue={dialogprops?.defaultFormValue}
wuhao's avatar
wuhao committed
163 164 165 166 167 168 169 170 171
            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
172
                  pic,
wuhao's avatar
wuhao committed
173 174 175
                });
              }
            }}
wuhao's avatar
wuhao committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            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
195 196 197 198 199 200 201 202
        ) : dialogprops?.title === "协作教师" ? (
          <InitForm
            defaultFormValue={{
              teacherIdList: dialogprops?.teacherIdList,
            }}
            fields={[
              {
                rowKey: "id",
wuhao's avatar
wuhao committed
203
                rowName: "name",
wuhao's avatar
wuhao committed
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
                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
254 255 256
        ) : (
          <InitForm
            defaultFormValue={{
wuhao's avatar
wuhao committed
257
              studentIdList: dialogprops?.studentIdList,
wuhao's avatar
wuhao committed
258 259 260 261
            }}
            fields={[
              {
                rowKey: "id",
wuhao's avatar
wuhao committed
262
                rowName: "name",
wuhao's avatar
wuhao committed
263
                valueType: "FormSelectList",
wuhao's avatar
wuhao committed
264
                dataIndex: "studentIdList",
wuhao's avatar
wuhao committed
265 266 267 268 269 270 271 272
                colProps: {
                  span: 24,
                },
                columns: [
                  {
                    title: "账号",
                    key: "userAccount",
                    dataIndex: "userAccount",
wuhao's avatar
wuhao committed
273
                    editable: false,
wuhao's avatar
wuhao committed
274 275
                  },
                  {
wuhao's avatar
wuhao committed
276
                    title: "学生姓名",
wuhao's avatar
wuhao committed
277 278
                    key: "name",
                    dataIndex: "name",
wuhao's avatar
wuhao committed
279
                    editable: false,
wuhao's avatar
wuhao committed
280 281 282
                  },
                  {
                    title: "学校名称",
wuhao's avatar
wuhao committed
283
                    key: "schoolId",
wuhao's avatar
wuhao committed
284
                    dataIndex: "schoolName",
wuhao's avatar
wuhao committed
285 286 287
                    valueType: "select",
                    search: false,
                    editable: false,
wuhao's avatar
wuhao committed
288 289 290 291 292
                  },
                  {
                    title: "院系名称",
                    key: "departmentName",
                    dataIndex: "departmentName",
wuhao's avatar
wuhao committed
293 294 295 296 297 298 299
                    editable: false,
                  },
                  {
                    title: "班级名称",
                    key: "className",
                    dataIndex: "className",
                    editable: false,
wuhao's avatar
wuhao committed
300 301
                  },
                ],
wuhao's avatar
wuhao committed
302
                path: "/user/getAllStudentByCurrentTeacherSchool",
wuhao's avatar
wuhao committed
303
                params: {
wuhao's avatar
wuhao committed
304
                  type: "3",
wuhao's avatar
wuhao committed
305 306 307 308
                },
              },
            ]}
            onFinish={(val) => {
wuhao's avatar
wuhao committed
309
              const studentIdList = val?.studentIdList?.map((it) => it?.id);
wuhao's avatar
wuhao committed
310
              runAsync({
wuhao's avatar
wuhao committed
311
                url: "/trainStudent/relationTrainStudent",
wuhao's avatar
wuhao committed
312
                params: {
wuhao's avatar
wuhao committed
313 314
                  studentIdList,
                  trainId: dialogprops?.defaultFormValue?.id,
wuhao's avatar
wuhao committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
                },
              });
            }}
          />
        )}
      </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
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
          <Tabs
            items={[
              {
                key: null,
                label: `全部`,
              },
              {
                key: "1",
                label: `待发布`,
              },
              {
                key: "2",
                label: `已发布`,
              },
              {
                key: "3",
                label: `已发布(暂停)`,
              },
              {
                key: "4",
                label: `已结束`,
              },
            ]}
            activeKey={params?.type}
            onChange={(val) => {
              setparams((s) => ({
                ...s,
                type: val,
              }));
wuhao's avatar
wuhao committed
359
            }}
wuhao's avatar
wuhao committed
360 361
          ></Tabs>

wuhao's avatar
wuhao committed
362 363
          <Input
            placeholder="请输入课程名称"
wuhao's avatar
wuhao committed
364
            style={{ width: 200, marginLeft: 24 }}
wuhao's avatar
wuhao committed
365 366 367 368 369 370 371 372
            value={params?.trainName}
            onChange={(e) => {
              setparams((s) => ({
                ...s,
                trainName: e.target.value,
              }));
            }}
          ></Input>
wuhao's avatar
wuhao committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
          <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
396 397 398 399 400 401 402 403 404
                <Grid
                  key={product.id}
                  item
                  xs={12}
                  sm={6}
                  md={4}
                  lg={3}
                  xl={2.4}
                >
wuhao's avatar
wuhao committed
405 406 407 408 409 410 411 412 413 414
                  <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
415
              <Grid key={product.id} item xs={12} sm={6} md={4} lg={3} xl={2.4}>
wuhao's avatar
wuhao committed
416 417 418 419 420 421 422
                <ShopProductCard
                  product={product}
                  loading={datalist?.loading}
                  edit={edit}
                  remove={remove}
                  publish={publish}
                  authorized={authorized}
wuhao's avatar
wuhao committed
423
                  tauthorized={tauthorized}
wuhao's avatar
wuhao committed
424 425 426 427 428 429 430 431 432 433 434
                />
              </Grid>
            ))
          )}
        </Grid>
      </Box>
    </Container>
  );
}

export default Lessons;