Commit 57d51709 authored by beisir's avatar beisir

fix: 删除ts

parent e95e3d78
...@@ -710,7 +710,7 @@ class goodsManage extends Component { ...@@ -710,7 +710,7 @@ class goodsManage extends Component {
</Col> </Col>
{specListData.length {specListData.length
? specListData.map((item, index) => ( ? specListData.map((item, index) => (
<Col span={24}> <Col key={item.specId} span={24}>
<FormItem label={item.specName} labelCol={{ span: 2 }}> <FormItem label={item.specName} labelCol={{ span: 2 }}>
{getFieldDecorator(`${item.specId}`, { {getFieldDecorator(`${item.specId}`, {
initialValue: initData[item.specId], initialValue: initData[item.specId],
......
import { InputNumber, Button, Form, Table } from 'antd'; import { InputNumber, Button, Form, Table } from 'antd';
import React, { useContext, createContext, useEffect, useState, forwardRef, useImperativeHandle } from 'react'; import React, {
useContext,
createContext,
useEffect,
useState,
forwardRef,
useImperativeHandle,
} from 'react';
import { ServiceContext } from '../context'; import { ServiceContext } from '../context';
const EditableContext = createContext(null); const EditableContext = createContext(null);
const EditableRow= ({ index, ...props }) => { const EditableRow = ({ index, ...props }) => <tr {...props} />;
// console.log('==========> index', props); const EditableCell = props => {
// const [form] = Form.useForm();
// console.log('==========>props', props)
return (
// <Form form={form} component={false}>
// <EditableContext.Provider value={form}>
<tr {...props} />
// </EditableContext.Provider>
// </Form>
);
};
const EditableCell = (props) => {
const { const {
rowIndex, rowIndex,
title, title,
...@@ -30,7 +24,7 @@ const EditableCell = (props) => { ...@@ -30,7 +24,7 @@ const EditableCell = (props) => {
...restProps ...restProps
} = props; } = props;
const form = useContext(EditableContext)!; const form = useContext(EditableContext);
const save = async () => { const save = async () => {
try { try {
const tableList = form.getFieldValue('tableList'); const tableList = form.getFieldValue('tableList');
...@@ -40,22 +34,19 @@ const EditableCell = (props) => { ...@@ -40,22 +34,19 @@ const EditableCell = (props) => {
} }
}; };
let childNode = children; const childNode = (
childNode = <Form.Item <Form.Item
style={{ margin: 0 }} style={{ margin: 0 }}
name={['tableList', rowIndex, dataIndex]} name={['tableList', rowIndex, dataIndex]}
rules={[{ required: true, message: `${title} is required.` }]}> rules={[{ required: true, message: `${title} is required.` }]}
>
{editable ? <InputNumber onBlur={save} /> : children[1]} {editable ? <InputNumber onBlur={save} /> : children[1]}
</Form.Item> </Form.Item>
);
return <td {...restProps}>{childNode}</td>; return <td {...restProps}>{childNode}</td>;
}; };
const EditFormTable = forwardRef((props, ref) => { const EditFormTable = forwardRef((props, ref) => {
const { initData, defaultColumns, setTableData, mergeTable } = props; const { initData, defaultColumns, setTableData, mergeTable } = props;
const customer = useContext(ServiceContext); const customer = useContext(ServiceContext);
const [dataSource, setDataSource] = useState([]); const [dataSource, setDataSource] = useState([]);
...@@ -66,7 +57,7 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -66,7 +57,7 @@ const EditFormTable = forwardRef((props, ref) => {
tableList: initData, tableList: initData,
}); });
setDataSource(initData); setDataSource(initData);
}, [initData]) }, [initData]);
const handleAdd = async () => { const handleAdd = async () => {
try { try {
...@@ -77,11 +68,10 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -77,11 +68,10 @@ const EditFormTable = forwardRef((props, ref) => {
} }
}; };
const handleSave = (row) => { const handleSave = row => {
setTableData([...row]); setTableData([...row]);
}; };
const onCheck = async () => { const onCheck = async () => {
try { try {
const values = await form.validateFields(); const values = await form.validateFields();
...@@ -96,15 +86,10 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -96,15 +86,10 @@ const EditFormTable = forwardRef((props, ref) => {
form, form,
})); }));
// 根据这里做判断渲染表格 // 根据这里做判断渲染表格
const columns = defaultColumns const columns = defaultColumns
.filter(item => { .filter(item => !item.role || item.role.includes(customer.productType))
// console.log('===============>column', item); .map((col, colIndex) => ({
return !item.role || item.role.includes(customer.productType);
})
.map((col, colIndex) => {
return {
...col, ...col,
onCell: (record, rowIndex) => { onCell: (record, rowIndex) => {
let rowSpan = null; let rowSpan = null;
...@@ -112,7 +97,7 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -112,7 +97,7 @@ const EditFormTable = forwardRef((props, ref) => {
rowSpan = record.rowSpanCount || 0; rowSpan = record.rowSpanCount || 0;
} }
return ({ return {
rowSpan, rowSpan,
record, record,
rowIndex, rowIndex,
...@@ -120,10 +105,9 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -120,10 +105,9 @@ const EditFormTable = forwardRef((props, ref) => {
dataIndex: col.dataIndex, dataIndex: col.dataIndex,
title: col.title, title: col.title,
handleSave, handleSave,
});
}
}; };
}); },
}));
return ( return (
<div> <div>
...@@ -144,7 +128,9 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -144,7 +128,9 @@ const EditFormTable = forwardRef((props, ref) => {
columns={columns} columns={columns}
/> />
</EditableContext.Provider> </EditableContext.Provider>
<Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>Add a row</Button> <Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>
Add a row
</Button>
</Form> </Form>
</div> </div>
); );
......
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