index.tsx
6.03 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import React, { useState } from 'react';
import {
Card, Row, Select, Button, Table,
Switch, message, Popover, Radio, Dropdown, Menu, Divider
} from 'antd';
import { history } from 'umi';
import type { MenuProps } from 'antd';
import { SnippetsOutlined, PlusOutlined } from '@ant-design/icons';
import Search from 'antd/lib/input/Search';
import Column from 'antd/lib/table/Column';
import { debounce } from 'lodash';
import * as api from './api';
import { useStore } from '../../index';
import RenderGoodsSpec from '@/pages/capital/components/RenderGoodsSpec';
import { AssetTypeEnum } from '@/pages/capital/entity';
const Option = Select.Option;
export default function List() {
const { typeName, setIsPart, breadcrumbs, MenuItems, setCurrentItem, innerParams,
list, setBreadcrumbs, setLoading, setParams, paginationConfig, loading, setCurrentBreadcrumb, editDisabled } = useStore();
const [switchLoading, setSwitchLoading] = useState(false);
function editAdd(value?: any) {
setCurrentItem(value);
setIsPart(value ? value.part : false);
setBreadcrumbs([...breadcrumbs, { name: `${value != undefined ? '编辑' : '新增'}`, key: 'detail' }]);
setCurrentBreadcrumb({ name: `${value != undefined ? '编辑' : '新增'}`, key: 'detail' });
}
function changeSwich(value: any) {
const param = {
code: value.code,
status: value.status == 1 ? 0 : 1,
};
setSwitchLoading(true);
api.startStop(param).then(res => {
message.success('操作成功');
setLoading(true);
setSwitchLoading(false);
}).catch(e => {
message.error(e.message);
setSwitchLoading(false);
});
}
const _onChange = debounce((value: any) => {
setParams({ keywords: value, current: 1 }, true);
}, 500);
const _onChangeType = debounce((value: any) => {
setParams({ ...value, current: 1 }, true);
});
const handleMenuClick: MenuProps['onClick'] = (e) => {
switch (e.key) {
case '1':
history.push("/ams/standardMange/receive/rules/goods");
break;
case '2':
history.push("/ams/standardMange/receive/rules/shops");
break;
case '3':
history.push("/ams/standardMange/receive/rules/post");
break;
default:
break;
}
};
const clickToAuth = (item: StanderList.ListVO) => {
history.push(`/ams/standardMange/auth/goods/${item.id}/${editDisabled || ''}`);
};
return (
<Card>
<Row justify="space-between">
<Radio.Group
buttonStyle="solid"
value={innerParams.status}
onChange={(e) => _onChangeType({ status: e.target.value })}
>
<Radio.Button key="1" value={1}>
启用
</Radio.Button>
<Radio.Button key="0" value={0}>
禁用
</Radio.Button>
</Radio.Group>
<Select allowClear onChange={(e) => _onChangeType({ type: e })} placeholder="请选择类型">
{typeName.map(i => (
<Option value={i.type} key={i.type}>{i.name}</Option>
))}
</Select>
<Select allowClear onChange={(v) => _onChangeType({ part: v })} placeholder="是否配件">
<Option value={1} key={1}>是</Option>
<Option value={0} key={0}>否</Option>
</Select>
<Search
style={{ width: 260 }}
placeholder="搜索资产名称/型号"
allowClear
onChange={(e) => _onChange(e.target.value)}
/>
{!editDisabled && (
<div>
<Dropdown
overlay={
<Menu onClick={handleMenuClick} items={MenuItems} />
}
>
<Button icon={<SnippetsOutlined />} type="primary" style={{ width: 100, marginRight: 20 }}>
领用授权
</Button>
</Dropdown>
<Button type="primary" icon={<PlusOutlined />} onClick={() => editAdd(undefined)}>新增</Button>
</div>
)}
</Row>
<Table
dataSource={list}
style={{ marginTop: 20 }}
loading={loading}
pagination={paginationConfig}
rowKey="id"
size="small"
>
<Column title="物品编码" dataIndex="code" />
<Column title="物品名称" dataIndex="name" />
<Column
title="型号规格"
dataIndex="specList"
width="16%"
render={(text, record) => <RenderGoodsSpec specList={text} />}
/>
<Column
title="物品类型"
dataIndex="type"
render={(value) => (
<span>{AssetTypeEnum[value]}</span>
)}
/>
<Column
title="单位"
dataIndex="unit"
/>
<Column title="摊销周期(月)" dataIndex="amortizePeriod" align="center" width="8%" />
<Column
title="状态"
render={(value) => (
<Switch
checkedChildren="开启"
unCheckedChildren="关闭"
checked={!!value.status}
loading={switchLoading}
disabled={!!editDisabled}
onChange={() => changeSwich(value)}
/>
)}
/>
<Column
title="采购渠道"
dataIndex="purchaseChannelList"
ellipsis
render={(text) => (
<Popover placement="topLeft" content={(text || []).map((i: any) => i.subjectName).join()}>
<span>{(text || []).map((i: any) => i.subjectName).join()}</span>
</Popover>
)}
/>
{/* <Column title="最高采购金额(元)" dataIndex="maxPrice" /> */}
<Column
title="操作"
align="center"
render={(record: StanderList.ListVO) => (
<>
<Button type="link" style={{ padding: 0 }} onClick={() => { editAdd(record); }}> {!editDisabled ? "编辑" : "查看"}</Button>
<Divider type="vertical" />
<Button type="link" style={{ padding: 0 }} onClick={() => { clickToAuth(record); }}>授权</Button>
</>
)}
/>
</Table>
</Card>
);
}