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 { useAsyncEffect, useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
import extraColumns from '@/utils/extraColumns';
import { message } from 'antd';
function Supplier(props) {
let actionRef = useRef(),
formRef = useRef();
const [drawer, setdrawer] = useState({
open: false,
});
const [columns, setcolumns] = useState([
{
title: 'asd',
key: 'ads',
},
]);
const pathconfig = useMemo(() => {
let pathconf = getcolumns(setdrawer, changeState)?.pathconfig ?? {};
return pathconf;
}, []);
const { run, loading } = useRequest(doFetch, {
manual: true,
onSuccess: (res, params) => {
if (res?.code == '0000') {
actionRef?.current?.reload();
setdrawer((s) => ({
...s,
open: false,
}));
}
},
});
const detail = (text, row, _, action) => {
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '详情',
val: 'detail',
title: '详细信息',
}));
},
}}
>
详情
);
};
const edit = (text, row, _, action) => {
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '编辑',
val: 'edit',
}));
},
}}
>
编辑
);
};
const remove = (text, row, _, action) => {
return (
{
run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
},
}}
btn={{
size: 'small',
type: 'danger',
}}
>
删除
);
};
function changeState(params) {
doFetch({ url: '/sparepart/sparePartSupplier/stopAndStart', params }).then((res) => {
if (res.code == '0000') {
message.success('操作成功');
actionRef?.current?.reload();
}
});
}
useAsyncEffect(async () => {
let extracolumns = await extraColumns({
url: '/base/paFormField/queryList',
params: { formId: 4 },
});
extracolumns = extracolumns?.map((it) => ({
...it,
hideInSearch: true,
}));
let defcolumn = getcolumns(setdrawer, changeState)?.columns ?? [];
setcolumns([
...defcolumn,
...extracolumns,
{
title: '操作',
valueType: 'option',
width: 150,
render: (text, row, _, action) => [
// pathconfig?.enabledetail && detail(text, row, _, action),
pathconfig?.enableedit && edit(text, row, _, action),
pathconfig?.enabledelete && remove(text, row, _, action),
],
},
]);
}, []);
return (
备件供应商}
columns={columns}
actionRef={actionRef}
path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
pageextra={pathconfig?.enableadd ? 'add' : null}
resizeable={false}
addconfig={{
// access: 'sysDepartment_save',
btn: {
disabled: false,
onClick: () => {
setdrawer((s) => ({
...s,
open: true,
item: { status: 1 },
title: '新增',
val: 'add',
}));
},
},
}}
/>
{
setdrawer((s) => ({
...s,
open: false,
}));
}}
{...drawer}
onFinish={(vals) => {
const newVals = JSON.parse(JSON.stringify(vals));
const supplierCharReqList = [];
for (let i in newVals) {
if (!isNaN(i)) {
supplierCharReqList.push({
fieldId: i,
fieldRealValue: newVals[i],
});
delete newVals[i];
}
}
newVals.supplierCharReqList = supplierCharReqList;
if (drawer?.val == 'add') {
run({ url: pathconfig?.add || '/add', params: { ...newVals } });
} else if (drawer?.val == 'edit') {
run({ url: pathconfig?.edit || '/edit', params: { ...newVals, id: drawer?.item?.id } });
}
}}
/>
);
}
export default Supplier;