|
@@ -0,0 +1,174 @@
|
|
|
+"use client";
|
|
|
+import { EmailNoticeRep } from "@/api/home";
|
|
|
+import Empty from "@/components/Empty";
|
|
|
+import GlobalNotify from "@/components/ModalPopup/GlobalNotifyModal";
|
|
|
+import { ClaimActiveErrorMap } from "@/enums";
|
|
|
+import { useRouter } from "@/i18n/routing";
|
|
|
+import { server } from "@/utils/client";
|
|
|
+import { formatAmount } from "@/utils/index";
|
|
|
+import { timeFormat } from "@/utils/methods";
|
|
|
+import { Toast } from "antd-mobile";
|
|
|
+import { useTranslations } from "next-intl";
|
|
|
+import React from "react";
|
|
|
+import styles from "./style.module.scss";
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ data: EmailNoticeRep[];
|
|
|
+ handler?: (active: string, key: string) => void;
|
|
|
+}
|
|
|
+
|
|
|
+enum Status {
|
|
|
+ DELETE = -1,
|
|
|
+ UNREAD = 0,
|
|
|
+ READ = 1,
|
|
|
+ RECEIVED = 2,
|
|
|
+}
|
|
|
+
|
|
|
+const changeStatus = (params: { ids: number[]; status: 1 | -1 }) => {
|
|
|
+ return server.request<EmailNoticeRep[]>({
|
|
|
+ url: "/v1/api/user/mail/setStatus",
|
|
|
+ method: "POST",
|
|
|
+ data: params,
|
|
|
+ });
|
|
|
+};
|
|
|
+const receiveGift = (ids: number[]) => {
|
|
|
+ return server.request<any>({
|
|
|
+ url: "/v1/api/user/mail/claimMailReward",
|
|
|
+ method: "POST",
|
|
|
+ data: { ids },
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const Email: React.FC<Props> = ({ data, handler }) => {
|
|
|
+ const t = useTranslations();
|
|
|
+ const router = useRouter();
|
|
|
+ const [amount, setAmount] = React.useState<any>({});
|
|
|
+ const [visible, setVisible] = React.useState<boolean>(false);
|
|
|
+
|
|
|
+ const goDetail = (item: EmailNoticeRep) => {
|
|
|
+ router.push(`/emailDetail?id=${item.id}`);
|
|
|
+ };
|
|
|
+ const doRefresh = () => {
|
|
|
+ if (typeof handler === "function") {
|
|
|
+ handler("refresh", "email");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const doDeleteRead = async () => {
|
|
|
+ const needSetArr: number[] = [];
|
|
|
+ data.filter((item) => {
|
|
|
+ if (item.status === Status.READ && !item?.attach?.length) {
|
|
|
+ needSetArr.push(item.id);
|
|
|
+ }
|
|
|
+ if (item.status === Status.RECEIVED) {
|
|
|
+ needSetArr.push(item.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!needSetArr?.length) return;
|
|
|
+ try {
|
|
|
+ Toast.show({ icon: "loading" });
|
|
|
+ await changeStatus({
|
|
|
+ ids: needSetArr,
|
|
|
+ status: -1,
|
|
|
+ });
|
|
|
+ Toast.show({ icon: "success" });
|
|
|
+ } finally {
|
|
|
+ doRefresh();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const doAllReceive = async () => {
|
|
|
+ const needSetArr: number[] = [];
|
|
|
+ data.filter((item) => {
|
|
|
+ if (item.status !== Status.RECEIVED && item?.attach?.length) {
|
|
|
+ needSetArr.push(item.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!needSetArr?.length) return;
|
|
|
+ try {
|
|
|
+ Toast.show({ icon: "loading" });
|
|
|
+ const res = await receiveGift(needSetArr);
|
|
|
+ if (res.code === 200 && res?.data?.code === 0) {
|
|
|
+ const amountObj: any = {};
|
|
|
+ if (res?.data?.reward) {
|
|
|
+ res?.data?.reward.forEach((item: any) => {
|
|
|
+ amountObj[`coin_${item.coin_type}`] = formatAmount(item.amount);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (res?.data?.extra_reward) {
|
|
|
+ res?.data?.extra_reward.forEach((item: any) => {
|
|
|
+ amountObj[`coin_${item.coin_type}`] = formatAmount(
|
|
|
+ new BigNumber(amountObj[`coin_${item.coin_type}`] || 0)
|
|
|
+ .plus(item.amount)
|
|
|
+ .toString()
|
|
|
+ );
|
|
|
+ });
|
|
|
+ }
|
|
|
+ setAmount(amountObj);
|
|
|
+ setVisible(true);
|
|
|
+ } else {
|
|
|
+ throw new Error(ClaimActiveErrorMap.get(res.data.code) || t(`code.400`));
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ doRefresh();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.emailBox}>
|
|
|
+ <div className={styles.content}>
|
|
|
+ {!!data.length &&
|
|
|
+ data.map((item) => {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ key={item.id}
|
|
|
+ className={styles.emailItem}
|
|
|
+ onClick={() => goDetail(item)}
|
|
|
+ >
|
|
|
+ <div className={styles.title}>
|
|
|
+ <div className="text-[#c6d4e1]">{item.title}</div>
|
|
|
+ <div className="mt-[.04rem] text-[.1rem] text-[#5d7284]">
|
|
|
+ {timeFormat(item.create_at)}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {item?.attach?.length && item.status !== Status.RECEIVED && (
|
|
|
+ <img className={styles.gift} src="/notice/gift.png" alt="" />
|
|
|
+ )}
|
|
|
+ {item.status === Status.UNREAD && (
|
|
|
+ <div className={styles.doGet}>Nova!!</div>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+
|
|
|
+ {!data?.length && (
|
|
|
+ <div className="flex h-[100%] items-center justify-center">
|
|
|
+ <Empty></Empty>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className={styles.footer}>
|
|
|
+ <div className="px-[.12rem] pb-[.12rem] text-[.1rem] text-[#697885]">
|
|
|
+ Os e-mails nāo podem ser recebidos apos expirar.
|
|
|
+ <br />
|
|
|
+ Os e-mails recebidos sao limpos após expirar.
|
|
|
+ </div>
|
|
|
+ <div className={styles.btns}>
|
|
|
+ <button onClick={doDeleteRead}>Excluir leitura</button>
|
|
|
+ <button onClick={doAllReceive}>Uma peça para pegar</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <GlobalNotify
|
|
|
+ amount={amount}
|
|
|
+ visible={visible}
|
|
|
+ onChange={() => setVisible(false)}
|
|
|
+ deraction={5000}
|
|
|
+ ></GlobalNotify>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default Email;
|