import React, { useEffect, useRef} from "react"; import { Modal, Form, message, Select } from "antd"; import * as API from '../api'; import useInitial from '@/hooks/useInitail'; import usePagination from '@/hooks/usePagination'; const FormItem = Form.Item; interface Props { visiable: boolean; setVisiable: (value: boolean) => any; setLoading: (value: boolean) => any; current: any; } function CreateModal(props: Props) { const { visiable, setVisiable, setLoading, current } = props; const [form] = Form.useForm(); const { data: store } = useInitial(API.fetchShops, [], ''); const { list: job, setParams } = usePagination(API.fetchPostList, {pageSize: 1000}); const { data: list } = useInitial(API.fetchOutsideType, [], {additional: 1, setting: true}); const page = useRef(10); useEffect(() => { if (current && current !== undefined) { form.setFieldsValue({ // shop: { value: current.shopId, label: current.shopName }, // job: { value: current.postId, label: current.postName }, shop: current.shops.map((e:any) => { return { value: e.shopId, label: e.shopName }; }), job: current.posts.map((e:any) => { return { value: e.postId, label: e.postName }; }), work: current.items.map((e:any) => { return { value: e.outsideTypeId, label: e.outsideTypeName}; }) }); } else { form.resetFields(); } }, [visiable]); function submit(item: any) { const params = { id: current ? current.id : undefined, shopIds: item.shop.map((e:any) => e.value), //shopName: item.shop.label, postIds: item.job.map((e:any) => e.value), //postName: item.job.label, outsideTypeIds: item.work.map((item:any) => item.value), }; API.saveApi(params) .then((res) => { message.success("保存成功"); setVisiable(false); setLoading(true); }) .catch((err) => { //console.log(err) message.error(err.message); }); } // const onLoad = (e: any) => { // const { target } = e; // // target.scrollTop + target.offsetHeight === target.scrollHeight 判断是否滑动到底部 // if (target.scrollTop + target.offsetHeight === target.scrollHeight) { // // 在这里调用接口 // page.current += 10; // setParams({ pageSize: page.current }, true); // } // }; const onShopSearch = (val: any) => { console.log("shop", val); }; const onJobSearch = (val: any) => { console.log("job", val); }; const onWorkSearch = (val: any) => { console.log("work", val); }; return ( setVisiable(false)} maskClosable={false} // getContainer={false} >
); } export default CreateModal;