Commit 2c747d4a authored by Bill's avatar Bill

fix: 删除Drawer 组件

parent 483cf50c
import ProductPanel from './productPanel';
import Product from './product';
export {
ProductPanel,
Product
};
.container {
.product {
position: relative;
&:hover {
.actions {
display: block;
}
}
}
.actions {
display: none;
position: absolute;
top: 4px;
right: 8px;
.iconContainer {
background: rgba(0, 0, 0, 0.5);
padding: 2px 4px;
cursor: pointer;
.icon {
color: #fff;
}
}
}
}
import React, { useContext, useEffect, useMemo, useState } from 'react';
import { Space, message } from 'antd';
import { useSelector } from '@lingxi-disign/react';
import { useToggle } from '@umijs/hooks';
import { GetMarketingPlatformActivityListAdornRequest } from '@/services/MaketingV2Api';
import { PublicApi } from '@/services/api';
import { resetCurrentComponent,} from '@lingxi-disign/core';
import { get } from 'lodash';
import styles from './productPanel.less';
import Product from './product';
import Drawer from '../Drawer';
import ActivityProductDrawer from '../ActivityAreaSetting/activityProductDrawer';
import { Context as ShopContext } from '../../common/context/shopContext';
interface Iprops {
visible: boolean,
onCancel?: null | (() => void)
value: any,
isWithLabels: boolean,
/** 活动类型, */
activityType?: number | null
}
const ProductPanel: React.FC<Iprops> = (props: Iprops) => {
const { visible, onCancel, value, isWithLabels, activityType } = props;
const { shopId } = useContext(ShopContext) || {};
const { pageConfig, selectedInfo } = useSelector<any, any>(['pageConfig', 'selectedInfo']);
const { state: productVisible, toggle: setProductVisible } = useToggle();
const [innerProducts, setInnerProducts] = useState<any>(null);
const activityImage = useMemo(() => pageConfig[1]?.props?.imageUrl, [pageConfig]);
const cacheProductList = useMemo(() => [innerProducts], [innerProducts]);
const onEdit = () => {
setProductVisible(true);
};
useEffect(() => {
if (!visible) {
return;
}
setInnerProducts(value);
}, [value, visible]);
const fetchData = async (params: GetMarketingPlatformActivityListAdornRequest) => {
const withActivityType = activityType ? { activityType: activityType } : {};
/** @tofix shopId */
const common = {
...params,
shopId: shopId,
...withActivityType
};
const isWithActivityType = common;
return await PublicApi.getMarketingAdornMerchantActivityListAdorn(isWithActivityType as any);
};
const onOk = (data: any) => {
const target = data[0];
if (target.activityId !== innerProducts.activityId || target.id !== innerProducts.id) {
setInnerProducts(data[0]);
}
setProductVisible(false);
};
const handleSubmit = () => {
console.log(innerProducts)
if(innerProducts === null) {
message.error("请选择活动商品");
return;
}
const currentKey = selectedInfo.selectedKey;
const parentKey = selectedInfo.parentKey;
const parentNode = get(pageConfig, [parentKey]);
const { childNodes, props } = parentNode;
const newNodeProps = childNodes.map((_item) => {
const elementProps = pageConfig[_item].props;
if (currentKey === _item) {
return innerProducts;
}
return elementProps;
});
resetCurrentComponent({
parentKey: parentKey,
childrenNode: newNodeProps.map((_item, index) => {
const otherProps = isWithLabels ? { isWithLabels: true } : {};
return {
key: `${parentKey}-${index + 1}`,
title: _item.productName,
props: _item,
componentName: props.theme === 2 ? 'CommodityList.CommodityTab' : 'CommodityList.Item',
...otherProps
};
}),
props: {
...props,
children: newNodeProps.map((_item) => _item.id),
products: newNodeProps
}
});
};
const onLabelChange = (data: { id: number, activityId: number, label: string[] }) => {
const current = {...innerProducts};
current["label"] = data.label;
setInnerProducts(current);
};
return (
<Drawer title="商品设置" visible={visible} onCancel={onCancel} onSubmit={handleSubmit}>
<div className={styles.container}>
<div className={styles.product}>
<Product
activityImage={activityImage}
onEdit={onEdit}
isWithLabels={isWithLabels}
onLabelChange={onLabelChange}
{...innerProducts}
/>
</div>
</div>
<ActivityProductDrawer
activityImage={activityImage}
products={cacheProductList}
onOk={onOk}
fetchData={fetchData}
visible={productVisible}
onCancel={() => setProductVisible(false)}
mode="radio"
/>
</Drawer>
);
};
export default ProductPanel;
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