dev-v2
parent
5df7630661
commit
2263402cd3
@ -0,0 +1,185 @@
|
|||||||
|
import { listAdminTreeUsingGet } from '@/services/pop-b2b2c/pbcCategoryController';
|
||||||
|
import {
|
||||||
|
addOrUpdateFashionTrendUsingPost,
|
||||||
|
fashionTrendDetailForAdminUsingGet,
|
||||||
|
} from '@/services/pop-b2b2c/pbcFashionTrendController';
|
||||||
|
import { getProductPageForAdminUsingPost } from '@/services/pop-b2b2c/pbcProductController';
|
||||||
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
|
import { ProTable } from '@ant-design/pro-components';
|
||||||
|
import { useAccess, useModel } from '@umijs/max';
|
||||||
|
import { message, Modal } from 'antd';
|
||||||
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
interface LinkProductModalProps {
|
||||||
|
visible: boolean;
|
||||||
|
onCancel: () => void;
|
||||||
|
trendId?: number;
|
||||||
|
onSuccess: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LinkProductModal: React.FC<LinkProductModalProps> = ({
|
||||||
|
visible,
|
||||||
|
onCancel,
|
||||||
|
trendId,
|
||||||
|
onSuccess,
|
||||||
|
}) => {
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||||
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
|
const [detailInfo, setDetailInfo] = useState<API.PbcFashionTrend_>();
|
||||||
|
const access: any = useAccess();
|
||||||
|
const { initialState } = useModel('@@initialState');
|
||||||
|
const { currentUser } = initialState || { currentUser: {} };
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (visible && trendId) {
|
||||||
|
fetchTrendDetail(trendId);
|
||||||
|
} else {
|
||||||
|
setSelectedRowKeys([]);
|
||||||
|
}
|
||||||
|
}, [visible, trendId]);
|
||||||
|
|
||||||
|
const fetchTrendDetail = async (id: number) => {
|
||||||
|
try {
|
||||||
|
const res = await fashionTrendDetailForAdminUsingGet({ pbcId: id });
|
||||||
|
if (res.retcode && res.data) {
|
||||||
|
const productIds = res.data.pbcProductIds
|
||||||
|
? res.data.pbcProductIds.split(',').map(Number)
|
||||||
|
: [];
|
||||||
|
setSelectedRowKeys(productIds);
|
||||||
|
setDetailInfo(res.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取详情失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOk = async () => {
|
||||||
|
if (!trendId) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const pbcProductIds = selectedRowKeys.join(',');
|
||||||
|
const res = await addOrUpdateFashionTrendUsingPost({
|
||||||
|
...detailInfo,
|
||||||
|
pbcId: trendId,
|
||||||
|
pbcProductIds: pbcProductIds,
|
||||||
|
});
|
||||||
|
if (res.retcode) {
|
||||||
|
message.success('关联成功');
|
||||||
|
onSuccess();
|
||||||
|
onCancel();
|
||||||
|
} else {
|
||||||
|
message.error(res.retmsg || '关联失败');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message.error('关联失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ProColumns<API.PbcProductVO>[] = [
|
||||||
|
{
|
||||||
|
title: '商品ID',
|
||||||
|
dataIndex: 'pbcId',
|
||||||
|
search: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '商品大类',
|
||||||
|
dataIndex: 'pbcProductTopCategoryName',
|
||||||
|
search: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '商品中类',
|
||||||
|
dataIndex: 'pbcProductParentCategoryName',
|
||||||
|
search: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '商品小类',
|
||||||
|
dataIndex: 'pbcProductCategoryName',
|
||||||
|
search: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '商品类目',
|
||||||
|
dataIndex: 'pbcProductCategoryId',
|
||||||
|
hideInTable: true,
|
||||||
|
valueType: 'cascader',
|
||||||
|
fieldProps: {
|
||||||
|
fieldNames: { label: 'pbcCategoryName', value: 'pbcId', children: 'children' },
|
||||||
|
},
|
||||||
|
request: async () => {
|
||||||
|
const msg = await listAdminTreeUsingGet({ type: 2 });
|
||||||
|
if (msg.retcode && msg.data) {
|
||||||
|
return msg.data;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '商品名称',
|
||||||
|
dataIndex: 'pbcProductTitle',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '款号',
|
||||||
|
dataIndex: 'pbcProductCode',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title="关联商品"
|
||||||
|
open={visible}
|
||||||
|
onCancel={onCancel}
|
||||||
|
onOk={handleOk}
|
||||||
|
width={1000}
|
||||||
|
confirmLoading={loading}
|
||||||
|
destroyOnHidden
|
||||||
|
>
|
||||||
|
<ProTable<API.PbcProductVO>
|
||||||
|
columns={columns}
|
||||||
|
actionRef={actionRef}
|
||||||
|
request={async (params) => {
|
||||||
|
const queryParam: API.PbcProductPageDTO = {
|
||||||
|
...params,
|
||||||
|
startDate:
|
||||||
|
params.pbcCreateAt && params.pbcCreateAt.length > 1
|
||||||
|
? params.pbcCreateAt[0]
|
||||||
|
: undefined,
|
||||||
|
endDate:
|
||||||
|
params.pbcCreateAt && params.pbcCreateAt.length > 1
|
||||||
|
? params.pbcCreateAt[1] + ' 23:59:59'
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
if (params.pbcProductCategoryId && params.pbcProductCategoryId.length === 3) {
|
||||||
|
queryParam.pbcProductCategoryId = params.pbcProductCategoryId[2];
|
||||||
|
}
|
||||||
|
queryParam.pbcUserType = 2;
|
||||||
|
if (access.isBusiness) {
|
||||||
|
queryParam.pbcBusinessId = currentUser?.pbcBusinessId;
|
||||||
|
}
|
||||||
|
const msg = await getProductPageForAdminUsingPost(queryParam);
|
||||||
|
return {
|
||||||
|
data: msg.data?.records || [],
|
||||||
|
success: !!msg.retcode,
|
||||||
|
total: msg.data?.total,
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
rowKey="pbcId"
|
||||||
|
search={{
|
||||||
|
labelWidth: 'auto',
|
||||||
|
}}
|
||||||
|
pagination={{
|
||||||
|
pageSize: 10,
|
||||||
|
}}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys,
|
||||||
|
onChange: (keys) => setSelectedRowKeys(keys),
|
||||||
|
preserveSelectedRowKeys: true,
|
||||||
|
}}
|
||||||
|
toolBarRender={false}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinkProductModal;
|
||||||
Loading…
Reference in New Issue