Commit 4f3b0b5ea88d75e9d9b7d8d08b55e69bffbb8283
1 parent
318e0f45
fix(cas): 优化保养机油配置
Showing
5 changed files
with
74 additions
and
220 deletions
src/pages/cas/afterSaleConfiguration/maintainConfig/interface.d.ts
src/pages/cas/afterSaleConfiguration/maintainConfig/subpages/MaintainEdit/components/EngineOilSelector/components/NewOilModal/index.tsx deleted
1 | -import React, { useEffect, useState } from 'react'; | |
2 | -import { Form, Modal, Select } from 'antd'; | |
3 | -import useInitail from '@/hooks/useInitail'; | |
4 | - | |
5 | -import { motorOilTypeData, oilViscosityData } from '@/pages/pms/entity'; | |
6 | -import { getBrandApi, getTypes } from '@/pages/cas/afterSaleConfiguration/maintainConfig/subpages/MaintainEdit/api'; | |
7 | - | |
8 | -interface Props { | |
9 | - selected: Maintain.OilGroup[]; | |
10 | - visible: boolean; | |
11 | - onCancel: () => void; | |
12 | - onOk: (data: Maintain.OilGroup[]) => any; | |
13 | - current: Maintain.OilGroup; | |
14 | - setCurrent: (value: any) => any; | |
15 | -} | |
16 | - | |
17 | -function NewOilModal(props: Props) { | |
18 | - const { visible, onCancel, onOk, selected, current, setCurrent } = props; | |
19 | - const [form] = Form.useForm(); | |
20 | - const [delay, setDelay] = useState(true); | |
21 | - const { data, setParams: setBrandParams } = useInitail<PmsPartOilSpace.Brand[], object>(getBrandApi, [], {}, delay); | |
22 | - const { data: oilLevelData, setParams: setOilLevelParams } = useInitail<PmsPartOilSpace.Type[], string>(getTypes, [], 'oil_level', delay); | |
23 | - const { data: oilModels, setParams } = useInitail<PmsPartOilSpace.Type[], string>(getTypes, [], 'oil_model', delay); | |
24 | - const { data: motorOilTypeData, setParams: oilType } = useInitail < PmsPartOilSpace.Type[], string> (getTypes, [], 'oil_type', delay); | |
25 | - const { data: oilViscosityData, setParams: oilViscosity } = useInitail < PmsPartOilSpace.Type[], string> (getTypes, [], 'oil_viscosity', delay); | |
26 | - useEffect(() => { | |
27 | - if (visible) { | |
28 | - setDelay(false); | |
29 | - setBrandParams({ oilType: 1 }, true); | |
30 | - oilType('oil_type', true); | |
31 | - oilViscosity('oil_viscosity', true); | |
32 | - setOilLevelParams('oil_level', true); | |
33 | - if (current.oilBrandId) { | |
34 | - form.setFieldsValue({ ...current }); | |
35 | - setParams(`oil_model_${current.oilBrandId}`, true); | |
36 | - } else { | |
37 | - form.resetFields(); | |
38 | - } | |
39 | - } | |
40 | - }, [visible]); | |
41 | - | |
42 | - function _onOk(value: any) { | |
43 | - const data: Maintain.OilGroup = { | |
44 | - ...value, | |
45 | - oilBrandName: value.oil.label, | |
46 | - oilBrandId: value.oil.value, | |
47 | - defaultUse: false, | |
48 | - }; | |
49 | - const index = selected.findIndex((e) => { | |
50 | - return ( | |
51 | - e.oilBrandId === value.oil.value && | |
52 | - e.motorOilType === value.motorOilType && | |
53 | - e.oilLevel === value.oilLevel && | |
54 | - e.oilModel === value.oilModel && | |
55 | - e.oilViscosity === value.oilViscosity | |
56 | - ); | |
57 | - }); | |
58 | - if (current.index || current.index == 0) { | |
59 | - selected[current.index] = data; | |
60 | - } else if (index > -1) { | |
61 | - selected[index] = data; | |
62 | - } else { | |
63 | - selected.push(data); | |
64 | - } | |
65 | - | |
66 | - setCurrent({}); | |
67 | - onOk && onOk(selected); | |
68 | - } | |
69 | - | |
70 | - const layout = { | |
71 | - labelCol: { span: 4 }, | |
72 | - wrapperCol: { span: 20 }, | |
73 | - }; | |
74 | - | |
75 | - return ( | |
76 | - <Modal width={650} forceRender title={`${current.oilBrandId ? '编辑' : '添加'}机油`} open={visible} onOk={form.submit} onCancel={onCancel}> | |
77 | - <Form {...layout} labelAlign="left" form={form} onFinish={_onOk} component={false}> | |
78 | - <Form.Item label="机油品牌" name="oil" rules={[{ required: true }]}> | |
79 | - <Select | |
80 | - labelInValue | |
81 | - placeholder="请选择机油品牌" | |
82 | - showSearch | |
83 | - optionFilterProp="children" | |
84 | - onChange={(id) => { | |
85 | - setParams(`oil_model_${id.value}`, true); | |
86 | - form.resetFields(['oilModel']); | |
87 | - }} | |
88 | - > | |
89 | - {data.map((i) => ( | |
90 | - <Select.Option value={i.brandId || 0} key={i.brandId || 0}> | |
91 | - {i.brandName || '--'} | |
92 | - </Select.Option> | |
93 | - ))} | |
94 | - </Select> | |
95 | - </Form.Item> | |
96 | - <Form.Item label="机油型号" name="oilModel" rules={[{ required: true }]}> | |
97 | - <Select placeholder="请选择机油型号" showSearch optionFilterProp="children"> | |
98 | - {oilModels.map((i) => ( | |
99 | - <Select.Option value={i.value || ''} key={i.value || ''}> | |
100 | - {i.value || '--'} | |
101 | - </Select.Option> | |
102 | - ))} | |
103 | - </Select> | |
104 | - </Form.Item> | |
105 | - <Form.Item label="机油类型" name="motorOilType" rules={[{ required: true }]}> | |
106 | - <Select placeholder="请选择机油类型" showSearch optionFilterProp="children"> | |
107 | - {motorOilTypeData.map((i) => ( | |
108 | - <Select.Option value={i.value || 0} key={i.value || 0}> | |
109 | - {i.value || '--'} | |
110 | - </Select.Option> | |
111 | - ))} | |
112 | - </Select> | |
113 | - </Form.Item> | |
114 | - <Form.Item label="机油等级" name="oilLevel" rules={[{ required: true }]}> | |
115 | - <Select placeholder="请选择机油等级" showSearch optionFilterProp="children"> | |
116 | - {oilLevelData.map((i) => ( | |
117 | - <Select.Option value={i.value || 0} key={i.value || 0}> | |
118 | - {i.value || '--'} | |
119 | - </Select.Option> | |
120 | - ))} | |
121 | - </Select> | |
122 | - </Form.Item> | |
123 | - <Form.Item label="粘稠度" name="oilViscosity" rules={[{ required: true }]}> | |
124 | - <Select placeholder="请选择粘稠度" showSearch optionFilterProp="children"> | |
125 | - {oilViscosityData.map((i) => ( | |
126 | - <Select.Option value={i.value || 0} key={i.value || 0}> | |
127 | - {i.value || '--'} | |
128 | - </Select.Option> | |
129 | - ))} | |
130 | - </Select> | |
131 | - </Form.Item> | |
132 | - </Form> | |
133 | - </Modal> | |
134 | - ); | |
135 | -} | |
136 | - | |
137 | -export default NewOilModal; |
src/pages/cas/afterSaleConfiguration/maintainConfig/subpages/MaintainEdit/components/EngineOilSelector/components/OilSelector.tsx
1 | -import React, { useState, useEffect } from 'react'; | |
2 | -import { Modal, Table, Spin } from 'antd'; | |
1 | +import React, { useEffect, useState } from 'react'; | |
2 | +import { Modal, Spin, Table } from 'antd'; | |
3 | 3 | |
4 | 4 | import useInitail from '@/hooks/useInitail'; |
5 | 5 | |
... | ... | @@ -10,16 +10,15 @@ const Column = Table.Column; |
10 | 10 | |
11 | 11 | interface Props { |
12 | 12 | visible: boolean; |
13 | - confirming?: boolean; | |
13 | + selected: Maintain.OilGroup[]; // 已选机油 | |
14 | 14 | onCancel: () => void; |
15 | - onConfirm: (selectItems: Maintain.ItemListVO[]) => void; | |
15 | + onConfirm: (selectItems: Maintain.OilGroup[]) => void; | |
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * 油料选择器 |
20 | - * @onConfirm workItems:选中的油料 | |
21 | 20 | */ |
22 | -export default function OilSelector({ visible, confirming = false, onCancel, onConfirm }: Props) { | |
21 | +export default function OilSelector({ visible, selected, onCancel, onConfirm }: Props) { | |
23 | 22 | const [delay, setDelay] = useState(true); |
24 | 23 | const [selectItems, setSelectItems] = useState<Maintain.OilGroup[]>([]); |
25 | 24 | |
... | ... | @@ -29,17 +28,25 @@ export default function OilSelector({ visible, confirming = false, onCancel, onC |
29 | 28 | if (visible) { |
30 | 29 | setDelay(false); |
31 | 30 | setParams(undefined, true); |
31 | + | |
32 | + if (selected?.length > 0) { | |
33 | + setSelectItems(selected); | |
34 | + } | |
32 | 35 | } |
33 | - }, [visible]); | |
36 | + }, [visible, selected]); | |
37 | + | |
38 | + const handleConfirm = () => { | |
39 | + onConfirm(selectItems); | |
40 | + setSelectItems([]); | |
41 | + }; | |
34 | 42 | |
35 | 43 | return ( |
36 | 44 | <Modal |
37 | 45 | title="选择作机油" |
38 | 46 | width={780} |
39 | 47 | open={visible} |
40 | - confirmLoading={confirming} | |
41 | 48 | okButtonProps={{ disabled: selectItems.length === 0 }} |
42 | - onOk={() => onConfirm(selectItems)} | |
49 | + onOk={handleConfirm} | |
43 | 50 | onCancel={onCancel} |
44 | 51 | destroyOnClose |
45 | 52 | > |
... | ... | @@ -52,7 +59,7 @@ export default function OilSelector({ visible, confirming = false, onCancel, onC |
52 | 59 | rowSelection={{ |
53 | 60 | type: 'checkbox', |
54 | 61 | selectedRowKeys: selectItems.map((si) => si.id) || [], |
55 | - onChange: (selectedRowKeys, selectedRows: Maintain.ItemListVO[]) => { | |
62 | + onChange: (selectedRowKeys, selectedRows: Maintain.OilGroup[]) => { | |
56 | 63 | setSelectItems(selectedRows); |
57 | 64 | }, |
58 | 65 | }} |
... | ... | @@ -65,12 +72,17 @@ export default function OilSelector({ visible, confirming = false, onCancel, onC |
65 | 72 | } |
66 | 73 | }, |
67 | 74 | })} |
75 | + footer={() => ( | |
76 | + <span> | |
77 | + 已选:<span className={st.colorPrimary}>{`${selectItems.length} `}</span>项 | |
78 | + </span> | |
79 | + )} | |
68 | 80 | > |
69 | - <Column title="机油名称" dataIndex="oilBrandName" /> | |
81 | + <Column title="机油品牌" dataIndex="oilBrandName" /> | |
70 | 82 | <Column title="型号" dataIndex="oilModel" /> |
71 | - <Column title="粘稠度" dataIndex="oilViscosity" /> | |
72 | - <Column title="等级" dataIndex="oilLevel" /> | |
73 | 83 | <Column title="类型" dataIndex="motorOilType" /> |
84 | + <Column title="等级" dataIndex="oilLevel" /> | |
85 | + <Column title="粘稠度" dataIndex="oilViscosity" /> | |
74 | 86 | </Table> |
75 | 87 | </Spin> |
76 | 88 | </Modal> | ... | ... |
src/pages/cas/afterSaleConfiguration/maintainConfig/subpages/MaintainEdit/components/EngineOilSelector/index.tsx
1 | 1 | import React, { useEffect, useState } from 'react'; |
2 | -import { Button, Row, Table } from 'antd'; | |
2 | +import { Button, Row, Table, Tag } from 'antd'; | |
3 | 3 | import { MenuOutlined } from '@ant-design/icons'; |
4 | 4 | import type { SortableContainerProps, SortEnd } from 'react-sortable-hoc'; |
5 | 5 | import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; |
6 | 6 | import { arrayMoveImmutable } from 'array-move'; |
7 | 7 | |
8 | -import NewOilModal from './components/NewOilModal'; | |
9 | 8 | import OilSelector from './components/OilSelector'; |
10 | 9 | import OilData from './components/OilData'; |
11 | 10 | |
... | ... | @@ -21,18 +20,36 @@ export interface Props { |
21 | 20 | oilGroups: Maintain.OilGroup[]; |
22 | 21 | capacity: number; |
23 | 22 | disabled?: boolean; |
24 | - onChange?: (data: any[]) => void; | |
23 | + onChange?: (data: Maintain.OilGroup[]) => void; | |
25 | 24 | } |
26 | 25 | |
27 | -export default function EngineOilSelector(props: Props) { | |
28 | - const { oilGroups, capacity, disabled, onChange } = props; | |
29 | - | |
26 | +export default function EngineOilSelector({ oilGroups, capacity, disabled, onChange }: Props) { | |
30 | 27 | const [visible, setVisible] = useState<boolean>(false); |
31 | - const [current, setCurrent] = useState({} as Maintain.OilGroup); | |
32 | 28 | const [oilData, setOilData] = useState<any>({ visible: false, data: {} }); |
33 | 29 | |
34 | 30 | const [dataSource, setDataSource] = useState<any[]>([]); |
35 | 31 | |
32 | + useEffect(() => { | |
33 | + const _list = oilGroups.map((e) => { | |
34 | + return { | |
35 | + ...e, | |
36 | + // 拼接 e 中属性为 id值 | |
37 | + id: `${e.oilBrandName}-${e.oilModel}-${e.motorOilType}-${e.oilLevel}-${e.oilViscosity}` | |
38 | + }; | |
39 | + }); | |
40 | + setDataSource([..._list]); | |
41 | + }, [oilGroups]); | |
42 | + | |
43 | + const handleOilSelect = (selectOils: Maintain.OilGroup[]) => { | |
44 | + onChange && onChange(selectOils); | |
45 | + setVisible(false); | |
46 | + }; | |
47 | + | |
48 | + const handleOilDelete = (index: number) => { | |
49 | + oilGroups.splice(index, 1); | |
50 | + onChange && onChange(oilGroups); | |
51 | + }; | |
52 | + | |
36 | 53 | const onSortEnd = ({ oldIndex, newIndex }: SortEnd) => { |
37 | 54 | if (oldIndex !== newIndex) { |
38 | 55 | const newData = arrayMoveImmutable(dataSource.slice(), oldIndex, newIndex).filter((el: any) => !!el); |
... | ... | @@ -51,41 +68,6 @@ export default function EngineOilSelector(props: Props) { |
51 | 68 | return <SortableItem index={index} {...restProps} />; |
52 | 69 | }; |
53 | 70 | |
54 | - useEffect(() => { | |
55 | - const _list = oilGroups.map((e, i) => { | |
56 | - return { | |
57 | - ...e, | |
58 | - id: i, | |
59 | - }; | |
60 | - }); | |
61 | - setDataSource([..._list]); | |
62 | - }, [oilGroups]); | |
63 | - | |
64 | - function _onOk(data: Maintain.OilGroup[]) { | |
65 | - onChange && onChange(data); | |
66 | - setVisible(false); | |
67 | - } | |
68 | - | |
69 | - function onDelete(record: Maintain.OilGroup) { | |
70 | - const _items = oilGroups; | |
71 | - const index = _items.findIndex((e) => { | |
72 | - return ( | |
73 | - e.oilBrandId === record.oilBrandId && | |
74 | - e.motorOilType === record.motorOilType && | |
75 | - e.oilLevel === record.oilLevel && | |
76 | - e.oilModel === record.oilModel && | |
77 | - e.oilViscosity === record.oilViscosity | |
78 | - ); | |
79 | - }); | |
80 | - _items.splice(index, 1); | |
81 | - _onOk(_items); | |
82 | - } | |
83 | - | |
84 | - function edit(record: Maintain.OilGroup, index: number) { | |
85 | - setCurrent({ ...record, oil: { value: record.oilBrandId, label: record.oilBrandName }, index }); | |
86 | - setVisible(true); | |
87 | - } | |
88 | - | |
89 | 71 | return ( |
90 | 72 | <div style={{ marginTop: 30 }}> |
91 | 73 | <Row justify="space-between" align="middle" style={{ marginBottom: 16 }}> |
... | ... | @@ -113,7 +95,22 @@ export default function EngineOilSelector(props: Props) { |
113 | 95 | }} |
114 | 96 | > |
115 | 97 | <Column align="center" className="drag-visible" title="拖拽排序" dataIndex="sort" width={100} render={() => <DragHandle />} /> |
116 | - <Column className="drag-visible" title="推荐顺序" dataIndex="oilIndex" width={100} render={(text, record, index) => <div>{index + 1}</div>} /> | |
98 | + <Column | |
99 | + className="drag-visible" | |
100 | + title="推荐顺序" | |
101 | + dataIndex="oilIndex" | |
102 | + width={160} | |
103 | + render={(text, record, index) => ( | |
104 | + <div> | |
105 | + {index + 1} | |
106 | + {index === 0 && ( | |
107 | + <Tag style={{ marginLeft: 5 }} color={'#FF9211'}> | |
108 | + 厂家首保机油 | |
109 | + </Tag> | |
110 | + )} | |
111 | + </div> | |
112 | + )} | |
113 | + /> | |
117 | 114 | <Column className="drag-visible" title="机油品牌" dataIndex="oilBrandName" /> |
118 | 115 | <Column className="drag-visible" title="机油型号" dataIndex="oilModel" /> |
119 | 116 | <Column className="drag-visible" title="机油类型" dataIndex="motorOilType" /> |
... | ... | @@ -135,40 +132,20 @@ export default function EngineOilSelector(props: Props) { |
135 | 132 | width={150} |
136 | 133 | align="center" |
137 | 134 | render={(text, record: Maintain.OilGroup, index) => ( |
138 | - <> | |
139 | - <Button onClick={() => edit(record, index)} type="link" size="small"> | |
140 | - 编辑 | |
141 | - </Button> | |
142 | - <Button onClick={() => onDelete(record)} type="link" danger size="small"> | |
143 | - 删除 | |
144 | - </Button> | |
145 | - </> | |
135 | + <Button onClick={() => handleOilDelete(index)} type="link" danger size="small"> | |
136 | + 删除 | |
137 | + </Button> | |
146 | 138 | )} |
147 | 139 | /> |
148 | 140 | </Table> |
149 | - {/*<NewOilModal*/} | |
150 | - {/* selected={[...oilGroups]}*/} | |
151 | - {/* onOk={_onOk}*/} | |
152 | - {/* visible={visible}*/} | |
153 | - {/* onCancel={() => setVisible(false)}*/} | |
154 | - {/* current={current}*/} | |
155 | - {/* setCurrent={setCurrent}*/} | |
156 | - {/*/>*/} | |
157 | - <OilSelector | |
158 | - visible={visible} | |
159 | - onCancel={() => setVisible(false)} | |
160 | - onConfirm={(selectOils) => { | |
161 | - console.log('log=>selectOils', selectOils); | |
162 | - setVisible(false); | |
163 | - }} | |
164 | - /> | |
141 | + | |
142 | + <OilSelector visible={visible} selected={dataSource} onCancel={() => setVisible(false)} onConfirm={handleOilSelect} /> | |
165 | 143 | <OilData |
166 | 144 | visible={oilData.visible} |
145 | + data={oilData.data} | |
167 | 146 | onCancel={() => { |
168 | 147 | setOilData({ visible: false, data: {} }); |
169 | - setCurrent({} as Maintain.OilGroup); | |
170 | 148 | }} |
171 | - data={oilData.data} | |
172 | 149 | /> |
173 | 150 | </div> |
174 | 151 | ); | ... | ... |
src/pages/cas/afterSaleConfiguration/maintainConfig/subpages/MaintainEdit/components/PartFilter/index.tsx
... | ... | @@ -105,7 +105,8 @@ export default function PartFilter({ partFilters, brandId, onChange }: Props) { |
105 | 105 | } |
106 | 106 | |
107 | 107 | const EditableCell: React.FC<EditableCellProps> = ({ editing, dataIndex, title, inputType, record, index, children, ...restProps }) => { |
108 | - const inputNode = <InputNumber />; | |
108 | + // todo 液态配件可以输入小数 | |
109 | + const inputNode = <InputNumber precision={0} />; | |
109 | 110 | |
110 | 111 | return ( |
111 | 112 | <td {...restProps}> | ... | ... |