2024-11-26 16:43:31 +08:00
|
|
|
import React, {Fragment, useRef, useState} from "react";
|
2025-01-20 17:42:05 +08:00
|
|
|
import { FormattedMessage, useAccess } from '@umijs/max';
|
|
|
|
|
import { FormInstance, Button, message, Modal } from 'antd';
|
|
|
|
|
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
|
|
|
import { PlusOutlined, DeleteOutlined, FormOutlined, AlignLeftOutlined } from '@ant-design/icons';
|
|
|
|
|
import {
|
|
|
|
|
getCmsAreaList,
|
|
|
|
|
addCmsAreaListRow,
|
|
|
|
|
updateCmsAreaListRow,
|
|
|
|
|
deleteCmsAreaListRow,
|
|
|
|
|
exportCmsAreaListRow
|
|
|
|
|
} from "@/services/area/business";
|
|
|
|
|
import BusinessEdit from "@/pages/Area/Business/edit";
|
2024-12-05 16:32:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemoveOne = async (selectedRow: API.AreaBusiness.Circle) => {
|
|
|
|
|
const hide = message.loading('正在删除');
|
|
|
|
|
if (!selectedRow) return true;
|
|
|
|
|
try {
|
|
|
|
|
const resp = await deleteCmsAreaListRow(selectedRow.commercialAreaId);
|
|
|
|
|
hide();
|
|
|
|
|
if (resp.code === 200) {
|
|
|
|
|
message.success('删除成功,即将刷新');
|
|
|
|
|
} else {
|
|
|
|
|
message.error(resp.msg);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
hide();
|
|
|
|
|
message.error('删除失败,请重试');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-01-20 17:42:05 +08:00
|
|
|
|
|
|
|
|
const handleExport = async (values: API.AreaBusiness.CircleEditParams) => {
|
|
|
|
|
const hide = message.loading('正在导出');
|
|
|
|
|
try {
|
|
|
|
|
await exportCmsAreaListRow(values);
|
|
|
|
|
hide();
|
|
|
|
|
message.success('导出成功');
|
|
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
hide();
|
|
|
|
|
message.error('导出失败,请重试');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-11-26 16:43:31 +08:00
|
|
|
function ManagementList() {
|
|
|
|
|
const access = useAccess();
|
|
|
|
|
|
|
|
|
|
const formTableRef = useRef<FormInstance>();
|
|
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
|
|
|
|
|
|
|
const [currentRow, setCurrentRow] = useState<API.AreaBusiness.Circle>()
|
|
|
|
|
const [modalVisible, setModalVisible] = useState<boolean>(false)
|
|
|
|
|
|
|
|
|
|
const columns: ProColumns<API.AreaBusiness.Circle>[] = [
|
|
|
|
|
{
|
|
|
|
|
title: '商圈名称',
|
|
|
|
|
dataIndex: 'commercialAreaName',
|
|
|
|
|
valueType: 'text',
|
2024-12-05 16:32:02 +08:00
|
|
|
align: 'center',
|
2024-11-26 16:43:31 +08:00
|
|
|
hideInSearch: true,
|
|
|
|
|
},
|
2024-12-05 16:32:02 +08:00
|
|
|
{
|
|
|
|
|
title: '操作',
|
|
|
|
|
align: 'center',
|
2025-01-20 17:42:05 +08:00
|
|
|
width: 300,
|
2024-12-05 16:32:02 +08:00
|
|
|
hideInSearch: true,
|
|
|
|
|
render: (_, record) => [
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
size="small"
|
|
|
|
|
key="detail"
|
2025-01-20 17:42:05 +08:00
|
|
|
icon={<AlignLeftOutlined />}
|
|
|
|
|
hidden={!access.hasPerms('area:business:List.detail')}
|
2024-12-05 16:32:02 +08:00
|
|
|
onClick={() => {
|
|
|
|
|
setModalVisible(true);
|
|
|
|
|
setCurrentRow(record);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
详细
|
|
|
|
|
</Button>,
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
size="small"
|
|
|
|
|
key="edit"
|
2025-01-20 17:42:05 +08:00
|
|
|
icon = {<FormOutlined />}
|
|
|
|
|
hidden={!access.hasPerms('area:business:List.update')}
|
2024-12-05 16:32:02 +08:00
|
|
|
onClick={() => {
|
|
|
|
|
setModalVisible(true);
|
|
|
|
|
setCurrentRow(record);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
编辑
|
|
|
|
|
</Button>,
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
size="small"
|
|
|
|
|
danger
|
|
|
|
|
key="batchRemove"
|
2025-01-20 17:42:05 +08:00
|
|
|
icon ={<DeleteOutlined/>}
|
|
|
|
|
hidden={!access.hasPerms('area:business:List')}
|
2024-12-05 16:32:02 +08:00
|
|
|
onClick={async () => {
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '删除',
|
|
|
|
|
content: '确定删除该项吗?',
|
|
|
|
|
okText: '确认',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
const success = await handleRemoveOne(record);
|
|
|
|
|
if (success) {
|
|
|
|
|
if (actionRef.current) {
|
|
|
|
|
actionRef.current.reload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
删除
|
|
|
|
|
</Button>
|
|
|
|
|
]
|
|
|
|
|
}
|
2024-11-26 16:43:31 +08:00
|
|
|
]
|
|
|
|
|
return (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div style={{ width: '100%', float: 'right' }}>
|
|
|
|
|
<ProTable<API.AreaBusiness.Circle>
|
|
|
|
|
// params 是需要自带的参数
|
|
|
|
|
// 这个参数优先级更高,会覆盖查询表单的参数
|
|
|
|
|
actionRef={actionRef}
|
|
|
|
|
formRef={formTableRef}
|
|
|
|
|
columns={columns}
|
2025-01-20 17:42:05 +08:00
|
|
|
rowKey={"commercialAreaName"}
|
|
|
|
|
key={"index"}
|
2024-11-26 16:43:31 +08:00
|
|
|
request={(params) =>
|
|
|
|
|
getCmsAreaList({ ...params } as API.AreaBusiness.CircleParams).then((res) => {
|
2025-01-20 17:42:05 +08:00
|
|
|
return {
|
2024-11-26 16:43:31 +08:00
|
|
|
data: res.rows,
|
|
|
|
|
total: res.total,
|
|
|
|
|
success: true,
|
2025-01-20 17:42:05 +08:00
|
|
|
}
|
2024-11-26 16:43:31 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
toolBarRender={() => [
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
key="add"
|
2025-01-20 17:42:05 +08:00
|
|
|
hidden={!access.hasPerms('manage:List:add')}
|
2024-11-26 16:43:31 +08:00
|
|
|
onClick={async () => {
|
|
|
|
|
setCurrentRow(undefined);
|
|
|
|
|
setModalVisible(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<PlusOutlined /> 新建
|
|
|
|
|
</Button>,
|
2025-01-20 17:42:05 +08:00
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
key="export"
|
|
|
|
|
hidden={!access.hasPerms('system:user:export')}
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
const searchVal = formTableRef.current && formTableRef.current.getFieldsValue();
|
|
|
|
|
handleExport(searchVal);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<PlusOutlined />
|
|
|
|
|
<FormattedMessage id="pages.searchTable.export" defaultMessage="导出" />
|
|
|
|
|
</Button>,
|
2024-11-26 16:43:31 +08:00
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-01-20 17:42:05 +08:00
|
|
|
<BusinessEdit
|
2024-12-05 16:32:02 +08:00
|
|
|
open={modalVisible}
|
|
|
|
|
onSubmit={async (values) => {
|
|
|
|
|
let resData
|
|
|
|
|
if(values.commercialAreaId) {
|
|
|
|
|
resData = await updateCmsAreaListRow(values)
|
|
|
|
|
} else {
|
|
|
|
|
resData = await addCmsAreaListRow(values)
|
|
|
|
|
}
|
|
|
|
|
if (resData.code === 200) {
|
|
|
|
|
setModalVisible(false);
|
|
|
|
|
setCurrentRow(undefined);
|
|
|
|
|
if(values.commercialAreaId) {
|
|
|
|
|
message.success('修改成功')
|
|
|
|
|
} else {
|
|
|
|
|
message.success('新增成功')
|
|
|
|
|
}
|
|
|
|
|
if (actionRef.current) {
|
|
|
|
|
actionRef.current.reload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
values={currentRow}
|
|
|
|
|
onCancel={() => {
|
|
|
|
|
setModalVisible(false);
|
|
|
|
|
setCurrentRow(undefined)
|
|
|
|
|
}}
|
2025-01-20 17:42:05 +08:00
|
|
|
></BusinessEdit>
|
2024-11-26 16:43:31 +08:00
|
|
|
</Fragment>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
export default ManagementList
|