WorkItemLimit.tsx
5.91 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
import React, { useState, useEffect, Ref, forwardRef } from 'react';
import { Card, Button, Table, Input, message, Select } from 'antd';
import TableSelect from '@/pages/coupon/CouponConfig/components/TableSelect';
import { PlusOutlined } from "@ant-design/icons";
import * as API from '../api';
import * as IF from '../interface';
import usePagination from '@/hooks/usePagination';
import { deRepetition } from '@/components/Condition/SeriesSelector/components/utils';
import useInitial from '@/hooks/useInitail';
import { getBrandFilterApi, getSeriesApi } from '@/common/api';
import { debounce } from 'lodash';
const st = require('@/pages/coupon/CouponConfig/style.less');
const Column = Table.Column;
const Search = Input.Search;
interface Props {
onChange?: (value: any[]) => any,
value?: any[],
style?: any
disabled?: boolean,
title?: string,
useScene: any, //作业项类型
}
function PartItem(props: Props, ref?: Ref<any>) {
const { onChange, value, style, disabled, title, useScene } = props;
/**机修作业项,类型1,2,5 */
const params = useScene === 1 ? { workTypes: "1,2,5,9" } : { workType: useScene };
const { loading, setLoading, list, setParams, paginationConfig, innerParams } = usePagination(API.fetchListApi, params);
const { data: brandList } = useInitial(getBrandFilterApi, [], {});
const [seriesList, setSeriesList] = useState<CommonApi.OptionVO[]>([]);
const [visible, setVisible] = useState(false);
const [listData, setListData] = useState<IF.ListVO[]>([]);
useEffect(() => {
value && setListData(value.map((v: any) => ({ itemCode: v.applyValue, itemName: v.applyName })));
}, []);
function getSeries(brandId: number) {
getSeriesApi(brandId).then((res) => {
setSeriesList(res.data || []);
}).catch((err) => {
message.error(err.message);
});
}
const onFilter = debounce((params) => setParams({ ...innerParams, ...params }, true), 600);
function selectedItems(value: any[]) {
const partIds = value.length && value.map((i: any) => i.applyValue).toString();
API.fetItemsApi({ partIds }).then(res => {
setListData((res.data || {}).data || []);
}).catch(e => {
message.error(e.message);
});
}
function onModalSelected(value: any) {
const newData = deRepetition(listData.concat(value), 'itemCode');
setListData(newData);
onChange && onChange(newData.map((item: any) => ({ applyValue: item.itemCode, applyName: item.itemName, applyType: 31 })));
}
function remove(itemCode: string) {
const newData = [...listData];
const index = newData.findIndex(item => itemCode === item.itemCode);
newData.splice(index, 1);
setListData(newData);
onChange && onChange(newData.map(item => ({ applyValue: item.itemCode, applyName: item.itemName, applyType: 31 })));
}
return (
<Card
style={style}
className={st.cardTable}
title={`${title}(${useScene == 1 ? "机修" : (useScene == 3 ? "钣喷" : "洗车")})`}
extra={!disabled && (
<div style={{ flex: 1, display: 'flex', justifyContent: 'space-between', flexDirection: 'row' }}>
<Button type="primary" icon={<PlusOutlined />} onClick={() => setVisible(true)}>新增</Button>
</div>
)}
>
<Table
rowKey="itemCode"
dataSource={listData}
// pagination={false}
scroll={{ y: 400 }}
bordered
>
<Column title="作业代码" dataIndex="itemCode" width="30%" />
<Column title="作业名称" dataIndex="itemName" align="center" width="30%" />
{/* <Column title="作业类型" dataIndex="workTypeName" align="center" width="20%" /> */}
{!disabled && (
<Column
title="操作"
width="20%"
render={(text, record: IF.ListVO) => {
return (
<a onClick={() => remove(record.itemCode!)}>删除</a>
);
}}
/>
)}
</Table>
<TableSelect
visible={visible}
onCancel={() => setVisible(false)}
fetchList={() => setLoading(true)}
dataSource={list}
onSure={onModalSelected}
value={listData}
pagination={paginationConfig}
loading={loading}
title="作业项"
columns={[
{ title: '作业名称', dataIndex: 'itemName' },
{ title: '作业代码', dataIndex: 'itemCode' },
{ title: '作业类型', dataIndex: 'workTypeName' },
]}
filter={[
<Select
optionFilterProp="children"
showSearch
allowClear
placeholder="搜索品牌"
style={{ width: 200, margin: 5 }}
onChange={(value) => {
setParams({ ...innerParams, brandId: value }, true);
getSeries(value);
}}
>
{brandList.map((item) => <Select.Option key={item.id} value={item.id}>{item.name}</Select.Option>)}
</Select>,
<Select
optionFilterProp="children"
mode="multiple"
showSearch
allowClear
placeholder="搜索车系"
style={{ width: 200, margin: 5 }}
onChange={(v) => { console.log(v); setParams({ ...innerParams, seriesIds: v.join(',') }, true); }}
>
{seriesList.map((item) => <Select.Option key={item.id} value={item.id}>{item.name}</Select.Option>)}
</Select>,
<Search
allowClear
value={innerParams.keywords}
style={{ margin: 5 }}
placeholder="搜索作业名称/代码"
onChange={(e) => onFilter({ keywords: e.target.value })}
/>,
<Search
allowClear
value={innerParams.specCode}
style={{ margin: 5 }}
placeholder="搜索整车代码"
onChange={(e) => onFilter({ specCode: e.target.value })}
/>
]}
/>
</Card>
);
}
export default forwardRef(PartItem);