update item

pull/1478/head
hutanglong 2 years ago
parent 9f2af3f23f
commit a58c2ccc88

@ -1,29 +1,104 @@
import { useRequest } from 'ahooks'; import { useRequest } from 'ahooks';
import { Form, Modal, Input, Select } from 'antd'; import { Form, Modal, Input, Select, notification } from 'antd';
import React from 'react'; import React, { useEffect } from 'react';
import { fetchTenantList } from '../tenant/service'; import { fetchTenantOptions } from '../tenant/service';
import { fetchAddItem, fetchUpdateItem } from './service';
const ItemCreate: React.FC<{ interface IProps {
type: string; type: string;
data: any; data: any;
visible: boolean; visible: boolean;
onClose: () => void; onClose: () => void;
}> = props => { reset: () => void;
const { visible, onClose, data, type } = props; }
const { data: tenant } = useRequest(fetchTenantList);
console.log('tenant', tenant); const ItemCreate: React.FC<IProps> = props => {
const { visible, onClose, data, type, reset } = props;
const [form] = Form.useForm();
const tenantRequest = useRequest(fetchTenantOptions, {
ready: !!type,
});
const updateRequest = useRequest(fetchUpdateItem, {
manual: true,
onSuccess: () => {
notification.success({ message: '更新成功' });
form.resetFields();
onClose();
reset();
},
onError: err => {
notification.error({ message: err.message });
},
});
const addRequest = useRequest(fetchAddItem, {
manual: true,
onSuccess: () => {
notification.success({ message: '创建成功' });
form.resetFields();
onClose();
reset();
},
onError: err => {
notification.error({ message: err.message });
},
});
const onSave = () => {
form
.validateFields()
.then(values => {
addRequest.run({ ...values });
})
.catch(info => {
console.log('Validate Failed:', info);
});
};
const onUpdate = () => {
form
.validateFields()
.then(values => {
updateRequest.run({ id: data.id, ...values });
})
.catch(info => {
console.log('Validate Failed:', info);
});
};
useEffect(() => {
if (type === 'edit') {
form.setFieldsValue({
...data,
});
}
}, [type, data, form]);
return ( return (
<Modal open={visible} onCancel={onClose} footer={null} width={600} title={type === 'edit' ? '编辑' : '创建'}> <Modal
<Form> open={visible}
<Form.Item label="租户" name=""> onCancel={onClose}
{/* <Select options={tenant}></Select> */} width={600}
title={type === 'edit' ? '编辑' : '创建'}
onOk={type === 'edit' ? onUpdate : onSave}
confirmLoading={addRequest.loading || updateRequest.loading}
>
<Form labelAlign="right" labelCol={{ span: 6 }} wrapperCol={{ span: 15 }} form={form}>
<Form.Item label="租户" name="tenantId" rules={[{ required: true }]}>
<Select
options={tenantRequest.data}
placeholder="租户"
loading={tenantRequest.loading}
disabled={type === 'edit'}
/>
</Form.Item>
<Form.Item label="项目" name="itemId" rules={[{ required: true }]}>
<Input placeholder="项目" disabled={type === 'edit'} />
</Form.Item>
<Form.Item label="项目名称" name="itemName" rules={[{ required: true }]}>
<Input placeholder="项目名称" />
</Form.Item> </Form.Item>
<Form.Item label="项目" name=""> <Form.Item label="负责人" name="owner" rules={[{ required: true }]}>
<Input /> <Input placeholder="负责人" />
</Form.Item> </Form.Item>
<Form.Item label="负责人" name=""> <Form.Item label="项目简介" name="itemDesc" rules={[{ required: true }]}>
<Input /> <Input.TextArea placeholder="项目简介" />
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>

@ -1,8 +1,8 @@
import { useAntdTable } from 'ahooks'; import { useAntdTable, useRequest } from 'ahooks';
import { Button, Form, Input, Row, Space, Table, Col, Modal } from 'antd'; import { Button, Form, Input, Row, Space, Table, Col, Modal, notification } from 'antd';
import { SearchOutlined, EditOutlined } from '@ant-design/icons'; import { SearchOutlined, EditOutlined } from '@ant-design/icons';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { fetchItemList } from './service'; import { fetchDeleteItem, fetchItemList } from './service';
import { useUrlSet } from '@/hooks/useUrlSet'; import { useUrlSet } from '@/hooks/useUrlSet';
import style from './index.module.less'; import style from './index.module.less';
import ItemCreate from './create'; import ItemCreate from './create';
@ -11,17 +11,16 @@ const baseColumns = [
{ {
title: '序号', title: '序号',
dataIndex: 'index', dataIndex: 'index',
with: 200,
}, },
{ {
title: '租户', title: '租户',
dataIndex: 'tenantId', dataIndex: 'tenantId',
with: 200, // with: 200,
}, },
{ {
title: '项目', title: '项目',
dataIndex: 'itemId', dataIndex: 'itemId',
with: 200, // with: 200,
}, },
{ {
title: '项目名称', title: '项目名称',
@ -46,16 +45,26 @@ const Tenant: React.FC = () => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const { setUrl } = useUrlSet({ form }); const { setUrl } = useUrlSet({ form });
const { tableProps, search } = useAntdTable(fetchItemList, { form }); const { tableProps, search } = useAntdTable(fetchItemList, { form });
// const {run: delete} = useRequest(fetchDeleteTenant, { manual: true }); const deleteRequest = useRequest(fetchDeleteItem, { manual: true });
const handleSearch = () => { const handleSearch = () => {
setUrl(); setUrl();
search.submit(); search.submit();
}; };
const handleDelete = (item: any) => { const handleDelete = (item: any) => {
Modal.confirm({ Modal.confirm({
title: `此操作将删除${item.itemName}, 是否继续?`, title: '提示',
onOk: () => { content: `此操作将删除${item.itemName}, 是否继续?`,
search.submit(); onOk: async () => {
try {
const res = await deleteRequest.runAsync(item.itemId);
if (res && res.success) {
notification.success({ message: '删除成功' });
search.reset();
}
} catch (e) {
notification.error({ message: '删除失败' });
}
}, },
}); });
}; };
@ -95,7 +104,7 @@ const Tenant: React.FC = () => {
<Button onClick={() => handleSearch()} type="primary" icon={<SearchOutlined />}> <Button onClick={() => handleSearch()} type="primary" icon={<SearchOutlined />}>
</Button> </Button>
<Button onClick={() => setEditVisible(true)} type="primary" icon={<EditOutlined />}> <Button onClick={() => actions('add')} type="primary" icon={<EditOutlined />}>
</Button> </Button>
</Space> </Space>
@ -131,7 +140,15 @@ const Tenant: React.FC = () => {
}, },
]} ]}
/> />
<ItemCreate data={curItem} onClose={handleClose} visible={editVisible} type={type} /> {editVisible && (
<ItemCreate
data={curItem}
onClose={handleClose}
visible={editVisible}
type={type}
reset={() => search.reset()}
/>
)}
</div> </div>
); );
}; };

@ -19,10 +19,10 @@ const fetchItemList = async (
list: res.data.records.map((item: any, index: number) => ({ index: index + 1, ...item })), list: res.data.records.map((item: any, index: number) => ({ index: index + 1, ...item })),
}; };
} }
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.message || '服务器开小差啦~');
}; };
const fetchAddTenant = async (params: { const fetchAddItem = async (params: {
itemDesc: string; // 项目简介 itemDesc: string; // 项目简介
itemId: string; // 项目 itemId: string; // 项目
itemName: string; // 项目名称 itemName: string; // 项目名称
@ -31,39 +31,47 @@ const fetchAddTenant = async (params: {
tenantDesc?: string; tenantDesc?: string;
tenantName?: string; tenantName?: string;
}) => { }) => {
const res = await request('/hippo4j/v1/cs/tenant/save', { const res = await request('/hippo4j/v1/cs/item/save', {
method: 'POST', method: 'POST',
body: { ...params }, body: { ...params },
}); });
if (res && res.success) { if (res && res.success) {
return res; return res;
} }
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.message || '服务器开小差啦~');
}; };
const fetchDeleteItem = async (id: string) => { const fetchUpdateItem = async (params: {
const url = 'hippo4j/v1/cs/item/delete/prescription/' + id; id: string;
const res = await request(url, { itemDesc: string; // 项目简介
method: 'DELETE', itemId: string; // 项目
itemName: string; // 项目名称
owner: string; // 负责人
tenantId: string; // 租户
tenantDesc?: string;
tenantName?: string;
}) => {
const res = await request('/hippo4j/v1/cs/item/update', {
method: 'POST',
body: { ...params },
}); });
if (res && res.success) { if (res && res.success) {
return res; return res;
} }
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.message || '服务器开小差啦~');
}; };
const fetchUpdateItem = async (id: string) => { const fetchDeleteItem = async (id: string) => {
const res = await request('/hippo4j/v1/cs/item/update', { const url = 'hippo4j/v1/cs/item/delete/prescription/' + id;
method: 'POST', const res = await request(url, {
params: { id }, method: 'DELETE',
}); });
if (res && res.success) { if (res && res.success) {
return res; return res;
} }
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.message || '服务器开小差啦~');
}; };
export { fetchItemList, fetchAddTenant, fetchDeleteItem, fetchUpdateItem }; export { fetchItemList, fetchAddItem, fetchDeleteItem, fetchUpdateItem };

@ -1,5 +1,21 @@
import request from '@/utils'; import request from '@/utils';
const fetchTenantOptions = async (tencent: string) => {
const res: any = await request('/hippo4j/v1/cs/tenant/query/page', {
method: 'POST',
body: {
tencent,
current: 1,
size: 10,
desc: true,
},
});
if (res && res.success) {
return res.data && res.data.records.map((item: any) => ({ value: item.tenantId, label: item.tenantName }));
}
throw new Error(res.msg || '服务器开小差啦~');
};
const fetchTenantList = async ( const fetchTenantList = async (
pageProps: { current: number; pageSize: number }, pageProps: { current: number; pageSize: number },
formData: { tencent: string | number } formData: { tencent: string | number }
@ -70,4 +86,4 @@ const fetchTenantDetail = async (id: string) => {
throw new Error(res.msg || '服务器开小差啦~'); throw new Error(res.msg || '服务器开小差啦~');
}; };
export { fetchTenantList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant, fetchTenantDetail }; export { fetchTenantOptions, fetchTenantList, fetchAddTenant, fetchDeleteTenant, fetchUpdateTenant, fetchTenantDetail };

Loading…
Cancel
Save