feat: 订单详情 & 问卷调查
This commit is contained in:
99
src/components/NTRPEvaluatePopup/index.tsx
Normal file
99
src/components/NTRPEvaluatePopup/index.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import React, {
|
||||
useState,
|
||||
useImperativeHandle,
|
||||
useEffect,
|
||||
forwardRef,
|
||||
} from "react";
|
||||
import { Button, Input, View, Text } from "@tarojs/components";
|
||||
import Taro from "@tarojs/taro";
|
||||
import CommonPopup from "../CommonPopup";
|
||||
import { getCurrentFullPath } from "@/components/Auth";
|
||||
import { useUserInfo, useUserActions } from "@/store/userStore";
|
||||
import style from "./index.module.scss";
|
||||
|
||||
export enum EvaluateType {
|
||||
EDIT = "edit",
|
||||
EVALUATE = "evaluate",
|
||||
}
|
||||
|
||||
export enum DisplayConditionType {
|
||||
AUTO = "auto",
|
||||
ALWAYS = "always",
|
||||
}
|
||||
|
||||
export enum SceneType {
|
||||
LIST = "list",
|
||||
PUBLISH = "publish",
|
||||
PERSONAL = "personal",
|
||||
DETAIL = "detail",
|
||||
}
|
||||
|
||||
interface NTRPEvaluatePopupProps {
|
||||
types: EvaluateType[];
|
||||
displayCondition: DisplayConditionType;
|
||||
scene: SceneType;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
function showCondition(scene, ntrp) {
|
||||
if (scene === "list") {
|
||||
// TODO: 显示频率
|
||||
return Math.random() < 0.1 && [0, undefined].includes(ntrp);
|
||||
}
|
||||
return [0, undefined].includes(ntrp);
|
||||
}
|
||||
|
||||
const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => {
|
||||
const {
|
||||
types = ["edit", "evaluate"],
|
||||
displayCondition = "auto",
|
||||
scene = "list",
|
||||
} = props;
|
||||
const [visible, setVisible] = useState(false);
|
||||
const { ntrp } = useUserInfo();
|
||||
const { fetchUserInfo } = useUserActions();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
show: () => setVisible(true),
|
||||
}));
|
||||
|
||||
function handleEvaluate() {
|
||||
setVisible(false);
|
||||
// TODO: 实现NTRP评估逻辑
|
||||
Taro.navigateTo({
|
||||
url: `/mod_user/ntrp-evaluate/index?redirect=${encodeURIComponent(getCurrentFullPath())}`,
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// fetchUserInfo();
|
||||
}, []);
|
||||
|
||||
const showEntry =
|
||||
displayCondition === "auto"
|
||||
? showCondition(scene, ntrp)
|
||||
: displayCondition === "always";
|
||||
|
||||
return (
|
||||
<>
|
||||
<CommonPopup
|
||||
title="NTRP评估"
|
||||
visible={visible}
|
||||
onClose={() => setVisible(false)}
|
||||
position="center"
|
||||
hideFooter
|
||||
enableDragToClose={false}
|
||||
>
|
||||
<View className={style.container}>
|
||||
{/* TODO: 直接修改NTRP水平 */}
|
||||
<Text>您还未测评。。。</Text>
|
||||
<Text>请先进行NTRP评估</Text>
|
||||
<Button onClick={handleEvaluate}>开始评估</Button>
|
||||
</View>
|
||||
</CommonPopup>
|
||||
{showEntry && props.children}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(NTRPEvaluatePopup);
|
||||
Reference in New Issue
Block a user