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 { useRequest } from 'ahooks'; import { doFetch } from '@/utils/doFetch'; import DetailPro from '@/components/DetailPro'; import EditTable from '@/components/InitForm/EditTable'; import { Button } from 'antd'; function Outstore(props) { const actionRef = useRef(), formRef = useRef(); const [drawer, setdrawer] = useState({ open: false, }), [activeTabKey, setactiveTabKey] = useState('1'); const [value, setvalue] = useState([]); 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 ( { doFetch({ url: '/sparepart/outWarehouseTask/queryByBeforeOut', params: { id: row?.id }, }).then((res) => { setdrawer((s) => ({ ...s, open: true, item: row, title: '出库', val: 'only', submitdata: res?.data?.data?.taskSpareList ?? [], })); }); }, }} > 出库 ); }; const remove = (text, row, _, action) => { return ( { run({ url: '/sparepart/outWarehouseTask/shut', params: { id: row?.id } }); }, }} btn={{ size: 'small', type: 'danger', }} > 关单 ); }; const columns = useMemo(() => { let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns; let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {}; return defcolumn.concat({ title: '操作', valueType: 'option', width: 150, render: (text, row, _, action) => [ defpath?.enabledetail && detail(text, row, _, action), defpath?.enableedit && edit(text, row, _, action), defpath?.enabledelete && remove(text, row, _, action), ], }); }, [activeTabKey]); const pathconfig = useMemo(() => { let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {}; return defpath; }, [activeTabKey]); return (
出库管理} columns={columns} path={pathconfig?.list || '/ngic-auth/sysUser/query/page'} actionRef={actionRef} pageextra={pathconfig?.enableadd ? 'add' : null} resizeable={false} addconfig={{ // access: 'sysDepartment_save', btn: { disabled: false, onClick: () => { setdrawer((s) => ({ ...s, open: true, item: null, title: '新增', val: 'add', })); }, }, }} tabList={getcolumns()} activeTabKey={activeTabKey} onTabChange={(key) => { setactiveTabKey(key); }} /> { setdrawer((s) => ({ ...s, open: false, })); }} {...drawer} onFinish={(vals) => { const taskSpareList = vals?.taskSpareList?.map?.((it, i) => { return { spareStockId: it?.id, operateNum: it?.operateNum, }; }); if (drawer?.val == 'add') { run({ url: pathconfig?.add || '/add', params: { ...vals, taskSpareList } }); } else if (drawer?.val == 'edit') { run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id, taskSpareList }, }); } }} > {drawer?.val == 'only' && (
!['details', 'taskSpareList'].includes(it?.key) && it.valueType != 'option', )} /> { return (
it?.id == record.id)[0] ?.taskSpareSupplierList?.map?.((it) => it?.spareSupplierStockId), onChange: (selectedKeys, selectedRows) => { const curval = value?.filter?.((it) => it?.id == record.id)[0] ?.taskSpareSupplierList ?? []; const rowkeylist = curval ? curval?.map((it) => it?.spareSupplierStockId) : []; const newValue = selectedRows?.map((its) => { if (rowkeylist.includes(its?.id)) { return curval.filter( (it) => it?.spareSupplierStockId == its?.id, )[0]; } else { return { spareSupplierStockId: its.id, operateNum: its.operateNum, }; } }); let nvalue = value ? [...value] : []; if (value && value.some((it) => it.id == record?.id)) { nvalue = value?.map((it, i) => { if (it.id == record.id) { it.taskSpareSupplierList = newValue; } return it; }); } else { nvalue.push({ id: record.id, taskSpareSupplierList: newValue, }); } setvalue(nvalue); }, }} editable={{ onValuesChange: (rower, recordList) => { const curval = value?.filter?.((it) => it?.id == record.id)[0] ?.taskSpareSupplierList ?? []; const newValue = curval?.map((its) => { if (its?.spareSupplierStockId == rower?.id) { return { spareSupplierStockId: rower.id, operateNum: rower.operateNum, }; } else { return its; } }); let nvalue = value ? [...value] : []; if (value && value.some((it) => it.id == record?.id)) { nvalue = value?.map((it, i) => { if (it.id == record.id) { it.taskSpareSupplierList = newValue; } return it; }); } else { nvalue.push({ id: record.id, taskSpareSupplierList: newValue, }); } setvalue(nvalue); }, }} />
); }, }} />
)}
); } export default Outstore;