sxcard.jsx 12.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
import PropTypes from "prop-types";
// @mui
import {
  Box,
  Card,
  colors,
  IconButton,
  Stack,
  Tooltip,
  Typography,
} from "@mui/material";
import { styled } from "@mui/material/styles";
// utils
// components
import IconFont from "@/components/IconFont";
import Label from "@/components/label";
import difftime from "@/utils/difftime";
import AccessTimeFilledIcon from "@mui/icons-material/AccessTimeFilled";
import CheckIcon from "@mui/icons-material/Check";
wuhao's avatar
wuhao committed
20
import CloseIcon from "@mui/icons-material/Close";
wuhao's avatar
wuhao committed
21 22
import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
wuhao's avatar
wuhao committed
23
import GroupIcon from "@mui/icons-material/Group";
wuhao's avatar
wuhao committed
24
import PauseIcon from "@mui/icons-material/Pause";
wuhao's avatar
wuhao committed
25
import { history, useModel } from "@umijs/max";
wuhao's avatar
wuhao committed
26
import { Progress } from "antd";
wuhao's avatar
wuhao committed
27
import dayjs from "dayjs";
wuhao's avatar
wuhao committed
28
import { useEffect, useState } from "react";
wuhao's avatar
wuhao committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

// ----------------------------------------------------------------------

const StyledProductImg = styled("img")({
  top: 0,
  width: "92%",
  height: "92%",
  marginTop: "4%",
  objectFit: "cover",
  position: "absolute",
});

ShopProductCard.propTypes = {
  product: PropTypes.object,
};

export default function ShopProductCard({
  product,
  remove,
  edit,
  copy,
  publish,
  authorized,
wuhao's avatar
wuhao committed
52
  tauthorized,
wuhao's avatar
wuhao committed
53 54 55 56 57 58 59 60 61 62 63
}) {
  const {
    trainName,
    picUrl,
    createTime,
    typeName,
    type,
    deadline,
    sectionNum,
    experimentNum,
    studentNum,
wuhao's avatar
wuhao committed
64
    startTime,
wuhao's avatar
wuhao committed
65 66
    totalSubmitExperimentNum,
    totalExperimentNum,
wuhao's avatar
wuhao committed
67 68
    unReadMsgCount,
    id,
wuhao's avatar
wuhao committed
69 70
  } = product;
  const [confirm, setconfirm] = useState(false);
wuhao's avatar
wuhao committed
71
  const [shut, setshut] = useState(false);
wuhao's avatar
wuhao committed
72 73 74 75 76
  const {
    initialState: { menuNum },
    setInitialState,
  } = useModel("@@initialState");
  const [Numcount, setNumcount] = useState({});
wuhao's avatar
wuhao committed
77
  const ifs = type === 1 || type === 3;
wuhao's avatar
wuhao committed
78

wuhao's avatar
wuhao committed
79 80 81 82 83 84 85 86 87 88 89 90
  let { TEACH_TRAIN_MANAGE_LIST } = menuNum ?? {};

  useEffect(() => {
    if (!TEACH_TRAIN_MANAGE_LIST) {
      return;
    }
    setNumcount((s) => ({
      ...s,
      [TEACH_TRAIN_MANAGE_LIST.id]: TEACH_TRAIN_MANAGE_LIST?.unReadMsgCount,
    }));
  }, [TEACH_TRAIN_MANAGE_LIST]);

wuhao's avatar
wuhao committed
91
  let num = Numcount?.[id] ?? unReadMsgCount;
wuhao's avatar
wuhao committed
92

wuhao's avatar
wuhao committed
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
  return (
    <Card sx={{ borderRadius: 3 }} className="hovered" id="jikl">
      <div
        style={{
          width: 24,
          height: 24,
          backgroundColor: "#ff4800",
          position: "absolute",
          right: 6,
          top: 6,
          zIndex: 999,
          borderRadius: 30,
          color: "#fff",
          fontSize: 12,
          display: !num ? "none" : "flex",
        }}
        className="center"
      >
        {num > 100 ? "99+" : num}
      </div>
      <Box sx={{ pt: "66%", position: "relative" }} className="center">
        {typeName && (
          <Label
            variant="filled"
            color={
              (type === 1 && "warning") ||
              (type === 2 && "info") ||
              (type === 3 && "default") ||
              "error"
            }
            sx={{
              zIndex: 9,
              top: 20,
              left: 20,
wuhao's avatar
wuhao committed
127

wuhao's avatar
wuhao committed
128 129 130
              position: "absolute",
              textTransform: "uppercase",
            }}
wuhao's avatar
wuhao committed
131
          >
wuhao's avatar
wuhao committed
132 133 134 135 136 137 138 139 140 141 142 143 144
            {typeName}
          </Label>
        )}
        <StyledProductImg
          alt={trainName}
          src={picUrl ?? DEFAULT_404_IMG}
          sx={{ borderRadius: 2 }}
        />
        <Box
          className="actionhover"
          sx={{ borderRadius: 2, overflow: "hidden" }}
        >
          <Box className="masker"></Box>
wuhao's avatar
wuhao committed
145
          {(ifs || type == 4) && (
wuhao's avatar
wuhao committed
146 147
            <Box className="edit">
              <Tooltip placement="bottom-start" title="编辑">
wuhao's avatar
wuhao committed
148 149
                <IconButton
                  onClick={() => {
wuhao's avatar
wuhao committed
150
                    edit(product);
wuhao's avatar
wuhao committed
151 152
                  }}
                >
wuhao's avatar
wuhao committed
153 154 155
                  <EditIcon
                    style={{ fontSize: 20, color: colors.blue[200] }}
                  ></EditIcon>
wuhao's avatar
wuhao committed
156 157 158
                </IconButton>
              </Tooltip>

wuhao's avatar
wuhao committed
159 160 161 162 163 164 165 166 167
              <Tooltip
                placement="bottom-start"
                title={confirm ? "确认删除" : "删除"}
              >
                {confirm ? (
                  <IconButton
                    disabled={confirm === "1"}
                    onClick={() => {
                      remove(product);
wuhao's avatar
wuhao committed
168
                    }}
wuhao's avatar
wuhao committed
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
                    sx={{ marginLeft: 2 }}
                  >
                    <CheckIcon
                      style={{
                        fontSize: 20,
                        color:
                          confirm === "1"
                            ? colors.grey[500]
                            : colors.green[500],
                      }}
                    ></CheckIcon>
                  </IconButton>
                ) : (
                  <IconButton
                    onClick={() => {
                      setconfirm("1");

                      setTimeout(() => {
                        setconfirm(true);
                      }, 200);

                      setTimeout(() => {
                        setconfirm(false);
                      }, 3000);
                    }}
                  >
                    <DeleteIcon
                      style={{ fontSize: 20, color: colors.red[500] }}
                    ></DeleteIcon>
                  </IconButton>
                )}
wuhao's avatar
wuhao committed
200
              </Tooltip>
wuhao's avatar
wuhao committed
201 202
            </Box>
          )}
wuhao's avatar
wuhao committed
203 204

          <Stack
wuhao's avatar
wuhao committed
205 206 207
            direction="row"
            alignItems="center"
            justifyContent="space-between"
wuhao's avatar
wuhao committed
208
            width={"100%"}
wuhao's avatar
wuhao committed
209 210
            className="stackani"
            padding={"0px 12px"}
wuhao's avatar
wuhao committed
211
          >
wuhao's avatar
wuhao committed
212 213 214 215
            <Tooltip placement="bottom-start" title={"协作教师"}>
              <IconButton
                onClick={() => {
                  tauthorized(product, ifs);
wuhao's avatar
wuhao committed
216
                }}
wuhao's avatar
wuhao committed
217 218 219 220 221
              >
                <GroupIcon
                  style={{
                    fontSize: 24,
                    color: "#fff",
wuhao's avatar
wuhao committed
222
                  }}
wuhao's avatar
wuhao committed
223 224 225
                ></GroupIcon>
              </IconButton>
            </Tooltip>
wuhao's avatar
wuhao committed
226

wuhao's avatar
wuhao committed
227 228 229 230 231 232 233 234 235 236 237
            <Tooltip placement="bottom-start" title={"成绩管理"}>
              <IconButton
                onClick={() => {
                  history.push("/work/rebustrain/" + product.id);
                }}
              >
                <IconFont
                  type="icon-chengjidan"
                  style={{
                    fontSize: 20,
                    color: "#fff",
wuhao's avatar
wuhao committed
238
                  }}
wuhao's avatar
wuhao committed
239 240 241
                ></IconFont>
              </IconButton>
            </Tooltip>
wuhao's avatar
wuhao committed
242
          </Stack>
wuhao's avatar
wuhao committed
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
        </Box>
      </Box>
      <Stack spacing={1} sx={{ p: 2 }}>
        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          width={"100%"}
          overflow={"hidden"}
          alignItems={"center"}
        >
          <div className="center">
            <Progress
              type="circle"
              size={20}
              percent={
                (totalSubmitExperimentNum * 100) / (totalExperimentNum ?? 1)
              }
              strokeColor={{
                "0%": "#00c6fb",
                "100%": "#005bea",
              }}
            />
            <Tooltip placement="bottom-start" title={trainName}>
              <Typography
                variant="subtitle2"
                noWrap
                sx={{
                  paddingLeft: 1,
                }}
              >
                {trainName}
              </Typography>
            </Tooltip>
          </div>
wuhao's avatar
wuhao committed
277

wuhao's avatar
wuhao committed
278 279
          <Box width={60} textAlign={"right"} flexShrink={0}>
            <Tooltip placement="bottom-start" title={createTime}>
wuhao's avatar
wuhao committed
280 281 282 283
              <Typography
                component="span"
                variant="body2"
                sx={{
wuhao's avatar
wuhao committed
284
                  color: "text.disabled",
wuhao's avatar
wuhao committed
285 286
                }}
              >
wuhao's avatar
wuhao committed
287
                {difftime(dayjs(), dayjs(createTime))}
wuhao's avatar
wuhao committed
288
              </Typography>
wuhao's avatar
wuhao committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
            </Tooltip>
          </Box>
        </Stack>

        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          width={"100%"}
          overflow={"hidden"}
          alignItems={"center"}
        >
          <Stack direction={"row"} alignItems={"center"}>
            <AccessTimeFilledIcon
              sx={{ color: colors.grey[800], fontSize: 20 }}
            />
            <Typography
              component="span"
              variant="body2"
              sx={{
                paddingLeft: 1,
              }}
            >
              {startTime ?? "-"}~{deadline}
            </Typography>
wuhao's avatar
wuhao committed
313
          </Stack>
wuhao's avatar
wuhao committed
314
        </Stack>
wuhao's avatar
wuhao committed
315

wuhao's avatar
wuhao committed
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
        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          alignItems={"center"}
          padding={"0 2px"}
        >
          <Stack direction={"row"} spacing={2} alignItems={"center"}>
            <Tooltip placement="bottom-start" title="备课">
              <Stack
                direction={"row"}
                alignItems={"center"}
                onClick={() => {
                  history.push("/work/dobustrain/" + product.id);
                }}
                sx={{ cursor: "pointer" }}
              >
                <IconFont
                  type="icon-beike"
                  style={{ fontSize: 16, opacity: 0.6 }}
                ></IconFont>

                <Typography
                  component="span"
                  variant="body2"
                  sx={{
                    color: "text.disabled",
                    paddingLeft: 1.2,
                    fontSize: 12,
                    margin: 0,
wuhao's avatar
wuhao committed
345 346
                  }}
                >
wuhao's avatar
wuhao committed
347 348 349 350
                  {sectionNum}课时/{experimentNum}实验
                </Typography>
              </Stack>
            </Tooltip>
wuhao's avatar
wuhao committed
351

wuhao's avatar
wuhao committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
            <Tooltip placement="bottom-start" title="授权">
              <Stack
                direction={"row"}
                alignItems={"center"}
                sx={{ cursor: "pointer" }}
                onClick={() => {
                  authorized(product, ifs);
                }}
              >
                <IconFont
                  type="icon-shouquanguanli"
                  style={{ fontSize: 16, color: "#999" }}
                ></IconFont>
                <Typography
                  component="a"
                  variant="body2"
                  sx={{
                    color: "text.disabled",
                    paddingLeft: 1.2,
                    fontSize: 12,
                    margin: 0,
wuhao's avatar
wuhao committed
373 374
                  }}
                >
wuhao's avatar
wuhao committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                  {studentNum}学生
                </Typography>
              </Stack>
            </Tooltip>
          </Stack>

          <Stack direction={"row"} spacing={0}>
            <Tooltip placement="bottom-start" title={ifs ? "发布" : "暂停发布"}>
              <IconButton
                style={{
                  opacity: type !== 5 && type !== 4 ? 1 : 0,
                  pointerEvents: type === 5 || type === 4 ? "none" : "auto",
                }}
                onClick={() => {
                  if (type === 5 || type === 4) return;
                  if (ifs) {
                    publish(product, { type: 2 });
                  } else {
                    publish(product, { type: 3 });
                  }
                }}
              >
                {ifs ? (
wuhao's avatar
wuhao committed
398
                  <IconFont
wuhao's avatar
wuhao committed
399 400
                    type="icon-fabu"
                    style={{ fontSize: 20, color: colors.blue[600] }}
wuhao's avatar
wuhao committed
401
                  ></IconFont>
wuhao's avatar
wuhao committed
402 403 404 405 406 407 408
                ) : (
                  <PauseIcon
                    style={{ fontSize: 20, color: colors.grey[900] }}
                  ></PauseIcon>
                )}
              </IconButton>
            </Tooltip>
wuhao's avatar
wuhao committed
409

wuhao's avatar
wuhao committed
410
            {type === 3 && (
wuhao's avatar
wuhao committed
411 412
              <Tooltip
                placement="bottom-start"
wuhao's avatar
wuhao committed
413
                title={shut ? "确认结束" : "结束"}
wuhao's avatar
wuhao committed
414
              >
wuhao's avatar
wuhao committed
415 416 417 418 419 420 421 422 423 424 425 426
                {shut ? (
                  <IconButton
                    disabled={shut === "1"}
                    onClick={() => {
                      publish(product, { type: 5 });
                    }}
                  >
                    <CheckIcon
                      style={{
                        fontSize: 20,
                        color:
                          shut === "1" ? colors.grey[500] : colors.green[500],
wuhao's avatar
wuhao committed
427
                      }}
wuhao's avatar
wuhao committed
428 429 430 431 432 433
                    ></CheckIcon>
                  </IconButton>
                ) : (
                  <IconButton
                    onClick={() => {
                      setshut("1");
wuhao's avatar
wuhao committed
434

wuhao's avatar
wuhao committed
435 436 437
                      setTimeout(() => {
                        setshut(true);
                      }, 200);
wuhao's avatar
wuhao committed
438

wuhao's avatar
wuhao committed
439 440 441 442 443 444 445 446 447 448 449 450 451
                      setTimeout(() => {
                        setshut(false);
                      }, 3000);
                    }}
                  >
                    <CloseIcon
                      type="icon-guanbi"
                      style={{ fontSize: 20, color: "#ff4800" }}
                    ></CloseIcon>
                  </IconButton>
                )}
              </Tooltip>
            )}
wuhao's avatar
wuhao committed
452 453
          </Stack>
        </Stack>
wuhao's avatar
wuhao committed
454 455
      </Stack>
    </Card>
wuhao's avatar
wuhao committed
456 457
  );
}