Commit 7fbd131f authored by luoxiaodong's avatar luoxiaodong

三级联动

parent 90658caf
// import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Form, Button, Input, Select, notification, Upload, Cascader, InputNumber } from 'antd'; import { Form, Button, Input, Select, notification, Upload, Cascader, InputNumber } from 'antd';
import '@ant-design/compatible/assets/index.css';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import styles from '../style.less'; import styles from '../style.less';
...@@ -14,6 +11,7 @@ const { Option } = Select; ...@@ -14,6 +11,7 @@ const { Option } = Select;
})) }))
class goodsManage extends Component { class goodsManage extends Component {
formRef = React.createRef(); formRef = React.createRef();
componentDidMount() { componentDidMount() {
this.props.onRef(this); this.props.onRef(this);
this.handleSearch(); this.handleSearch();
...@@ -27,6 +25,7 @@ class goodsManage extends Component { ...@@ -27,6 +25,7 @@ class goodsManage extends Component {
handleSearch = () => { handleSearch = () => {
this.props.handleSearch(1); this.props.handleSearch(1);
}; };
valueMin = value => { valueMin = value => {
const { getFieldValue, setFieldsValue } = this.formRef.current; const { getFieldValue, setFieldsValue } = this.formRef.current;
const minVal = getFieldValue('supplyPriceMin'); const minVal = getFieldValue('supplyPriceMin');
...@@ -34,11 +33,13 @@ class goodsManage extends Component { ...@@ -34,11 +33,13 @@ class goodsManage extends Component {
setFieldsValue({ supplyPriceMax: minVal }); setFieldsValue({ supplyPriceMax: minVal });
} }
}; };
onReset = () => { onReset = () => {
const form = this.formRef.current; const form = this.formRef.current;
form.resetFields(); form.resetFields();
this.props.onReset(); this.props.onReset();
}; };
addSpu = () => { addSpu = () => {
this.props.addSpu(); this.props.addSpu();
}; };
......
import { Form, Modal, Input, Select, Cascader, Tag, notification } from 'antd'; import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Modal, Input, Select, Cascader, Tag, notification } from 'antd';
import { da } from 'date-fns/locale'; import { da } from 'date-fns/locale';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { getTemplate } from '../service'; import { getTemplate } from '../service';
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
import { Form } from '@ant-design/compatible'; import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css'; import '@ant-design/compatible/assets/index.css';
import { MinusCircleOutlined, PlusOutlined, RestOutlined } from '@ant-design/icons';
import { import {
Modal, Modal,
Table, Table,
Button, Button,
Select, Select,
Input, Input,
Icon,
Row, Row,
Col, Col,
Checkbox, Checkbox,
...@@ -680,9 +680,8 @@ class goodsManage extends Component { ...@@ -680,9 +680,8 @@ class goodsManage extends Component {
/>, />,
)} )}
{firstKeys.length > 0 ? ( {firstKeys.length > 0 ? (
<Icon <MinusCircleOutlined
className="dynamic-delete-button" className="dynamic-delete-button"
type="minus-circle-o"
onClick={() => this.remove('firstKeys', k)} onClick={() => this.remove('firstKeys', k)}
/> />
) : null} ) : null}
...@@ -695,7 +694,7 @@ class goodsManage extends Component { ...@@ -695,7 +694,7 @@ class goodsManage extends Component {
onClick={() => this.add('firstKeys')} onClick={() => this.add('firstKeys')}
style={{ textAlign: 'center' }} style={{ textAlign: 'center' }}
> >
<Icon type="plus" /> <PlusOutlined />
</Button> </Button>
</FormItem> </FormItem>
</Row> </Row>
...@@ -744,9 +743,8 @@ class goodsManage extends Component { ...@@ -744,9 +743,8 @@ class goodsManage extends Component {
validateTrigger: ['onChange', 'onBlur'], validateTrigger: ['onChange', 'onBlur'],
})(<Input key={k} style={{ width: '60%', marginRight: 8 }} />)} })(<Input key={k} style={{ width: '60%', marginRight: 8 }} />)}
{secondKeys.length > 0 ? ( {secondKeys.length > 0 ? (
<Icon <MinusCircleOutlined
className="dynamic-delete-button" className="dynamic-delete-button"
type="minus-circle-o"
onClick={() => this.remove('secondKeys', k)} onClick={() => this.remove('secondKeys', k)}
/> />
) : null} ) : null}
...@@ -759,7 +757,7 @@ class goodsManage extends Component { ...@@ -759,7 +757,7 @@ class goodsManage extends Component {
style={{ textAlign: 'center' }} style={{ textAlign: 'center' }}
disabled={isJDGoods} disabled={isJDGoods}
> >
<Icon type="plus" /> <PlusOutlined />
</Button> </Button>
</FormItem> </FormItem>
</Row> </Row>
...@@ -815,7 +813,7 @@ class goodsManage extends Component { ...@@ -815,7 +813,7 @@ class goodsManage extends Component {
size="small" size="small"
onClick={this.deleteImg} onClick={this.deleteImg}
style={{ marginTop: '10px' }} style={{ marginTop: '10px' }}
icon="rest" icon={<RestOutlined />}
> >
图片批量删除 图片批量删除
</Button> </Button>
......
import { Form, Modal, Input, Select, Cascader, Tag, notification } from 'antd'; import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Modal, Input, Select, Cascader, Tag, notification } from 'antd';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import RcTreeSelect from 'rc-tree-select';
import { el } from 'date-fns/locale'; import { el } from 'date-fns/locale';
import { areaList, getAddTemplate, forbiddenAddress } from '../services'; import { areaList, getAddTemplate, forbiddenAddress } from '../services';
...@@ -9,10 +10,11 @@ const { Option } = Select; ...@@ -9,10 +10,11 @@ const { Option } = Select;
const AddAreaModal = props => { const AddAreaModal = props => {
const { const {
visible, visible,
form: { getFieldDecorator, validateFields, resetFields }, form: { getFieldDecorator, validateFields, resetFields, setFieldsValue },
templateData, templateData,
} = props; } = props;
const [addList, setAddList] = useState([]); const [addList, setAddList] = useState([]);
const [initList, setInitList] = useState([]);
const [selectedList, setSelectedList] = useState([]); const [selectedList, setSelectedList] = useState([]);
const [selected, setSelect] = useState([]); const [selected, setSelect] = useState([]);
const a = []; const a = [];
...@@ -38,6 +40,7 @@ const AddAreaModal = props => { ...@@ -38,6 +40,7 @@ const AddAreaModal = props => {
}), }),
); );
setAddList(newData); setAddList(newData);
setInitList(newData);
} }
}; };
...@@ -59,14 +62,19 @@ const AddAreaModal = props => { ...@@ -59,14 +62,19 @@ const AddAreaModal = props => {
value: itemData.addrId, value: itemData.addrId,
addressId: itemData.addrId, addressId: itemData.addrId,
addressLevel: itemData.addrLevel, addressLevel: itemData.addrLevel,
// isLeaf: itemData.addrLevel === 4,
isLeaf: false, isLeaf: false,
}), }),
); );
targetOption.children = newData; targetOption.children = newData;
let checkedData = [];
if (targetOption.addressLevel > 1) {
checkedData = initList.concat(targetOption).concat(newData);
} else {
checkedData = initList.concat(newData);
}
targetOption.loading = false;
setAddList([...addList]);
} }
targetOption.loading = false;
setAddList([...addList]);
}; };
// 限制区域删除 // 限制区域删除
const preventDefault = val => { const preventDefault = val => {
...@@ -119,45 +127,40 @@ const AddAreaModal = props => { ...@@ -119,45 +127,40 @@ const AddAreaModal = props => {
}); });
}; };
// 判断是否重复 // 判断是否重复
const getChilds = (data, { addressId }) => { const getChilds = (data, address) => {
let flag = true;
const arr = []; const arr = [];
function judgeChildren(dat) { const reslutData = [];
// eslint-disable-next-line no-plusplus for (let i = 0; i < data.length; i += 1) {
for (let i = 0; i < dat.length; i++) { const item = data[i];
const item = dat[i]; if (!item.addressName.includes(address.addressName)) {
if (!flag) { arr.push(item);
return;
}
if (+item.addressId === +addressId) {
flag = false;
}
// if (item.children && item.children.length) {
// judgeChildren(item.children);
// }
} }
} }
judgeChildren(data); for (let i = 0; i < arr.length; i += 1) {
return flag; const item = arr[i];
if (!address.addressName.includes(item.addressName)) {
reslutData.push(item);
}
}
return reslutData;
}; };
const onPopupVisibleChange = labels => { const onPopupVisibleChange = labels => {
if (!labels && selected?.length) { if (!labels && selected?.length) {
let data = selectedList;
const select = selected.slice(-1)[0]; const select = selected.slice(-1)[0];
const arr = selected.map(x => x.label); const arr = selected.map(x => x.label);
select.addressName = arr.join('/'); select.addressName = arr.join('/');
const staust = getChilds(selectedList, select); const staust = getChilds(data, select);
if (staust) { staust.push(select);
selectedList.push(select); data = staust;
// 用中文字符排序 // 用中文字符排序
const resultArray = selectedList.sort((param1, param2) => const resultArray = data.sort((param1, param2) =>
param1.addressName.localeCompare(param2.addressName, 'zh'), param1.addressName.localeCompare(param2.addressName, 'zh'),
); );
setSelectedList([...resultArray]); setSelectedList([...resultArray]);
setSelect([]); setSelect([]);
}
} }
}; };
useEffect(() => { useEffect(() => {
getAreaList(); getAreaList();
if (props.templateData) { if (props.templateData) {
...@@ -189,9 +192,8 @@ const AddAreaModal = props => { ...@@ -189,9 +192,8 @@ const AddAreaModal = props => {
loadData={loadData} loadData={loadData}
onChange={(val, label) => onChange(val, label)} onChange={(val, label) => onChange(val, label)}
allowClear={false} allowClear={false}
// expandTrigger="hover"
changeOnSelect changeOnSelect
onPopupVisibleChange={onPopupVisibleChange} onDropdownVisibleChange={onPopupVisibleChange}
/>, />,
)} )}
{selectedList?.map((selItem, selIndex) => ( {selectedList?.map((selItem, selIndex) => (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment