Commit 8fb29c3f58b98cf77125264675dc773745745055

Authored by 杜志良
1 parent f9572dfa

feature: 售后作业项标准管理列表工时标准添加排序功能

src/pages/cas/afterSaleConfiguration/jobManagement/index.tsx
1 1 import React, { useState, useEffect } from 'react';
2   -import { Button, message, Table, Popconfirm, Select, Card, Dropdown, Menu, Divider } from 'antd';
  2 +import { Button, message, Table, Popconfirm, Select, Card, Dropdown, Menu, Divider, TableProps } from 'antd';
3 3 import CreateModal from './components/CreateModal';
4 4 import UploadModal from './components/UploadModal';
5 5 import { DownOutlined } from '@ant-design/icons';
... ... @@ -16,6 +16,18 @@ const { Column } = Table;
16 16 const { Option } = Select;
17 17 const indexS = require('@/pages/cas/afterSaleConfiguration/jobManagement/index.less');
18 18  
  19 +interface DataType {
  20 + key: React.Key;
  21 + name: string;
  22 + age: number;
  23 + address: string;
  24 +}
  25 +
  26 +const sortTypes = {
  27 + ascend: "asc",
  28 + descend: "desc",
  29 +};
  30 +
19 31 export default function FactoryList() {
20 32 const [visibleEdit, setVisibleEdit] = useState<boolean>(false);
21 33 const [visibleUpload, setVisibleUpload] = useState<boolean>(false);
... ... @@ -23,11 +35,15 @@ export default function FactoryList() {
23 35 const [brand, setBrand] = useState<WorkProject.optionItem[]>([]);
24 36 const [brandItem, setBrandItem] = useState<number>();
25 37 const [brandName, setBrandName] = useState<string>();
26   - const { loading, setLoading, list, setParams, paginationConfig } = usePagination(getWorkControl, {});
27 38  
28 39 const [specVisible, setSpecVisible] = useState(false);
29 40 const [specList, setSpecList] = useState<any>([]);
30 41  
  42 + // 记录排序方式,当排序方式改变时,重置分页current为1
  43 + const [sortType, setSortType] = useState<"asc" | "desc" | undefined>(undefined);
  44 +
  45 + const { loading, setLoading, list, setParams, paginationConfig } = usePagination(getWorkControl, {});
  46 +
31 47 useEffect(() => {
32 48 fetchBrand();
33 49 }, []);
... ... @@ -37,40 +53,51 @@ export default function FactoryList() {
37 53 }, 800);
38 54  
39 55 function fetchBrand() {
40   - getBrandFilterApi().then(res => {
41   - const { data } = res;
42   - setBrand(data || []);
43   - }).catch(e => {
44   - message.error(e.message);
45   - });
  56 + getBrandFilterApi()
  57 + .then((res) => {
  58 + const { data } = res;
  59 + setBrand(data || []);
  60 + })
  61 + .catch((e) => {
  62 + message.error(e.message);
  63 + });
46 64 }
47 65  
48 66 function handleDelete(param?: number) {
49   - deleteProject(param).then(res => {
50   - message.success("删除成功");
51   - setLoading(true);
52   - }).catch(e => {
53   - message.error(e.message);
54   - });
  67 + deleteProject(param)
  68 + .then((res) => {
  69 + message.success("删除成功");
  70 + setLoading(true);
  71 + })
  72 + .catch((e) => {
  73 + message.error(e.message);
  74 + });
55 75 }
56 76  
57 77 function handleMenuClick(e: any) {
58 78 // const brandName =
59   - // e.item.props.children[1].props.props.children[1].props.children;
  79 + // e.item.props.children[1].props.props.children[1].props.children;
60 80 // setBrandName(brandName || '');
61 81 // setBrandItem(e.key);
62 82 setItem({});
63 83 setVisibleEdit(true);
64 84 }
65 85  
  86 + const handleTableChange: TableProps<DataType>["onChange"] = (pagination, filters, sorter) => {
  87 + const isReset = sortType !== sortTypes[sorter.order];
  88 + setParams({
  89 + current: isReset ? 1 : pagination.current,
  90 + pageSize: pagination.pageSize,
  91 + orderType: sortTypes[sorter.order],
  92 + }, true);
  93 + setSortType(sortTypes[sorter.order]);
  94 + };
  95 +
66 96 return (
67 97 <PageHeaderWrapper title="作业项标准管理">
68 98 <Card className={indexS.page}>
69 99 <div className={indexS.header}>
70   - <Filter
71   - onFilter={(value) => setParams({ ...value, current: 1 }, true)}
72   - brandList={brand}
73   - />
  100 + <Filter onFilter={(value) => setParams({ ...value, current: 1 }, true)} brandList={brand} />
74 101 {/* <Dropdown
75 102 overlay={
76 103 <Menu onClick={handleMenuClick}>
... ... @@ -84,11 +111,7 @@ export default function FactoryList() {
84 111 新增 <DownOutlined />
85 112 </Button>
86 113 </Dropdown> */}
87   - <Button
88   - className={indexS.add}
89   - type="primary"
90   - onClick={handleMenuClick}
91   - >
  114 + <Button className={indexS.add} type="primary" onClick={handleMenuClick}>
92 115 新增
93 116 </Button>
94 117 </div>
... ... @@ -98,16 +121,12 @@ export default function FactoryList() {
98 121 loading={loading}
99 122 rowKey={(record) => String(record.id)}
100 123 style={{ marginTop: 20 }}
  124 + onChange={handleTableChange}
101 125 >
102 126 <Column title="作业项代码" dataIndex="itemCode" align="center" />
103 127 {/* <Column title="分组代码" dataIndex="specGroupCode" align="center" /> */}
104 128 <Column title="作业项名称" dataIndex="itemName" align="center" />
105   - <Column
106   - title="品牌"
107   - dataIndex="brandName"
108   - align="center"
109   - render={(text) => <span>{text || "--"}</span>}
110   - />
  129 + <Column title="品牌" dataIndex="brandName" align="center" render={(text) => <span>{text || "--"}</span>} />
111 130 <Column
112 131 title="车系"
113 132 dataIndex="seriesName"
... ... @@ -140,7 +159,7 @@ export default function FactoryList() {
140 159 align="center"
141 160 // render={(text) => workTypeEnum[text]}
142 161 />
143   - <Column title="标准工时" dataIndex="stdManHours" align="center" />
  162 + <Column title="标准工时" dataIndex="stdManHours" align="center" sorter />
144 163 <Column
145 164 title="操作"
146 165 width="16%"
... ... @@ -166,10 +185,7 @@ export default function FactoryList() {
166 185 okText="确定"
167 186 cancelText="取消"
168 187 >
169   - <a
170   - onClick={(e) => e.preventDefault()}
171   - style={{ color: "red" }}
172   - >
  188 + <a onClick={(e) => e.preventDefault()} style={{ color: "red" }}>
173 189 删除
174 190 </a>
175 191 </Popconfirm>
... ... @@ -178,12 +194,7 @@ export default function FactoryList() {
178 194 )}
179 195 />
180 196 </Table>
181   - {visibleUpload && (
182   - <UploadModal
183   - brandList={brand}
184   - onCancel={() => setVisibleUpload(false)}
185   - />
186   - )}
  197 + {visibleUpload && <UploadModal brandList={brand} onCancel={() => setVisibleUpload(false)} />}
187 198 {visibleEdit && (
188 199 <CreateModal
189 200 item={item}
... ... @@ -193,12 +204,8 @@ export default function FactoryList() {
193 204 brandName={brandName}
194 205 />
195 206 )}
196   - <SpecModal
197   - list={specList}
198   - visible={specVisible}
199   - setVisible={setSpecVisible}
200   - />
  207 + <SpecModal list={specList} visible={specVisible} setVisible={setSpecVisible} />
201 208 </Card>
202 209 </PageHeaderWrapper>
203 210 );
204   -}
205 211 \ No newline at end of file
  212 +}
... ...