import Tables from "@/components/Tables" import { useAjax } from "@/Hook/useAjax" import { getGoodsApi, synGoodsApi } from "@/services/launchAdq/createAd" import { CheckOutlined, SyncOutlined } from "@ant-design/icons" import { Button, Modal, Space } from "antd" import React, { useEffect, useState } from "react" import style from './index.less' import columns from './tableConfig' /** * 获取商品列表 * @returns */ interface Props { visible?: boolean, onClose?: () => void, onChange?: (data: any) => void, data: any } const GoodsModal: React.FC = (props) => { /************************/ const { visible, onClose, data: data1, onChange } = props const [tableData, setTableData] = useState([])//table数据 const [selectAdz, setSelectAdz] = useState(1) // 选择广告主 const [data, setData] = useState(data1) const getGoods = useAjax((params) => getGoodsApi(params)) const synGoods = useAjax((params) => synGoodsApi(params)) /************************/ useEffect(() => { if (data?.length > 0) { getList([data[selectAdz - 1].adAccountId]) } else { setTableData([]) } }, [selectAdz]) // 获取商品列表 const getList = (params: number[]) => { getGoods.run(params).then(res => { console.log('res===>', res) if (res && Object.keys(res)?.indexOf(params[0].toString()) !== -1) { setTableData(res[params[0]]?.map((item: { productOuterId: string }) => ({ ...item, id: Number(item?.productOuterId?.replace(/\D/ig, '')) }))) } else { setTableData([]) } }) } const handleOk = () => { onChange && onChange(data) } // 同步商品库 const synGoodsList = () => { synGoods.run(data?.map((item: { id: number }) => item?.id)).then(res => { getList([data[selectAdz - 1].adAccountId]) }) } /** 设置选中广告主 */ const handleSelectAdz = (value: number, item: any) => { if (value === selectAdz) { return } setSelectAdz(value) } /** 表格选折 */ const onChangeTable = (selectedRowKeys: React.Key[], selectedRows: any) => { let newData = JSON.parse(JSON.stringify(data)) newData[selectAdz - 1]['productList'] = selectedRows setData([...newData]) } return 商品库 } visible={visible} onCancel={() => { onClose && onClose() }} onOk={handleOk} width={1100} className={style.SelectPackage} bodyStyle={{ padding: '0 10px 0 10px' }} >

广告主账户

{data?.map((item: { adAccountId: number, id: number }, index: number) => (
{ handleSelectAdz(index + 1, item) }} className={`${style.accItem} ${selectAdz === index + 1 && style.select} `}> {item?.adAccountId} {data[index].productList?.length > 0 && }
))}
{/*

商品库

{goodsData?.map((item: { name: string, goodsList: any[], catalogId: number }, index: number) => (
{ handleGoods(index + 1, { ...queryFormDetail, godsId: goodsData[index].catalogId }) }} className={`${style.accItem} ${selectGoods === index + 1 && style.select} `}> {item?.name} {orientPackage[selectAdz - 1]?.goods?.key === item?.catalogId && orientPackage[selectAdz - 1].goods?.data?.length > 0 && }
)) }
*/}
item?.id?.toString()), onChange: onChangeTable }} />
} export default React.memo(GoodsModal)