|
|
@ -4,6 +4,7 @@ import { CaretDownOutlined } from '@ant-design/icons';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import useProductsStore from '@/stores/Products/Index';
|
|
|
|
import useProductsStore from '@/stores/Products/Index';
|
|
|
|
import { useProductsTypes, useProductsAuditStatesMapVal } from '@/hooks/useProductsSets';
|
|
|
|
import { useProductsTypes, useProductsAuditStatesMapVal } from '@/hooks/useProductsSets';
|
|
|
|
|
|
|
|
import { groupBy, sortBy } from '@/utils/commons';
|
|
|
|
|
|
|
|
|
|
|
|
const flattenTreeFun = (tree) => {
|
|
|
|
const flattenTreeFun = (tree) => {
|
|
|
|
let flatList = [];
|
|
|
|
let flatList = [];
|
|
|
@ -52,6 +53,13 @@ const ProductsTree = ({ onNodeSelect, ...props }) => {
|
|
|
|
// 只显示有产品的类型;
|
|
|
|
// 只显示有产品的类型;
|
|
|
|
// const title = text || r.lgc_details?.['2']?.title || r.lgc_details?.['1']?.title || '';
|
|
|
|
// const title = text || r.lgc_details?.['2']?.title || r.lgc_details?.['1']?.title || '';
|
|
|
|
const hasDataTypes = Object.keys(agencyProducts);
|
|
|
|
const hasDataTypes = Object.keys(agencyProducts);
|
|
|
|
|
|
|
|
// const cityData = groupBy(productsSortByHT, (row) => `${row.info.city_id}-${row.info.city_name}`);
|
|
|
|
|
|
|
|
const copyAgencyProducts = structuredClone(agencyProducts);
|
|
|
|
|
|
|
|
Object.keys(copyAgencyProducts).map((key) => {
|
|
|
|
|
|
|
|
const _cityProductsData = groupBy(copyAgencyProducts[key], (row) => `${row.info.city_name || '(空)'}`);
|
|
|
|
|
|
|
|
copyAgencyProducts[key] = _cityProductsData;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// console.log(copyAgencyProducts);
|
|
|
|
const _show = productsTypes
|
|
|
|
const _show = productsTypes
|
|
|
|
.filter((kk) => hasDataTypes.includes(kk.value))
|
|
|
|
.filter((kk) => hasDataTypes.includes(kk.value))
|
|
|
|
.map((ele) => ({
|
|
|
|
.map((ele) => ({
|
|
|
@ -62,10 +70,20 @@ const ProductsTree = ({ onNodeSelect, ...props }) => {
|
|
|
|
const lgc_map = product.lgc_details.reduce((rlgc, clgc) => ({...rlgc, [clgc.lgc]: clgc}), {});
|
|
|
|
const lgc_map = product.lgc_details.reduce((rlgc, clgc) => ({...rlgc, [clgc.lgc]: clgc}), {});
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
title: product.info.title || lgc_map?.['2']?.title || lgc_map?.['1']?.title || '',
|
|
|
|
title: product.info.title || lgc_map?.['2']?.title || lgc_map?.['1']?.title || '',
|
|
|
|
|
|
|
|
// title: `【${product.info.city_name}】` + (product.info.title || lgc_map?.['2']?.title || lgc_map?.['1']?.title || ''),
|
|
|
|
// key: `${ele.value}-${product.info.id}`,
|
|
|
|
// key: `${ele.value}-${product.info.id}`,
|
|
|
|
key: product.info.id,
|
|
|
|
key: product.info.id,
|
|
|
|
_raw: product,
|
|
|
|
_raw: product,
|
|
|
|
|
|
|
|
isLeaf: true,
|
|
|
|
}}),
|
|
|
|
}}),
|
|
|
|
|
|
|
|
// 增加`城市`层级
|
|
|
|
|
|
|
|
_children: Object.keys(copyAgencyProducts[ele.value] || []).map(city => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
title: city,
|
|
|
|
|
|
|
|
key: `${ele.value}-${city}`,
|
|
|
|
|
|
|
|
children: copyAgencyProducts[ele.value][city],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
setTreeData(_show);
|
|
|
|
setTreeData(_show);
|
|
|
|
setRawTreeData(_show);
|
|
|
|
setRawTreeData(_show);
|
|
|
@ -88,12 +106,17 @@ const ProductsTree = ({ onNodeSelect, ...props }) => {
|
|
|
|
setSearchValue(value);
|
|
|
|
setSearchValue(value);
|
|
|
|
setAutoExpandParent(true);
|
|
|
|
setAutoExpandParent(true);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const handleNodeSelect = (_, { node }) => {
|
|
|
|
const handleNodeSelect = (selectedKeys, { node }) => {
|
|
|
|
if (node._raw) {
|
|
|
|
if (node._raw) {
|
|
|
|
setEditingProduct(node._raw);
|
|
|
|
setEditingProduct(node._raw);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 单击: 折叠/展开
|
|
|
|
|
|
|
|
// const isExpand = expandedKeys.includes(selectedKeys[0]);
|
|
|
|
|
|
|
|
// const _keys = isExpand ? expandedKeys.filter(k => k !== node.key) : [].concat(expandedKeys, selectedKeys);
|
|
|
|
|
|
|
|
// setExpandedKeys(_keys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof onNodeSelect === 'function') {
|
|
|
|
if (typeof onNodeSelect === 'function') {
|
|
|
|
onNodeSelect(_, { node });
|
|
|
|
onNodeSelect(selectedKeys, { node });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const onExpand = (keys) => {
|
|
|
|
const onExpand = (keys) => {
|
|
|
@ -123,7 +146,7 @@ const ProductsTree = ({ onNodeSelect, ...props }) => {
|
|
|
|
<Input.Search placeholder='Search' onChange={onSearch} allowClear className='sticky top-1 z-20 mb-3' />
|
|
|
|
<Input.Search placeholder='Search' onChange={onSearch} allowClear className='sticky top-1 z-20 mb-3' />
|
|
|
|
<Tree
|
|
|
|
<Tree
|
|
|
|
blockNode
|
|
|
|
blockNode
|
|
|
|
showLine
|
|
|
|
showLine defaultExpandAll expandAction={'doubleClick'}
|
|
|
|
selectedKeys={[editingProduct?.info?.id || editingProduct?.info?.product_type_id]}
|
|
|
|
selectedKeys={[editingProduct?.info?.id || editingProduct?.info?.product_type_id]}
|
|
|
|
switcherIcon={<CaretDownOutlined />}
|
|
|
|
switcherIcon={<CaretDownOutlined />}
|
|
|
|
onSelect={handleNodeSelect}
|
|
|
|
onSelect={handleNodeSelect}
|
|
|
|