Files
boluo-app-main/src/components/material-manage-popup/index.tsx
2025-03-31 22:34:22 +08:00

59 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Button } from '@tarojs/components';
import { Popup } from '@taroify/core';
import { useCallback, useEffect, useState } from 'react';
import SafeBottomPadding from '@/components/safe-bottom-padding';
import Select from '@/components/select';
import { MaterialStatus } from '@/constants/material';
import { MaterialProfile } from '@/types/material';
import './index.less';
interface IProps {
open: boolean;
value: MaterialStatus;
onSave: (newValue: MaterialProfile['isOpen']) => void;
onClose: () => void;
}
const PREFIX = 'material-manage-popup';
const OPTIONS = [
{ label: '开放', value: MaterialStatus.Open },
{ label: '关闭', value: MaterialStatus.Close },
];
function MaterialManagePopup(props: IProps) {
const { open, value = MaterialStatus.Open, onSave, onClose } = props;
const [currentValue, setCurrentValue] = useState<MaterialStatus>(value);
const handleSelect = useCallback((v: MaterialStatus) => setCurrentValue(v), []);
const handleSave = useCallback(() => {
onSave(currentValue === MaterialStatus.Open);
onClose();
}, [currentValue, onSave, onClose]);
useEffect(() => {
setCurrentValue(value);
}, [value]);
return (
<Popup className={`${PREFIX}__popup`} placement="bottom" open={open} onClose={onClose}>
<div className={PREFIX}>
<div className={`${PREFIX}__header`}>
<div className={`${PREFIX}__title`}></div>
<div className={`${PREFIX}__tips`}></div>
</div>
<Select className={`${PREFIX}__select`} options={OPTIONS} value={currentValue} onSelect={handleSelect} />
<Button className={`${PREFIX}__btn`} onClick={handleSave}>
</Button>
</div>
<SafeBottomPadding />
</Popup>
);
}
export default MaterialManagePopup;