1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React, { 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 { doFetch } from '@/utils/doFetch';
import { useRequest } from "ahooks";
const Custom = () => {
let actionRef = useRef();
const [drawer, setdrawer] = useState({
open: false,
});
const { run, loading, runAsync } = useRequest(doFetch, {
manual: true,
onSuccess: (res, params) => {
if (res?.code == "0000") {
actionRef?.current?.reload();
setdrawer((s) => ({
...s,
open: false,
item: {}
}));
}
},
});
const edit = (text, row, _, action) => {
return (
<PremButton
key='edit'
btn={{
size: 'small',
onClick: () => {
setdrawer((s) => ({
...s,
open: true,
item: row,
val: 'edit',
title: '编辑'
}));
},
}}
>
编辑
</PremButton>
);
};
const remove = (text, row, _, action) => {
return (
<PremButton
key='remove'
pop={{
title: '是否删除该客户?',
okText: '确认',
cancelText: '取消',
onConfirm: async () => {
let res = await doFetch({ url: pathconfig.delete, params: { id: row.id } });
if (res.code === '0000') {
actionRef.current.reload();
}
},
}}
btn={{
size: 'small',
type: 'danger',
}}
>
删除
</PremButton>
);
};
const columns = useMemo(() => {
let defcolumn = getcolumns(setdrawer)?.columns ?? [];
let factory = defcolumn.filter(it => it.key == 'factoryId')?.[0];
if (drawer.val == 'add') {
factory.options.params = {}
} else if (drawer.val == 'edit') {
factory.options.params = { factoryId: drawer.item.factoryId };
}
return defcolumn.concat({
title: '操作',
valueType: 'option',
width: 150,
render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
});
}, [drawer.val, drawer.item]);
const pathconfig = useMemo(() => {
let pathconf = getcolumns(setdrawer)?.pathconfig ?? {};
return pathconf;
}, []);
return <div>
<AutoTable
pagetitle={<h3 className="page-title">客户管理</h3>}
columns={columns}
path={pathconfig?.list}
actionRef={actionRef}
pageextra={'add'}
resizeable={false}
addconfig={{
// access: 'sysDepartment_save',
btn: {
type: 'primary',
disabled: false,
onClick: () => {
// let res = await doFetch({url:})
setdrawer((s) => ({
...s,
open: true,
item: {},
params: {},
title: '新增',
val: 'add'
}));
},
},
}}
/>
<DrawerPro
{...drawer}
fields={columns}
detailpath={drawer.val == 'add' || !drawer?.item?.id ? '' : pathconfig?.detail}
params={drawer.val == 'add' ? {} : { id: drawer?.item?.id }}
defaultFormValue={drawer?.item ?? {}}
placement="right"
onClose={() => {
setdrawer((s) => ({
...s,
open: false,
}));
}}
onFinish={async (vals) => {
if (drawer?.val == "add") {
await runAsync({ url: pathconfig?.add, params: { ...vals } });
} else if (drawer?.val == "edit") {
await runAsync({
url: pathconfig?.edit,
params: { ...vals, id: drawer?.item?.id },
});
}
}}
>
</DrawerPro>
</div>
}
export default Custom;