sxcard.jsx 11.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 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
import { history } from "@umijs/max";
import { Progress } from "antd";
import dayjs from "dayjs";
import { useState } from "react";

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

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 64 65 66 67
}) {
  const {
    trainName,
    picUrl,
    createTime,
    typeName,
    type,
    deadline,
    sectionNum,
    experimentNum,
    studentNum,
    totalSubmitExperimentNum,
    totalExperimentNum,
  } = product;
  const [confirm, setconfirm] = useState(false);
wuhao's avatar
wuhao committed
68 69 70
  const [shut, setshut] = useState(false);

  const ifs = type === 1 || type === 3;
wuhao's avatar
wuhao committed
71 72 73 74 75 76 77 78

  return (
    <Card sx={{ borderRadius: 3 }} className="hovered" id="jikl">
      <Box sx={{ pt: "66%", position: "relative" }} className="center">
        {typeName && (
          <Label
            variant="filled"
            color={
wuhao's avatar
wuhao committed
79 80 81 82
              (type === 1 && "warning") ||
              (type === 2 && "info") ||
              (type === 3 && "default") ||
              "error"
wuhao's avatar
wuhao committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
            }
            sx={{
              zIndex: 9,
              top: 20,
              left: 20,

              position: "absolute",
              textTransform: "uppercase",
            }}
          >
            {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
107
          {ifs && (
wuhao's avatar
wuhao committed
108
            <Box className="edit">
wuhao's avatar
wuhao committed
109
              <Tooltip placement="bottom-start" title="编辑">
wuhao's avatar
wuhao committed
110 111 112 113 114 115 116 117 118 119 120
                <IconButton
                  onClick={() => {
                    edit(product);
                  }}
                >
                  <EditIcon
                    style={{ fontSize: 20, color: colors.blue[200] }}
                  ></EditIcon>
                </IconButton>
              </Tooltip>

wuhao's avatar
wuhao committed
121 122 123 124
              <Tooltip
                placement="bottom-start"
                title={confirm ? "确认删除" : "删除"}
              >
wuhao's avatar
wuhao committed
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
                {confirm ? (
                  <IconButton
                    disabled={confirm === "1"}
                    onClick={() => {
                      remove(product);
                    }}
                    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>
                )}
              </Tooltip>
            </Box>
          )}

          <Stack
            direction="row"
            alignItems="center"
            justifyContent="space-between"
            width={"100%"}
            className="stackani"
            padding={"0px 12px"}
          >
wuhao's avatar
wuhao committed
174
            <Tooltip placement="bottom-start" title={"协作教师"}>
wuhao's avatar
wuhao committed
175 176
              <IconButton
                onClick={() => {
wuhao's avatar
wuhao committed
177
                  tauthorized(product, ifs);
wuhao's avatar
wuhao committed
178 179 180 181 182 183 184 185 186 187
                }}
              >
                <GroupIcon
                  style={{
                    fontSize: 24,
                    color: "#fff",
                  }}
                ></GroupIcon>
              </IconButton>
            </Tooltip>
wuhao's avatar
wuhao committed
188

wuhao's avatar
wuhao committed
189
            <Tooltip placement="bottom-start" title={"成绩管理"}>
wuhao's avatar
wuhao committed
190 191
              <IconButton
                onClick={() => {
wuhao's avatar
wuhao committed
192
                  history.push("/work/rebustrain/" + product.id);
wuhao's avatar
wuhao committed
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
                }}
              >
                <IconFont
                  type="icon-chengjidan"
                  style={{
                    fontSize: 20,
                    color: "#fff",
                  }}
                ></IconFont>
              </IconButton>
            </Tooltip>
          </Stack>
        </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={parseInt(Math.random() * 100)}
              strokeColor={{
                "0%": "#00c6fb",
                "100%": "#005bea",
              }}
            />
wuhao's avatar
wuhao committed
226
            <Tooltip placement="bottom-start" title={trainName}>
wuhao's avatar
wuhao committed
227 228 229 230 231 232 233 234 235 236 237 238 239
              <Typography
                variant="subtitle2"
                noWrap
                sx={{
                  paddingLeft: 1,
                }}
              >
                {trainName}
              </Typography>
            </Tooltip>
          </div>

          <Box width={60} textAlign={"right"} flexShrink={0}>
wuhao's avatar
wuhao committed
240
            <Tooltip placement="bottom-start" title={createTime}>
wuhao's avatar
wuhao committed
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
              <Typography
                component="span"
                variant="body2"
                sx={{
                  color: "text.disabled",
                }}
              >
                {difftime(dayjs(), dayjs(createTime))}
              </Typography>
            </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,
              }}
            >
              截止日期: {deadline}
            </Typography>
          </Stack>
        </Stack>

        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          alignItems={"center"}
          padding={"0 2px"}
        >
          <Stack direction={"row"} spacing={2} alignItems={"center"}>
wuhao's avatar
wuhao committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
            <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
306 307
                  }}
                >
wuhao's avatar
wuhao committed
308 309 310 311
                  {sectionNum}课时/{experimentNum}实验
                </Typography>
              </Stack>
            </Tooltip>
wuhao's avatar
wuhao committed
312

wuhao's avatar
wuhao committed
313 314 315 316 317 318
            <Tooltip placement="bottom-start" title="授权">
              <Stack
                direction={"row"}
                alignItems={"center"}
                sx={{ cursor: "pointer" }}
                onClick={() => {
wuhao's avatar
wuhao committed
319
                  authorized(product, ifs);
wuhao's avatar
wuhao committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333
                }}
              >
                <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
334 335
                  }}
                >
wuhao's avatar
wuhao committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
                  {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
359
                  <IconFont
wuhao's avatar
wuhao committed
360 361
                    type="icon-fabu"
                    style={{ fontSize: 20, color: colors.blue[600] }}
wuhao's avatar
wuhao committed
362
                  ></IconFont>
wuhao's avatar
wuhao committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
                ) : (
                  <PauseIcon
                    style={{ fontSize: 20, color: colors.grey[900] }}
                  ></PauseIcon>
                )}
              </IconButton>
            </Tooltip>

            {type === 3 && (
              <Tooltip
                placement="bottom-start"
                title={shut ? "确认关闭" : "关闭"}
              >
                {shut ? (
                  <IconButton
                    disabled={shut === "1"}
                    onClick={() => {
                      publish(product, { type: 3 });
wuhao's avatar
wuhao committed
381 382
                    }}
                  >
wuhao's avatar
wuhao committed
383 384 385 386 387 388 389 390 391 392 393 394
                    <CheckIcon
                      style={{
                        fontSize: 20,
                        color:
                          shut === "1" ? colors.grey[500] : colors.green[500],
                      }}
                    ></CheckIcon>
                  </IconButton>
                ) : (
                  <IconButton
                    onClick={() => {
                      setshut("1");
wuhao's avatar
wuhao committed
395

wuhao's avatar
wuhao committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
                      setTimeout(() => {
                        setshut(true);
                      }, 200);

                      setTimeout(() => {
                        setshut(false);
                      }, 3000);
                    }}
                  >
                    <CloseIcon
                      type="icon-guanbi"
                      style={{ fontSize: 20, color: "#ff4800" }}
                    ></CloseIcon>
                  </IconButton>
                )}
wuhao's avatar
wuhao committed
411 412 413 414 415 416 417 418
              </Tooltip>
            )}
          </Stack>
        </Stack>
      </Stack>
    </Card>
  );
}