功能:后台管理页面添加商品绑定话题id功能

上级 e4dc018d
...@@ -109,6 +109,7 @@ export type exchangeGoodsInfoType = InterFunction<{ firstId: number; secondId: n ...@@ -109,6 +109,7 @@ export type exchangeGoodsInfoType = InterFunction<{ firstId: number; secondId: n
//商品-新增(新) //商品-新增(新)
//商品item类型 //商品item类型
type goodsItemType = { type goodsItemType = {
gambitId: number;
categoryPrimaryId: number; categoryPrimaryId: number;
categorySubId: number; categorySubId: number;
description: string; description: string;
......
...@@ -15,9 +15,17 @@ interface selfProps { ...@@ -15,9 +15,17 @@ interface selfProps {
onOk: () => void; onOk: () => void;
onCancel: () => void; onCancel: () => void;
currentTopicItem: topicListType[0] | undefined; currentTopicItem: topicListType[0] | undefined;
showProperty?: boolean;
} }
const AddTopicModal: FC<ModalProps & selfProps> = ({ open, onCancel, onOk, currentTopicItem }) => {
const AddTopicModal: FC<ModalProps & selfProps> = ({
open,
onCancel,
onOk,
currentTopicItem,
showProperty = true,
}) => {
const [form] = Form.useForm<addTopicParams>(); const [form] = Form.useForm<addTopicParams>();
const [gambitIconFileList, setGambitIconFileList] = useState<any>([]); const [gambitIconFileList, setGambitIconFileList] = useState<any>([]);
const [gambitCoverFileList, setGambitCoverFileList] = useState<any>([]); const [gambitCoverFileList, setGambitCoverFileList] = useState<any>([]);
...@@ -130,13 +138,15 @@ const AddTopicModal: FC<ModalProps & selfProps> = ({ open, onCancel, onOk, curre ...@@ -130,13 +138,15 @@ const AddTopicModal: FC<ModalProps & selfProps> = ({ open, onCancel, onOk, curre
<UploadOutlined /> <UploadOutlined />
</Uploader> </Uploader>
</Form.Item> </Form.Item>
<Form.Item {showProperty && (
label='属性' <Form.Item
name='gambitProperty' label='属性'
rules={[{ required: true, message: '请选择属性' }]} name='gambitProperty'
> rules={[{ required: true, message: '请选择属性' }]}
<Select placeholder='请选择属性' options={gambitPropertyList}></Select> >
</Form.Item> <Select placeholder='请选择属性' options={gambitPropertyList}></Select>
</Form.Item>
)}
</Form> </Form>
</Modal> </Modal>
); );
......
...@@ -8,3 +8,17 @@ ...@@ -8,3 +8,17 @@
transform: translate(50%,-25%); transform: translate(50%,-25%);
} }
} }
.gambit-choose {
display: flex;
marginLeft: 200px;
width: 800px;
flex-wrap: nowrap;
.Form-item {
width: 300px;
margin-right: 20px;
padding-left: 20px;
.Select {
padding-left: 400px;
}
}
}
\ No newline at end of file
...@@ -3,16 +3,19 @@ import { Uploader } from '~/components/uploader'; ...@@ -3,16 +3,19 @@ import { Uploader } from '~/components/uploader';
import type { RadioChangeEvent } from 'antd'; import type { RadioChangeEvent } from 'antd';
import { UploadOutlined } from '@ant-design/icons'; import { UploadOutlined } from '@ant-design/icons';
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'; import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { InterDataType } from '~/api/interface'; import { InterDataType, InterListType } from '~/api/interface';
import { categoryListRespType } from '~/api/interface/categoryManage'; import { categoryListRespType } from '~/api/interface/categoryManage';
import { CategoryManageAPI } from '~/api'; import { CategoryManageAPI, ForumManageAPI } from '~/api';
import deletePng from '~/assets/image/delete.png'; import deletePng from '~/assets/image/delete.png';
import './index.scss'; import './index.scss';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import AddTopicModal from '~/pages/forumManage/topicList/components/addTopicModal';
import { listGambitType } from '~/api/interface/forumManageType';
//分类返回类型 //分类返回类型
type categoryType = InterDataType<categoryListRespType>['list']; type categoryType = InterDataType<categoryListRespType>['list'];
// 话题列表返回类型
type topicListType = InterListType<listGambitType>;
interface selfProps { interface selfProps {
ref: any; ref: any;
} }
...@@ -38,18 +41,27 @@ export type baseInfoType = { ...@@ -38,18 +41,27 @@ export type baseInfoType = {
uid: number; uid: number;
url: string; url: string;
}[]; }[];
gambitId: number;
categoryId: number[]; categoryId: number[];
shelfStatus: number; shelfStatus: number;
labelShow: number; labelShow: number;
goodsLabel: string; goodsLabel: string;
}; };
const { Option } = Select;
const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
const { userInfo } = useSelector((state: any) => state.UserInfo); const { userInfo } = useSelector((state: any) => state.UserInfo);
const [baseInfoForm] = Form.useForm<baseInfoType>(); const [baseInfoForm] = Form.useForm<baseInfoType>();
const [labelShow, setLabelShow] = useState<boolean>(false); const [labelShow, setLabelShow] = useState<boolean>(false);
//分类列表 //分类列表
const [categoryList, setCategoryList] = useState<categoryType>([]); const [categoryList, setCategoryList] = useState<categoryType>([]);
const [addTopicModalShow, setAddTopicModalShow] = useState<boolean>(false);
const [currentTopicItem, setCurrentTopicItem] = useState<topicListType[0]>();
const [gambitList, setGambitList] = useState<
{
id: number;
name: string;
}[]
>([]);
//主图 //主图
const [mainFileList, setMainFileList] = useState< const [mainFileList, setMainFileList] = useState<
{ {
...@@ -125,6 +137,32 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { ...@@ -125,6 +137,32 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
setCategoryList(result.list || []); setCategoryList(result.list || []);
}); });
}; };
const getGambitList = () => {
ForumManageAPI.getTopicList({ pageNo: 1, pageSize: 99999 }).then(({ result }) => {
// 使用map方法创建新的数组,仅包含id和gambitName字段
const gambitTempList = result.list.map((item) => ({
id: item.id,
name: item.gambitName,
}));
const gambitListWithDefinedNames = gambitTempList.map((item) => ({
...item,
name: item.name || '',
}));
setGambitList(gambitListWithDefinedNames);
});
};
const addTopicModalShowOk = () => {
setAddTopicModalShow(false);
};
const addTopicModalCancel = () => {
setAddTopicModalShow(false);
};
const addTopicModalShowClick = (record?: topicListType[0]) => {
setCurrentTopicItem(record ? { ...record } : undefined);
setAddTopicModalShow(true);
};
//视频删除 //视频删除
const deleteVideo = () => { const deleteVideo = () => {
setVideoFileList([]); setVideoFileList([]);
...@@ -133,8 +171,8 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { ...@@ -133,8 +171,8 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
useEffect(() => { useEffect(() => {
getCategoryList(); getCategoryList();
getGambitList();
}, []); }, []);
return ( return (
<div className='base-info'> <div className='base-info'>
<Form <Form
...@@ -185,6 +223,7 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { ...@@ -185,6 +223,7 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
<Form.Item label='商品视频' name='videoList'> <Form.Item label='商品视频' name='videoList'>
{videoFileList.length ? ( {videoFileList.length ? (
<div className='goods-video-wrap'> <div className='goods-video-wrap'>
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
<video <video
src={videoFileList[0].url} src={videoFileList[0].url}
style={{ width: '200px', height: '200px' }} style={{ width: '200px', height: '200px' }}
...@@ -248,6 +287,35 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { ...@@ -248,6 +287,35 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
<Radio value={0}>不显示</Radio> <Radio value={0}>不显示</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<div className='flex-start gambit-choose'>
<Form.Item
label='关联话题'
name='gambitId'
rules={[{ required: false, message: '请选择话题' }]}
>
<Select
placeholder='请选择话题'
showSearch
optionFilterProp='children' // 指定筛选的字段
filterOption={(input, option) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
option?.children?.toLowerCase().includes(input.toLowerCase())
}
// value={baseInfoForm.getFieldValue('gambitId')}
// onSelect={(e) => baseInfoForm.setFieldValue('gambitId', e)}
>
{gambitList.map((i, j) => (
<Option key={j} value={i.id}>
{i.name}
</Option>
))}
</Select>
</Form.Item>
<Button type='primary' onClick={() => addTopicModalShowClick()}>
新建
</Button>
</div>
{labelShow ? ( {labelShow ? (
<Form.Item <Form.Item
label='商品标签' label='商品标签'
...@@ -259,6 +327,13 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => { ...@@ -259,6 +327,13 @@ const BaseInfo = forwardRef<any, selfProps>((_props, ref) => {
) : ( ) : (
'' ''
)} )}
<AddTopicModal
open={addTopicModalShow}
onCancel={addTopicModalCancel}
onOk={addTopicModalShowOk}
currentTopicItem={currentTopicItem}
showProperty={false}
/>
</Form> </Form>
</div> </div>
); );
......
...@@ -101,12 +101,19 @@ const GoodsAddOrEditOrDetail = () => { ...@@ -101,12 +101,19 @@ const GoodsAddOrEditOrDetail = () => {
]) ])
.then((values: any) => { .then((values: any) => {
const addGoodsEditReq = { const addGoodsEditReq = {
...filterObjAttr(values[0], ['mainImgList', 'subImgList', 'videoList', 'categoryId']), ...filterObjAttr(values[0], [
'mainImgList',
'subImgList',
'videoList',
'gambitList',
'categoryId',
]),
resourcesList: [ resourcesList: [
...values[0].mainImgList.map((v: any) => ({ type: 0, url: v.url })), ...values[0].mainImgList.map((v: any) => ({ type: 0, url: v.url })),
...(values[0].subImgList?.map((v: any) => ({ type: 1, url: v.url })) || []), ...(values[0].subImgList?.map((v: any) => ({ type: 1, url: v.url })) || []),
...(values[0].videoList?.map((v: any) => ({ type: 2, url: v.url })) || []), ...(values[0].videoList?.map((v: any) => ({ type: 2, url: v.url })) || []),
], ],
gambitId: values[0].gambitId,
categoryPrimaryId: values[0].categoryId[0], categoryPrimaryId: values[0].categoryId[0],
categorySubId: values[0].categoryId.length === 2 ? values[0].categoryId[1] : undefined, categorySubId: values[0].categoryId.length === 2 ? values[0].categoryId[1] : undefined,
goodsDetails, goodsDetails,
...@@ -166,6 +173,7 @@ const GoodsAddOrEditOrDetail = () => { ...@@ -166,6 +173,7 @@ const GoodsAddOrEditOrDetail = () => {
goodsLabel: result.goodsLabel || undefined, goodsLabel: result.goodsLabel || undefined,
priceShow: result.priceShow, priceShow: result.priceShow,
recommend: result.recommend, recommend: result.recommend,
gambitId: result.gambitId,
}); });
baseInfoRef.current.setLabelShow(!!result.labelShow); baseInfoRef.current.setLabelShow(!!result.labelShow);
baseInfoRef.current.mediaData.setMainFileList(mainImgList); baseInfoRef.current.mediaData.setMainFileList(mainImgList);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论