/* eslint-disable react-hooks/exhaustive-deps */
/* 接单平台
* @Author: Li Hanlin
* @Date: 2022-12-05 10:13:42
* @Last Modified by: Li Hanlin
* @Last Modified time: 2023-02-01 14:00:27
*/
import * as React from 'react';
import { useState, useMemo, useRef, useEffect } 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 OrderHandle from './RepairOrderHandle';
import { message } from 'antd';
import Detail from '@/components/RepaireDetail/Detail';
function Platform(props) {
const actionRef = useRef(),
formRef = useRef();
const [drawer, setdrawer] = useState({
open: false,
SpecName: null,
}),
[activeTabKey, setactiveTabKey] = useState('1');
const { run, loading } = useRequest(doFetch, {
manual: true,
onSuccess: (res, params) => {
if (res?.code == '0000') {
actionRef?.current?.reload();
setdrawer((s) => ({
...s,
open: false,
}));
}
},
});
useEffect(async () => {
let params = {};
if (activeTabKey == '1') {
params.businessSpecName = 'ORDER_RECEIVING_DISTRIBUTE';
} else if (activeTabKey == '2') {
params.businessSpecName = 'TRACKING_ORDER_DISTRIBUTE';
} else if (activeTabKey == '3') {
params.businessSpecName = 'TRANSFER_ORDER_DISTRIBUTE';
}
let res = await doFetch({
url: '/base/pmBaseBusinessData/queryBySpecName',
params,
});
setdrawer((s) => ({
...s,
SpecName: res?.data?.data,
}));
}, [activeTabKey]);
const detail = (text, row, _, action) => {
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '详情',
val: 'detail',
title: '详细信息',
}));
},
}}
>
详情
);
};
// 接单按钮
const receiveBtn = (text, row, _, action, activeTab) => {
if (row?.status == 0 || row?.status == 1) {
if (activeTab == '2') {
// 追踪
return (
{
// setdrawer((s) => ({
// ...s,
// type: null,
// }));
//console.log('zzjd');
let params = {
id: row?.id,
};
let res = await doFetch({
url: '/repair/umTrackOrder/orderReceiving',
params,
});
if (res.code === '0000') {
message.success('操作成功!');
setdrawer((s) => ({
...s,
open: false,
}));
actionRef.current.reload();
}
},
}}
>
接单
);
} else if (activeTab == '3') {
return (
{
let params = {
id: row?.id,
};
let res = await doFetch({
url: '/repair/umOtherUnitsOrder/orderReceiving',
params,
});
if (res.code === '0000') {
message.success('操作成功!');
setdrawer((s) => ({
...s,
open: false,
}));
actionRef.current.reload();
}
},
}}
>
接单
);
} else if (activeTab == '1') {
// 维修
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '接单',
val: 'only',
type: 'wxjd',
}));
},
}}
>
接单
);
}
} else {
if (activeTab == '2') {
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '派单',
type: 'zzpd',
val: 'only',
}));
},
}}
>
派单
);
} else if (activeTab == '1') {
// 维修
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '派单',
type: 'wxpd',
val: 'only',
}));
},
}}
>
派单
);
} else if (activeTab == '3') {
return (
{
setdrawer((s) => ({
...s,
open: true,
item: row,
title: '派单',
type: 'wpd',
val: 'only',
}));
},
}}
>
派单
);
}
}
};
const columns = useMemo(() => {
let defcolumn = getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
(it) => it.key == activeTabKey,
)[0]?.columns;
let defpath =
getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
(it) => it.key == activeTabKey,
)[0]?.pathconfig ?? {};
let actions = {
title: '操作',
valueType: 'option',
width: 150,
render: (text, row, _, action) => receiveBtn(text, row, _, action, activeTabKey),
};
return defcolumn.concat(actions);
}, [activeTabKey]);
const pathconfig = useMemo(() => {
let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
return defpath;
}, [activeTabKey]);
function selectType(type) {
switch (type) {
case 'wxjd':
return (
);
case 'wxpd':
return (
);
case 'zzpd':
return (
);
case 'wpd':
return (
);
case 'detail_wxgd':
return (
);
case 'detail_wgd':
return (
);
case 'detail_zzgd':
return (
);
default:
break;
}
}
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) => {
if (drawer?.val == 'add') {
run({ url: pathconfig?.add || '/add', params: { ...vals } });
} else if (drawer?.val == 'edit') {
run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id } });
}
}}
>
{selectType(drawer?.type)}
);
}
export default Platform;