diff --git a/src/pages/ProductList/add.tsx b/src/pages/ProductList/add.tsx index fb239fb..3937d2f 100644 --- a/src/pages/ProductList/add.tsx +++ b/src/pages/ProductList/add.tsx @@ -8,7 +8,6 @@ import { ProCard, ProForm, ProFormCascader, - ProFormCheckbox, ProFormDigit, ProFormInstance, ProFormList, @@ -20,9 +19,9 @@ import { import { PageContainer } from '@ant-design/pro-layout'; import { DndContext, DragEndEvent, PointerSensor, useSensor } from '@dnd-kit/core'; import { arrayMove, SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable'; -import { Button, Col, message, Row } from 'antd'; +import { Button, Col, Flex, message, Row, Tag, Tooltip } from 'antd'; import Upload, { RcFile, UploadFile } from 'antd/es/upload'; -import React, { useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { CSS } from '@dnd-kit/utilities'; import { getLabelListForAdminUsingPost } from '@/services/pop-b2b2c/pbcProductLabelConfigController'; @@ -62,7 +61,15 @@ const Detail: React.FC = () => { const [colorData, setColorData] = useState() const [commonDataList, setCommonDataList] = useState() - const [labelAssociations, setLabelAssociationList] = useState() + // const [labelAssociations, setLabelAssociationList] = useState() + + const [tags, setTags] = useState([]) + // const [inputVisible, setInputVisible] = useState(false); + // const [loading, setLoading] = useState(false); + // const [inputValue, setInputValue] = useState(''); + // const inputRef = useRef(null); + const [selectedTags, setSelectedTags] = useState([]); + const [pbcBusinessId, setPbcBusinessId] = useState(); const formRef = useRef(); @@ -90,14 +97,75 @@ const Detail: React.FC = () => { } } + const getTags = () => { + if (pbcBusinessId) { + getLabelListForAdminUsingPost({pbcBusinessId}).then(res => { + const arr: API.PbcProductLabelConfig_[] = [] + if (res.retcode && res.data) { + const data: API.PbcProductLabelConfigVO = res.data || [] as API.PbcProductLabelConfigVO + if (data.systemLabelList) { + arr.push(...data.systemLabelList) + } + if (data.frequentLabelList) { + arr.push(...data.frequentLabelList) + } + if (data.businessLabelList) { + arr.push(...data.businessLabelList) + } + } + setTags(arr) + }).catch(() => { setTags([]) }) + } + } + + useEffect(() => { + getTags() + }, [pbcBusinessId]) + + // useEffect(() => { + // if (inputVisible) { + // inputRef.current?.focus(); + // } + // }, [inputVisible]); + + const handleChange = (tag: API.PbcProductLabelConfig_, checked: boolean) => { + const nextSelectedTags = checked && tag.pbcId + ? [...selectedTags, tag.pbcId] + : selectedTags.filter((t) => t !== tag.pbcId); + setSelectedTags(nextSelectedTags); + }; + + // const showInput = () => { + // setInputVisible(true); + // }; + + // const handleInputChange = (e: React.ChangeEvent) => { + // setInputValue(e.target.value); + // }; + + // const handleInputConfirm = () => { + // if (inputValue && pbcBusinessId) { + // setLoading(true) + // const params: API.PbcProductLabelConfig_ = { + // pbcLabelName: inputValue, + // pbcBusinessId: pbcBusinessId + // } + // addOrUpdateLabelConfigForAdminUsingPost(params).then(res => { + // if (res.retcode) { + // getTags() + // setInputVisible(false); + // setInputValue(''); + // } + // }).catch(() => { }).finally(() => setLoading(false)) + // } + // }; + const onSubmit = async (values: any) => { let pbcProductOriginalProvince = undefined, pbcProductOriginalCity = undefined; if (values?.pbcZone?.length) { ([pbcProductOriginalProvince, pbcProductOriginalCity] = values.pbcZone); } const [pbcProductTopCategoryId, pbcProductParentCategoryId, pbcProductCategoryId] = values.pbcProductCategoryIdList - console.log(values.colorItems) - console.log(values.specItems) const specItems: API.PbcProductCommonData[] = [] if (colorData && values.colorItems && values.colorItems.length > 0) { for (let i = 0; i < values.colorItems.length; i++) { @@ -129,7 +197,11 @@ const Detail: React.FC = () => { }) } } - const labelAssociationList = labelAssociations?.filter(e => values.labelAssociationList && values.labelAssociationList.includes(e.pbcId)) + //标签 + let labelAssociationList: API.PbcProductLabelConfig_[] = [] + if (selectedTags.length > 0) { + labelAssociationList = tags.filter(it => it.pbcId && selectedTags.includes(it.pbcId)) + } const params: API.PbcProductDTO = { ...values, labelAssociationList, @@ -205,19 +277,20 @@ const Detail: React.FC = () => { ]} onChange={(value) => { formRef.current?.setFieldValue('labelAssociationList', []) - if (value) { - getLabelListForAdminUsingPost({ pbcBusinessId: value as number }).then(res => { - if (res.retcode && res.data) { - setLabelAssociationList(res.data.systemLabelList) - } else { - setLabelAssociationList([]) - } - }).catch(() => { - setLabelAssociationList([]) - }) - } else { - setLabelAssociationList([]) - } + setPbcBusinessId(value as number) + // if (value) { + // getLabelListForAdminUsingPost({ pbcBusinessId: value as number }).then(res => { + // if (res.retcode && res.data) { + // setLabelAssociationList(res.data.systemLabelList) + // } else { + // setLabelAssociationList([]) + // } + // }).catch(() => { + // setLabelAssociationList([]) + // }) + // } else { + // setLabelAssociationList([]) + // } }} request={ async () => { const msg = await getPbcBusinessListUsingPost(); @@ -281,7 +354,46 @@ const Detail: React.FC = () => { - + + {tags.map((tag) => { + const isLongTag = tag.pbcLabelName && tag.pbcLabelName.length > 20; + const tagElem = ( + handleChange(tag, checked)} + style={{ userSelect: 'none', padding: 8, border: '1px solid' }} + > + {isLongTag ? `${tag.pbcLabelName?.slice(0, 20)}...` : tag.pbcLabelName} + + ); + return isLongTag ? ( + + {tagElem} + + ) : ( + tagElem + ); + })} + {/* {inputVisible ? ( + + ) : ( + } onClick={showInput}> + 添加 + + )} */} + + + {/* = () => { rules={[ { required: true, message: '请选择商品标签' }, ]} - /> + /> */} {colorData ?