stucard.jsx 5.73 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
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";
wuhao's avatar
wuhao committed
19
import { history } from "@umijs/max";
wuhao's avatar
wuhao committed
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
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,
}) {
  const {
    trainName,
    picUrl,
    createTime,
    typeName,
    type,
    deadline,
    sectionNum,
    experimentNum,
    startTime,
  } = product;
  const [confirm, setconfirm] = useState(false);
  const [shut, setshut] = useState(false);


  return (
    <Card sx={{ borderRadius: 3 }} className="hovered" id="jikl">
      <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,

              position: "absolute",
              textTransform: "uppercase",
            }}
          >
            {typeName}
          </Label>
        )}
        <StyledProductImg
          alt={trainName}
          src={picUrl ?? DEFAULT_404_IMG}
          sx={{ borderRadius: 2 }}
        />
      </Box>

      <Stack spacing={1} sx={{ p: 2 }}>
        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          width={"100%"}
          overflow={"hidden"}
          alignItems={"center"}
        >
          <div className="center">
            <Tooltip placement="bottom-start" title={trainName}>
              <Typography
                variant="subtitle2"
                noWrap
                sx={{
                  paddingLeft: 0,
                }}
              >
                {trainName}
              </Typography>
            </Tooltip>
          </div>

          <Box width={60} textAlign={"right"} flexShrink={0}>
            <Tooltip placement="bottom-start" title={createTime}>
              <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,
              }}
            >
wuhao's avatar
wuhao committed
142
              {startTime ?? "-"}~{deadline}
wuhao's avatar
wuhao committed
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
            </Typography>
          </Stack>
        </Stack>

        <Stack
          direction={"row"}
          justifyContent={"space-between"}
          alignItems={"center"}
          padding={"0 2px"}
        >
          <Stack direction={"row"} spacing={2} alignItems={"center"}>
            <Stack
              direction={"row"}
              alignItems={"center"}
              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,
                }}
              >
                {sectionNum}课时/{experimentNum}实验
              </Typography>
            </Stack>
          </Stack>

wuhao's avatar
wuhao committed
179 180 181 182 183 184 185
          <Stack
            direction={"row"}
            spacing={0}
            flex={1}
            justifyContent={"flex-end"}
          >
            <Tooltip placement="bottom-start" title={"开始学习"}>
wuhao's avatar
wuhao committed
186 187 188 189 190 191
              <IconButton
                onClick={() => {
                  history.push("/work/domybustrain/" + product.id);
                }}
              >
                <IconFont
wuhao's avatar
wuhao committed
192 193
                  type="icon-w_xuexi"
                  style={{ fontSize: 26, color: colors.blue[600] }}
wuhao's avatar
wuhao committed
194 195 196 197
                ></IconFont>
              </IconButton>
            </Tooltip>

wuhao's avatar
wuhao committed
198
            <Tooltip placement="bottom-start" title={"成绩"}>
wuhao's avatar
wuhao committed
199 200
              <IconButton
                disabled={shut === "1"}
wuhao's avatar
wuhao committed
201
                sx={{ flexShrink: 0 }}
wuhao's avatar
wuhao committed
202
                onClick={() => {
maojiafeng's avatar
maojiafeng committed
203
                  history.push("/work/myrebustrain/" + product.id);
wuhao's avatar
wuhao committed
204 205
                }}
              >
wuhao's avatar
wuhao committed
206 207 208 209 210 211 212 213 214
                <div style={{ width: 26, height: 26 }} className="center">
                  <IconFont
                    type="icon-chengjidan-copy"
                    style={{
                      fontSize: 20,
                      color: "#000",
                    }}
                  ></IconFont>
                </div>
wuhao's avatar
wuhao committed
215 216 217 218 219 220 221 222
              </IconButton>
            </Tooltip>
          </Stack>
        </Stack>
      </Stack>
    </Card>
  );
}