import { PlusOutlined } from '@ant-design/icons'; import { ActionType, ProColumns, ProFormInstance, ProFormText, ProFormDigit, ProFormRadio, ProFormDependency, } from '@ant-design/pro-components'; import { ModalForm, PageContainer, ProTable } from '@ant-design/pro-components'; import '@umijs/max'; import { Button } from 'antd'; import dayjs from 'dayjs'; import React, { useEffect, useRef, useState } from 'react'; import { TIME_FORMAT } from '@/constants/global'; import { postGiveVip, getGiveVipList, getProductList } from '@/services/list'; const ProductTypeText: Record = { VIP: '主播', BOSSVIP: 'BOSSVIP', GROUP_BATCH_PUSH: 'GROUP_BATCH_PUSH', BOSS_VIP_NEW: '企业', }; const TableList: React.FC = () => { const [updateModalOpen, handleUpdateModalOpen] = useState(false); const [productVipList, setProductVipList] = useState([]); const [productBossVipList, setProductBossVipList] = useState([]); const actionRef = useRef(); const formRef = useRef(); const getProducts = async () => { try { const [vipList, bossVipList] = await Promise.all([getProductList('VIP'), getProductList('BOSS_VIP_NEW')]); setProductVipList(vipList); setProductBossVipList(bossVipList); } catch (e) { } finally { } }; useEffect(() => { getProducts(); }, []); const columns: ProColumns[] = [ { title: '用户ID', dataIndex: 'userId', valueType: 'textarea', search: true, }, { title: '用户手机号', dataIndex: 'userPhone', valueType: 'textarea', search: true, }, { title: '类型', dataIndex: 'productType', valueType: 'textarea', search: false, renderText: productType => ProductTypeText[productType as API.ProductType], }, { title: '会员', dataIndex: 'productSpecId', valueType: 'textarea', search: false, renderText: (productSpecId: string, record: API.GiveVipListItem) => { let product; if (record.productType === 'VIP') { product = productVipList.find(it => it.productSpecId === productSpecId); } if (record.productType === 'BOSS_VIP_NEW') { product = productBossVipList.find(it => it.productSpecId === productSpecId); } return product ? product.productName : productSpecId || '-'; }, }, { title: '赠送个数', dataIndex: 'giveCount', valueType: 'textarea', search: false, }, { title: '赠送时间', dataIndex: 'createTime', valueType: 'dateTime', renderText(created: string) { return dayjs(created).format(TIME_FORMAT); }, search: false, }, ]; return ( headerTitle="查询表格" actionRef={actionRef} rowKey="key" search={{ labelWidth: 120, collapsed: false, collapseRender: false }} request={getGiveVipList} columns={columns} toolBarRender={() => [ , ]} /> { const params: API.PostGiveVip = { userId: formData.userId, userPhone: formData.userPhone, productType: formData.productType, productSpecId: formData.productSpecId, giveCount: formData.giveCount, }; console.log('update confirm', formData, params); try { await postGiveVip(params); actionRef.current?.reload(); formRef.current?.resetFields(); } catch (e) {} handleUpdateModalOpen(false); }} > { formRef.current?.setFieldsValue({ productSpecId: undefined, }); }, }} options={[ { value: 'VIP', label: ProductTypeText.VIP, }, { value: 'BOSS_VIP_NEW', label: ProductTypeText.BOSS_VIP_NEW, }, ]} /> {({ productType }) => { return ( ({ value: it.productSpecId, label: it.productName, }))} rules={[{ required: true, message: '必填项' }]} /> ); }} ); }; export default TableList;