Commit a0d2fee9 authored by beisir's avatar beisir

fix: 批量设置

parent 8a5a0130
import { InputNumber, InputRef } from 'antd';
import { Button, Form, Input, Popconfirm, Table } from 'antd';
import type { FormInstance } from 'antd/es/form';
import React, { useContext, useEffect, useRef, useState } from 'react';
import React, { useContext, useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
const EditableContext = React.createContext<FormInstance<any> | null>(null);
interface DataType {
rowSpanCount?: number;
supplyPrice: number;
commissionRate: number;
marketPrice: number;
salePrice: number;
stock: number;
productStockWarning: number;
}
interface PropType {
initData: any[];
defaultColumns: any[];
setTableData: (item: DataType[]) => {};
};
interface Item {
key: string;
......@@ -26,15 +37,7 @@ interface EditableCellProps {
interface EditableRowProps {
index: number;
}
interface DataType {
rowSpanCount?: number;
supplyPrice: number;
commissionRate: number;
marketPrice: number;
salePrice: number;
stock: number;
productStockWarning: number;
}
type EditableTableProps = Parameters<typeof Table>[0];
type ColumnTypes = Exclude<EditableTableProps['columns'], undefined>;
......@@ -74,16 +77,15 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
};
let childNode = children;
if (editable) {
// if (editable) {
childNode = <Form.Item
style={{ margin: 0 }}
name={['tableList', rowIndex, dataIndex]}
// initialValue={record[dataIndex]}
rules={[{ required: true, message: `${title} is required.` }]}>
<InputNumber onBlur={save} />
{editable ?<InputNumber onBlur={save} /> : children[1]}
</Form.Item>
}
// }
return <td {...restProps}>{childNode}</td>;
};
......@@ -91,9 +93,9 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
const EditFormTable = (props: PropType) => {
const EditFormTable = forwardRef((props: PropType, ref) => {
const { initData } = props;
const { initData, defaultColumns, setTableData } = props;
// console.log(initData);
const [dataSource, setDataSource] = useState<DataType[]>([]);
const [form] = Form.useForm();
......@@ -108,48 +110,6 @@ const EditFormTable = (props: PropType) => {
setDataSource(initData);
}, [initData])
const defaultColumns: (ColumnTypes[number] & { editable?: boolean; dataIndex: string })[] = [
{
title: '一级规格',
dataIndex: 'firstSpecValue',
},
{
title: '二级规格',
dataIndex: 'secondSpecValue',
},
{
title: '供货价',
dataIndex: 'supplyPrice',
editable: true,
},
{
title: '佣金费率',
dataIndex: 'commissionRate',
editable: true,
},
{
title: '市场价',
dataIndex: 'marketPrice',
editable: true,
},
{
title: '销售价',
dataIndex: 'salePrice',
editable: true,
},
{
title: '库存',
dataIndex: 'stock',
editable: true,
},
{
title: '库存预警阈值',
dataIndex: 'productStockWarning',
editable: true,
},
];
const handleAdd = async () => {
try {
const { tableList } = await form.validateFields();
......@@ -168,8 +128,25 @@ const EditFormTable = (props: PropType) => {
// ...item,
// ...row,
// });
setDataSource([...row]);
setTableData([...row]);
};
const onCheck = async () => {
try {
const values = await form.validateFields();
return values;
} catch (errorInfo) {
return null;
}
};
useImperativeHandle(ref, () => ({
onCheck,
form,
}));
// 根据这里做判断渲染表格
const columns = defaultColumns.map((col, colIndex) => {
// if (!col.editable) {
......@@ -201,9 +178,6 @@ const EditFormTable = (props: PropType) => {
return (
<div>
<Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>
Add a row
</Button>
<Form form={form} scrollToFirstError component={false}>
<EditableContext.Provider value={form}>
<Table
......@@ -221,9 +195,10 @@ const EditFormTable = (props: PropType) => {
columns={columns as ColumnTypes}
/>
</EditableContext.Provider>
<Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>Add a row</Button>
</Form>
</div>
);
};
});
export default EditFormTable;
\ No newline at end of file
......@@ -64,3 +64,36 @@ export const WeeksList = [
value: 7,
},
];
export const StaticColumns = [{
title: '供货价',
dataIndex: 'supplyPrice',
editable: true,
},
{
title: '佣金费率',
dataIndex: 'commissionRate',
editable: true,
role: [],
},
{
title: '市场价',
dataIndex: 'marketPrice',
editable: true,
},
{
title: '销售价',
dataIndex: 'salePrice',
editable: true,
},
{
title: '库存',
dataIndex: 'stock',
editable: true,
},
{
title: '库存预警阈值',
dataIndex: 'productStockWarning',
editable: true,
role: [],
}];
import React, { useState, useRef, useEffect } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Spin, Button } from 'antd';
import { ConsoleSqlOutlined } from '@ant-design/icons';
// import { getAppChannelAllList } from '@/services/common';
import { Title, WrapperContainer } from './components/CommonTemplate';
import { TaskTypeSelect } from './components/TaskTypeSelect';
import { Task } from './type';
......@@ -28,30 +25,19 @@ import { ServiceContext } from './context';
const ServiceGoods = options => {
const pageId = +options.match.params.id; // pageId: 0-新增,1-修改,2-查看
const ref = useRef();
const basicRef = useRef(null);
const stockRef = useRef(null);
const settingRef = useRef(null);
const settleOtrRef = useRef(null);
const [isEdit, setIsEdit] = useState(false);
const [productType, setProductType] = useState(1);
const [pageLoading, setPageLoading] = useState(false);
const [isEdit, setIsEdit] = useState(false); // 是否是编辑状态
const [productType, setProductType] = useState(1); // 商品状态
const [pageLoading, setPageLoading] = useState(false); // 页面加载状态
const [categoryList, setCategoryList] = useState([]); // 获取三级类目
const [brandList, setBrandList] = useState([]); // 获取商品牌
const [specList, setSpecList] = useState([]); // 规格列表
const [examLoading, setExamLoading] = useState(false);
const [channelAllList, setChannelAllList] = useState({});
const [editData, setEditData] = useState({});
// const refreshTable = () => {
// ref.current.reload();
// };
const [editData, setEditData] = useState({}); // 编辑保存数据
// useEffect(() => {
// getChannelAllList();
// }, []);
// const onReset = () => {};
const productChange = (task: Task): void => {
setProductType(task.type);
};
......@@ -66,6 +52,7 @@ const ServiceGoods = options => {
console.log(resuslt);
};
// 编辑回显详情数据
const getProductDetailResponse = async () => {
try {
const res = await getProductDetail(pageId);
......@@ -112,7 +99,7 @@ const ServiceGoods = options => {
<Spin tip="正在加载..." spinning={pageLoading} delay={100}>
<PageHeaderWrapper className={commonStyle.header}>
<WrapperContainer>
<ServiceContext.Provider value={{ pageId, isEdit }}>
<ServiceContext.Provider value={{ pageId, isEdit, productType }}>
<Title title="商品类型" />
<TaskTypeSelect productType={productType} onChange={productChange} />
......
import { Button, Form, Input, Popconfirm, Table } from 'antd';
export interface Task {
name: string;
type: number;
desc: string;
}
interface EditableRowProps {
index: number;
}
export type EditableTableProps = Parameters<typeof Table>[0];
export type ColumnTypes = Exclude<EditableTableProps['columns'], undefined>;
......@@ -16,8 +16,6 @@ const createInitProduct = (skuItem, isCreate) => {
return skuItem;
}
return {
// firstSpecValue: '',
// secondSpecValue: '',
weight: null,
productStockWarning: null,
marketPrice: null,
......@@ -29,8 +27,6 @@ const createInitProduct = (skuItem, isCreate) => {
};
const initData = {
// firstSpecValue: '',
// secondSpecValue: '',
weight: null,
productStockWarning: null,
marketPrice: null,
......@@ -42,8 +38,6 @@ const initData = {
const createSecondProduct = (secondSpecList, initItem, secondSpec, dataSource, callback) => {
secondSpecList.forEach(secondItem => {
console.log('============>', Object.keys(secondItem));
const specSecond =
Object.keys(secondItem).length < 2
? {
......@@ -83,7 +77,6 @@ export const createProductData = ({ firstValues, secondValues, firstSpecId, seco
dataSource.push(specFirst);
});
} else if (secondValues.length) {
// const childData = createInitProduct();
createSecondProduct(secondValues, initData, secondSpecId, dataSource);
} else {
const specFirst = createInitProduct();
......
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