/* 设备供应商
* @Author: Li Hanlin
* @Date: 2022-11-09 14:44:44
* @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-14 10:39:38
*/
import * as React from 'react';
import { useState, useMemo, useRef } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { doFetch } from '@/utils/doFetch';
import { message } from 'antd';
function Supplier(props) {
const actionRef = useRef(),
formRef = useRef();
const [drawer, setDrawer] = useState({
visible: false,
});
const urlParams = {
save: '/asset/equipmentSupplier/save',
remove: '/asset/equipmentSupplier/deleteById',
list: '/asset/equipmentSupplier/queryList',
detail: '/asset/equipmentSupplier/query/detail',
detail_nocp: '/asset/equipmentSupplier/queryById',
};
const detail = (text, row, _, action) => {
return (
{
setDrawer((s) => ({
...s,
visible: true,
item: row,
title: '详情',
val: 'detail',
title: row.userName + '的详细信息',
}));
},
}}
>
详情
);
};
const edit = (text, row, _, action) => {
return (
{
setDrawer((s) => ({
...s,
visible: true,
detailpath: urlParams.detail,
params: { id: row?.id },
title: '编辑',
val: 'edit',
onFinish: async (vals) => {
console.log(1);
let params = {
...vals,
id: row.id,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('编辑成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}));
},
}}
>
编辑
);
};
const remove = (text, row, _, action) => {
return (
{
let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
if (res.code === '0000') {
message.success('删除成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}}
btn={{
size: 'small',
type: 'danger',
}}
>
删除
);
};
const columns = useMemo(() => {
let defcolumn = getcolumns(setDrawer);
defcolumn[1].render = (text, row) => {
return (
{
setDrawer((s) => ({
...s,
visible: true,
title: '查看详情',
fields: columns,
val: 'detail',
detailpath: urlParams.detail,
params: { id: row.id },
}));
}}
>
{row.supplierName}
);
};
return defcolumn.concat({
title: '操作',
valueType: 'option',
width: 150,
render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
});
}, []);
return (
设备供应商}
columns={columns}
path={urlParams.list}
actionRef={actionRef}
pageextra={'add'}
resizeable={false}
addconfig={{
// access: 'sysDepartment_save',
btn: {
disabled: false,
type: 'primary',
onClick: () => {
setDrawer((s) => ({
...s,
visible: true,
item: {
status: 1,
},
title: '新增',
detailpath: null,
val: 'add',
onFinish: async (vals) => {
let params = {
...vals,
};
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
}));
},
},
}}
/>
{
setDrawer((s) => ({
...s,
visible: false,
}));
}}
{...drawer}
/>
);
}
export default Supplier;