Commit 8a5a0130 authored by beisir's avatar beisir

fix: 生成表格校验

parent 03acb249
...@@ -2,16 +2,16 @@ const isProduction = process.env.NODE_ENV === 'production'; ...@@ -2,16 +2,16 @@ const isProduction = process.env.NODE_ENV === 'production';
const isPre = process.env.PRE_ENV === 'pre'; const isPre = process.env.PRE_ENV === 'pre';
const envAPi = { const envAPi = {
api: '//backstms-yxm.liangkebang.net', api: 'https://backstms-xyqb.liangkebang.net',
kdspOpApi: 'https://kdsp-operation-yxm.liangkebang.net', kdspOpApi: 'https://kdsp-operation-xyqb.liangkebang.net',
kdspApi: 'https://sc-op-api-yxm.liangkebang.net', kdspApi: 'https://sc-op-api-xyqb.liangkebang.net',
goodsApi: 'https://sc-op-api-yxm.liangkebang.net', goodsApi: 'https://sc-op-api-xyqb.liangkebang.net',
querysApi: 'https://sc-settlement-api-yxm.liangkebang.net', querysApi: 'https://sc-settlement-api-xyqb.liangkebang.net',
// goodsApi: '//192.168.188.111:7000', // goodsApi: '//192.168.188.111:7000',
prologueDomain: 'https://mall-yxm.liangkebang.net', prologueDomain: 'https://mall-xyqb.liangkebang.net',
// qiniuHost: 'https://appsync.lkbang.net', // qiniuHost: 'https://appsync.lkbang.net',
qiniuHost: 'https://kdspstatic.q-gp.com/', qiniuHost: 'https://kdspstatic.q-gp.com/',
opapiHost: 'https://opapi-yxm.liangkebang.net', opapiHost: 'https://opapi-xyqb.liangkebang.net',
}; };
const prodApi = { const prodApi = {
......
...@@ -5,16 +5,38 @@ import React, { useContext, useEffect, useRef, useState } from 'react'; ...@@ -5,16 +5,38 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
const EditableContext = React.createContext<FormInstance<any> | null>(null); const EditableContext = React.createContext<FormInstance<any> | null>(null);
interface PropType {
initData: any[];
};
interface Item { interface Item {
key: string; key: string;
name: string; name: string;
age: string; age: string;
address: string; address: string;
} }
interface EditableCellProps {
rowIndex: number;
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: keyof Item;
record: Item;
handleSave: (record: Item) => void;
}
interface EditableRowProps { interface EditableRowProps {
index: number; 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>;
const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => { const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
// console.log('==========> index', props); // console.log('==========> index', props);
...@@ -29,15 +51,6 @@ const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => { ...@@ -29,15 +51,6 @@ const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
); );
}; };
interface EditableCellProps {
rowIndex: number;
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: keyof Item;
record: Item;
handleSave: (record: Item) => void;
}
const EditableCell: React.FC<EditableCellProps> = (props) => { const EditableCell: React.FC<EditableCellProps> = (props) => {
const { const {
...@@ -50,73 +63,61 @@ const EditableCell: React.FC<EditableCellProps> = (props) => { ...@@ -50,73 +63,61 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
handleSave, handleSave,
...restProps ...restProps
} = props; } = props;
// console.log(props);
const form = useContext(EditableContext)!; const form = useContext(EditableContext)!;
const save = async () => { const save = async () => {
try { try {
console.log(rowIndex); const tableList = form.getFieldValue('tableList');
const { tableList } = await form.validateFields();
handleSave(tableList); handleSave(tableList);
} catch (errInfo) { } catch (errInfo) {
console.log('Save failed:', errInfo); console.log('Save failed:', errInfo);
} }
}; };
const childNode = <Form.Item let childNode = children;
style={{ margin: 0 }}
name={['tableList', rowIndex, dataIndex]} if (editable) {
initialValue={record[dataIndex]} childNode = <Form.Item
rules={[ { required: true, message: `${title} is required.` }]}> style={{ margin: 0 }}
<InputNumber onBlur={save} /> name={['tableList', rowIndex, dataIndex]}
</Form.Item> // initialValue={record[dataIndex]}
rules={[{ required: true, message: `${title} is required.` }]}>
<InputNumber onBlur={save} />
</Form.Item>
}
return <td {...restProps}>{childNode}</td>; return <td {...restProps}>{childNode}</td>;
}; };
type EditableTableProps = Parameters<typeof Table>[0];
interface DataType {
supplyPrice: number;
commissionRate: number;
marketPrice: number;
salePrice: number;
stock: number;
productStockWarning: number;
}
type ColumnTypes = Exclude<EditableTableProps['columns'], undefined>;
const EditFormTable: React.FC = () => {
const [dataSource, setDataSource] = useState<DataType[]>([ const EditFormTable = (props: PropType) => {
{
supplyPrice: 100, const { initData } = props;
commissionRate: 20, // console.log(initData);
marketPrice: 32, const [dataSource, setDataSource] = useState<DataType[]>([]);
salePrice: 100,
stock: 100,
productStockWarning: 100,
},
{
supplyPrice: 100,
commissionRate: 20,
marketPrice: 32,
salePrice: 100,
stock: 100,
productStockWarning: 100,
}
]);
// const form = useContext(EditableContext)!;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [count, setCount] = useState(2); useEffect(() => {
console.log('==============>坚听initData', initData);
form.setFieldsValue({
tableList: initData,
});
setDataSource(initData);
}, [initData])
const handleDelete = (key: React.Key) => {
const newData = dataSource.filter(item => item.key !== key);
setDataSource(newData);
};
const defaultColumns: (ColumnTypes[number] & { editable?: boolean; dataIndex: string })[] = [ const defaultColumns: (ColumnTypes[number] & { editable?: boolean; dataIndex: string })[] = [
{
title: '一级规格',
dataIndex: 'firstSpecValue',
},
{
title: '二级规格',
dataIndex: 'secondSpecValue',
},
{ {
title: '供货价', title: '供货价',
dataIndex: 'supplyPrice', dataIndex: 'supplyPrice',
...@@ -149,23 +150,17 @@ const EditFormTable: React.FC = () => { ...@@ -149,23 +150,17 @@ const EditFormTable: React.FC = () => {
}, },
]; ];
const handleAdd = () => { const handleAdd = async () => {
console.log(form.getFieldsValue()); try {
// const newData: DataType = { const { tableList } = await form.validateFields();
// key: count, console.log(tableList);
// supplyPrice: 200, } catch (errInfo) {
// commissionRate: 20, console.log('Save failed:', errInfo);
// marketPrice: 32, }
// salePrice: 100,
// stock: 100,
// productStockWarning: 100,
// };
// setDataSource([...dataSource, newData]);
// setCount(count + 1);
}; };
const handleSave = (row: DataType[]) => { const handleSave = (row: DataType[]) => {
console.log('============>row', row); // console.log('============>row', row);
// const newData = [...dataSource]; // const newData = [...dataSource];
// const index = newData.findIndex(item => row.key === item.key); // const index = newData.findIndex(item => row.key === item.key);
// const item = newData[index]; // const item = newData[index];
...@@ -175,28 +170,32 @@ const EditFormTable: React.FC = () => { ...@@ -175,28 +170,32 @@ const EditFormTable: React.FC = () => {
// }); // });
setDataSource([...row]); setDataSource([...row]);
}; };
const components = {
body: {
row: EditableRow,
cell: EditableCell,
},
};
// 根据这里做判断渲染表格 // 根据这里做判断渲染表格
const columns = defaultColumns.map((col, colIndex) => { const columns = defaultColumns.map((col, colIndex) => {
if (!col.editable) { // if (!col.editable) {
return col; // return col;
} // }
return { return {
...col, ...col,
onCell: (record: DataType, rowIndex: number) => ({ onCell: (record: DataType, rowIndex: number) => {
record, let rowSpan = null;
rowIndex, if (col.dataIndex === 'firstSpecValue') {
editable: col.editable, // console.log(record, rowSpan);
dataIndex: col.dataIndex, rowSpan = record.rowSpanCount ? record.rowSpanCount : 0;
title: col.title, }
handleSave,
}), return ({
rowSpan,
record,
rowIndex,
editable: col.editable,
dataIndex: col.dataIndex,
title: col.title,
handleSave,
});
}
}; };
}); });
...@@ -205,12 +204,17 @@ const EditFormTable: React.FC = () => { ...@@ -205,12 +204,17 @@ const EditFormTable: React.FC = () => {
<Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}> <Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>
Add a row Add a row
</Button> </Button>
<Form form={form} component={false}> <Form form={form} scrollToFirstError component={false}>
<EditableContext.Provider value={form}> <EditableContext.Provider value={form}>
<Table <Table
pagination={false} pagination={false}
size="small" size="small"
components={components} components={{
body: {
row: EditableRow,
cell: EditableCell,
},
}}
bordered bordered
dataSource={dataSource} dataSource={dataSource}
rowKey={(row, rowInd) => rowInd} rowKey={(row, rowInd) => rowInd}
......
import { ConsoleSqlOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { ConsoleSqlOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, Select, Space, Modal } from 'antd'; import { Button, Form, Input, Select, Space, Modal, notification } from 'antd';
import React, { useState, forwardRef, useImperativeHandle, useEffect } from 'react'; import React, { useState, forwardRef, useImperativeHandle, useEffect } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { formItemLayout } from '../config'; import { formItemLayout } from '../config';
import EditFormTable from './EditFormTable'; import EditFormTable from './EditFormTable';
import { createProductData } from '../utils';
import { ServiceContext } from '../context';
const { Option } = Select; const { Option } = Select;
interface SpecItem { interface SpecItem {
specId: number; specId: number;
specName: string; specName: string;
...@@ -17,10 +18,28 @@ interface PropsType { ...@@ -17,10 +18,28 @@ interface PropsType {
specList: Array<SpecItem>; specList: Array<SpecItem>;
} }
const SpecificationTemplate = (props, _) => { const validatorSpecValue = (value, list, index, specName) => {
const { specList, label, name, selectName, specName, form } = props; const checkList = list.filter((item, ind) => {
if (ind === index) {
return false;
}
return item[specName] === value;
});
return checkList.length;
};
const isRepeatProduct = (list, message) => {
const isRepeat = [...new Set(list)].length !== list.length;
if (isRepeat) {
notification.warning({ message });
}
return isRepeat;
};
const SpecificationTemplate = (props, _) => {
const { specList, label, name, selectName, specName, form, specDataList } = props;
console.log('==============>specDataList', specDataList);
const handleChange = (val, option) => { const handleChange = (val, option) => {
const optionSpecName = option ? option.specName : null; const optionSpecName = option ? option.specName : null;
form.setFieldsValue({ [selectName]: optionSpecName }); form.setFieldsValue({ [selectName]: optionSpecName });
...@@ -37,64 +56,139 @@ const SpecificationTemplate = (props, _) => { ...@@ -37,64 +56,139 @@ const SpecificationTemplate = (props, _) => {
} }
console.log(specId); console.log(specId);
addCallback(); addCallback();
} };
return <> return (
<Form.Item name={name} label={label}> <>
<Select <Form.Item name={name} label={label}>
allowClear <Select
options={specList} allowClear
style={{ width: 200 }} options={specList}
fieldNames={{ label: 'specName', value: 'specId' }} style={{ width: 200 }}
placeholder={`请选择${label}`} fieldNames={{ label: 'specName', value: 'specId' }}
showSearch placeholder={`请选择${label}`}
filterOption={(input, option) => option.specName.toLowerCase().indexOf(input.toLowerCase()) >= 0} showSearch
onChange={handleChange} filterOption={(input, option) =>
/> option.specName.toLowerCase().indexOf(input.toLowerCase()) >= 0
</Form.Item> }
<Form.Item name={selectName} hidden></Form.Item> onChange={handleChange}
<Form.List name={specName}> />
{(fields, { add, remove }) => ( </Form.Item>
<> <Form.Item name={selectName} hidden></Form.Item>
{fields.map((field, index) => ( <Form.List name={specName}>
<Form.Item key={field.key} noStyle shouldUpdate={(prevValues, curValues) => false}> {(fields, { add, remove }) => (
{() => ( <>
<Space key={field.key} align="baseline"> {/* {fields.map((field, index) => (
<Form.Item style={{ marginLeft: 10 }} name={[field.name, specName]} <Space key={field.key} align="baseline">
rules={[{ required: true, message: '请输入规格名称' }]} <Form.Item style={{ marginLeft: 10 }} name={[index]}
> rules={[{ required: true, message: '请输入规格名称' }]}
<Input placeholder="请输入规格名称" /> >
</Form.Item> <Input placeholder="请输入规格名称" />
<MinusCircleOutlined onClick={() => remove(field.name)} /> </Form.Item>
</Space> <MinusCircleOutlined onClick={() => remove(field.name)} />
)} </Space>
</Form.Item> ))} */}
))} {fields.map((field, index) => (
{fields.length < 3 && <Form.Item noStyle> <Form.Item key={field.key} noStyle shouldUpdate={(prevValues, curValues) => false}>
<Button style={{ marginLeft: 10, marginBottom: 24 }} type="dashed" onClick={() => bundlePlusAddSpecEvent(add)} icon={<PlusOutlined />} /> {() => (
</Form.Item>} <Space key={field.key} align="baseline">
</> <Form.Item
)} style={{ marginLeft: 10 }}
</Form.List> name={[field.name, specName]}
</> rules={[
} { required: true, message: '请输入规格名称' },
{
message: '规格名不能重复!',
validator(rule, value, callback) {
const checkList = form.getFieldValue(specName);
const check = validatorSpecValue(value, checkList, index, specName);
return check ? callback('规格名不能重复!') : callback();
},
},
]}
>
<Input
disabled={specDataList[index] && specDataList[index].id}
placeholder="请输入规格名称"
/>
</Form.Item>
{!(specDataList[index] && specDataList[index].id) && (
<MinusCircleOutlined onClick={() => remove(field.name)} />
)}
</Space>
)}
</Form.Item>
))}
{fields.length < 3 && (
<Form.Item noStyle>
<Button
style={{ marginLeft: 10, marginBottom: 24 }}
type="dashed"
onClick={() => bundlePlusAddSpecEvent(add)}
icon={<PlusOutlined />}
/>
</Form.Item>
)}
</>
)}
</Form.List>
</>
);
};
const filterSpecData = skuList => skuList.reduce((originObj, item) => { const originItems = {
if (item.firstSpecValue) {
originObj.firstSpecValue.push({ firstSpecValue: item.firstSpecValue });
}
if (item.secondSpecValue) {
originObj.secondSpecValue.push({ secondSpecValue: item.secondSpecValue });
}
return originObj;
}, {
firstSpecValue: [], firstSpecValue: [],
secondSpecValue: [], secondSpecValue: [],
}); dataSource: [],
firstDuplicate: [],
secondDuplicate: [],
};
const filterItem = skuItem => {
const { imageList, serviceItem, ...argsItem } = skuItem;
argsItem.disabled = true;
return argsItem;
};
const filterSpecData = skuList =>
skuList.reduce((orgin, skuItem) => {
// console.log(item);
const item = filterItem(skuItem);
const { firstSpecValue, secondSpecValue } = item;
if (firstSpecValue && !orgin.firstDuplicate.includes(firstSpecValue)) {
orgin.firstSpecValue.push(item);
orgin.firstDuplicate.push(firstSpecValue);
}
if (secondSpecValue && !orgin.secondDuplicate.includes(secondSpecValue)) {
orgin.secondSpecValue.push(item);
orgin.secondDuplicate.push(secondSpecValue);
}
// orgin.dataSource.push({
// id: item.id,
// firstSpec: item.firstSpec,
// firstSpecId: item.firstSpecId,
// firstSpecValue: item.firstSpecValue,
// secondSpec: item.secondSpec,
// secondSpecId: item.secondSpecId,
// secondSpecValue: item.secondSpecValue,
// commissionRate: item.commissionRate,
// supplyPrice: item.supplyPrice, // 供货价
// marketPrice: item.marketPrice,
// salePrice: item.salePrice,
// stock: item.stock,
// productStockWarning: item.productStockWarning,
// });
return orgin;
}, originItems);
const createTableData = () => {};
const FormPriceOrStock = forwardRef((props: PropsType, ref) => { const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
const { specList, editData } = props; const { specList, editData } = props;
console.log('============>000000000000', props);
const [form] = Form.useForm(); const [form] = Form.useForm();
const [specInitValue, setSpecInitValue] = useState({ const [specInitValue, setSpecInitValue] = useState({
firstSpec: '', firstSpec: '',
...@@ -105,8 +199,42 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => { ...@@ -105,8 +199,42 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
secondSpecValue: [], secondSpecValue: [],
}); });
const [tableData, setTableData] = useState([]);
const onFinish = (values: any) => { const onFinish = (values: any) => {
console.log('Received values of form:', values); console.log(values);
// const values = form.getFieldsValue();
// const { firstValues = [], secondValues = [], firstSpecId, secondSpecId } = values;
// if ([fisrtIsRepeat, secondIsRepeat].includes(true)) {
// setTableData([]);
// return;
// }
const cleanValues = {
firstValues: values.firstSpecValue,
secondValues: values.secondSpecValue,
firstSpecId: values.firstSpecId,
secondSpecId: values.secondSpecId,
};
const newData = createProductData(cleanValues);
// console.log('=============>生成商品数据', newData);
setTableData(newData);
// // const columnsData = createProductColumns(cleanValues, newData);
// form.resetFields('tableArray', []);
// setColumns(columnsData);
// setProductData(newData);
// console.log(newData);
// console.log(columnsData);
if (!values.firstSpecId && !values.firstSpecId) {
// 如果两个都没有选择默认生成一条数据
// Modal.warning({
// maskClosable: true,
// title: '请先选择规格分类!',
// });
}
}; };
const onCheck = async () => { const onCheck = async () => {
...@@ -128,7 +256,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => { ...@@ -128,7 +256,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
const { skuList } = editData; const { skuList } = editData;
const [oneItem] = skuList; const [oneItem] = skuList;
// 根据接口过滤数据 // 根据接口过滤数据
const { firstSpecValue, secondSpecValue } = filterSpecData(skuList); const { firstSpecValue, secondSpecValue, dataSource } = filterSpecData(skuList);
const specData = { const specData = {
firstSpec: oneItem.firstSpec, firstSpec: oneItem.firstSpec,
firstSpecId: oneItem.firstSpecId, firstSpecId: oneItem.firstSpecId,
...@@ -137,13 +265,15 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => { ...@@ -137,13 +265,15 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
secondSpecId: oneItem.secondSpecId, secondSpecId: oneItem.secondSpecId,
secondSpecValue, secondSpecValue,
}; };
form.setFieldsValue(specData); form.setFieldsValue(specData); // 设置规格数据
setSpecInitValue(specData); setSpecInitValue(specData); // 缓存规格数据
setTableData([...dataSource]);
} }
}, [id, editData]); }, [id, editData]);
return ( return (
// {...formItemLayout} // {...formItemLayout}
<Form <Form
form={form} form={form}
name="dynamic_form_nest_item" name="dynamic_form_nest_item"
...@@ -158,6 +288,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => { ...@@ -158,6 +288,7 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
selectName="firstSpec" selectName="firstSpec"
specName="firstSpecValue" specName="firstSpecValue"
specList={specList} specList={specList}
specDataList={specInitValue.firstSpecValue}
/> />
<SpecificationTemplate <SpecificationTemplate
form={form} form={form}
...@@ -166,16 +297,16 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => { ...@@ -166,16 +297,16 @@ const FormPriceOrStock = forwardRef((props: PropsType, ref) => {
selectName="secondSpec" selectName="secondSpec"
specName="secondSpecValue" specName="secondSpecValue"
specList={specList} specList={specList}
specDataList={specInitValue.secondSpecValue}
/> />
<Form.Item> <Form.Item>
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit">
Submit 生成商品信息
</Button> </Button>
</Form.Item> </Form.Item>
<EditFormTable /> <EditFormTable initData={tableData} />
</Form> </Form>
); );
}); });
......
...@@ -42,7 +42,6 @@ const FormRuleSetting = forwardRef((props: { editData: any }, ref) => { ...@@ -42,7 +42,6 @@ const FormRuleSetting = forwardRef((props: { editData: any }, ref) => {
const [commonImageList, setCommonImageList] = useState([]); const [commonImageList, setCommonImageList] = useState([]);
const [detailImageList, setDetailImageList] = useState([]); const [detailImageList, setDetailImageList] = useState([]);
useEffect(() => { useEffect(() => {
console.log(id);
if (+id !== 0) { if (+id !== 0) {
console.log(); console.log();
if (!Object.keys(editData).length) return; if (!Object.keys(editData).length) return;
......
import React from 'react';
export const ServiceContext = React.createContext(null);
...@@ -12,7 +12,13 @@ import FormPriceOrStock from './components/FormPriceOrStock'; ...@@ -12,7 +12,13 @@ import FormPriceOrStock from './components/FormPriceOrStock';
import FormRuleSetting from './components/FormRuleSetting'; import FormRuleSetting from './components/FormRuleSetting';
import FormSettlementOthers from './components/FormSettlementOthers'; import FormSettlementOthers from './components/FormSettlementOthers';
import commonStyle from './common.less'; import commonStyle from './common.less';
import { getProductDetail, merchantCategoryGetAll, merchantBrandList, merchantSpecList } from './service'; import {
getProductDetail,
merchantCategoryGetAll,
merchantBrandList,
merchantSpecList,
} from './service';
import { ServiceContext } from './context';
/** /**
* 服务商品改造-商品模块 * 服务商品改造-商品模块
...@@ -28,9 +34,9 @@ const ServiceGoods = options => { ...@@ -28,9 +34,9 @@ const ServiceGoods = options => {
const settingRef = useRef(null); const settingRef = useRef(null);
const settleOtrRef = useRef(null); const settleOtrRef = useRef(null);
const [isEdit, setIsEdit] = useState(false);
const [productType, setProductType] = useState(1); const [productType, setProductType] = useState(1);
const [pageLoading, setPageLoading] = useState(false); const [pageLoading, setPageLoading] = useState(false);
const [categoryList, setCategoryList] = useState([]); // 获取三级类目 const [categoryList, setCategoryList] = useState([]); // 获取三级类目
const [brandList, setBrandList] = useState([]); // 获取商品牌 const [brandList, setBrandList] = useState([]); // 获取商品牌
const [specList, setSpecList] = useState([]); // 规格列表 const [specList, setSpecList] = useState([]); // 规格列表
...@@ -91,10 +97,11 @@ const ServiceGoods = options => { ...@@ -91,10 +97,11 @@ const ServiceGoods = options => {
useEffect(() => { useEffect(() => {
(async () => { (async () => {
setPageLoading(true); setPageLoading(true);
await getMerchantCategory(); // await getMerchantCategory();
await getMerchantBrandList(); // await getMerchantBrandList();
await getMerchantSpecList(); await getMerchantSpecList();
if (pageId !== 0) { if (pageId !== 0) {
setIsEdit(true);
await getProductDetailResponse(); await getProductDetailResponse();
} }
setPageLoading(false); setPageLoading(false);
...@@ -105,27 +112,29 @@ const ServiceGoods = options => { ...@@ -105,27 +112,29 @@ const ServiceGoods = options => {
<Spin tip="正在加载..." spinning={pageLoading} delay={100}> <Spin tip="正在加载..." spinning={pageLoading} delay={100}>
<PageHeaderWrapper className={commonStyle.header}> <PageHeaderWrapper className={commonStyle.header}>
<WrapperContainer> <WrapperContainer>
<Title title="商品类型" /> <ServiceContext.Provider value={{ pageId, isEdit }}>
<TaskTypeSelect productType={productType} onChange={productChange} /> <Title title="商品类型" />
<TaskTypeSelect productType={productType} onChange={productChange} />
<Title title="商品基本信息编辑" />
<FormInformationBasic <Title title="商品基本信息编辑" />
ref={basicRef} <FormInformationBasic
editData={editData} ref={basicRef}
categoryList={categoryList} editData={editData}
brandList={brandList} categoryList={categoryList}
/> brandList={brandList}
/>
<Title title="价格与库存" />
<FormPriceOrStock ref={stockRef} specList={specList} editData={editData} /> <Title title="价格与库存" />
<FormPriceOrStock ref={stockRef} specList={specList} editData={editData} />
<Title title="规则设置" />
<FormRuleSetting ref={settingRef} editData={editData} /> <Title title="规则设置" />
<FormRuleSetting ref={settingRef} editData={editData} />
<FormSettlementOthers ref={settleOtrRef} editData={editData} />
<Button type="primary" onClick={submitEvent}> <FormSettlementOthers ref={settleOtrRef} editData={editData} />
Register <Button type="primary" onClick={submitEvent}>
</Button> Register
</Button>
</ServiceContext.Provider>
</WrapperContainer> </WrapperContainer>
</PageHeaderWrapper> </PageHeaderWrapper>
</Spin> </Spin>
......
import { ConsoleSqlOutlined } from '@ant-design/icons';
export const cleanArray = actual => {
const newArray = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i]);
}
}
return newArray;
};
const createInitProduct = (skuItem, isCreate) => {
if (isCreate && Object.keys(skuItem).length > 5) {
return skuItem;
}
return {
// firstSpecValue: '',
// secondSpecValue: '',
weight: null,
productStockWarning: null,
marketPrice: null,
supplyPrice: null,
stock: null,
thirdSkuNo: null,
skuLink: null,
};
};
const initData = {
// firstSpecValue: '',
// secondSpecValue: '',
weight: null,
productStockWarning: null,
marketPrice: null,
supplyPrice: null,
stock: null,
thirdSkuNo: null,
skuLink: null,
};
const createSecondProduct = (secondSpecList, initItem, secondSpec, dataSource, callback) => {
secondSpecList.forEach(secondItem => {
console.log('============>', Object.keys(secondItem));
const specSecond =
Object.keys(secondItem).length < 2
? {
firstSpecId: initItem.firstSpecId,
firstSpecValue: initItem.firstSpecValue,
...initData,
}
: Object.assign({}, initItem); // 继承fist参数
if (callback) {
callback(specSecond);
}
specSecond.secondSpecId = secondSpec;
specSecond.secondSpecValue = secondItem.secondSpecValue;
dataSource.push(specSecond);
});
};
export const createProductData = ({ firstValues, secondValues, firstSpecId, secondSpecId }) => {
console.log(firstValues, secondValues);
const countRowSpan = {};
const dataSource = [];
if (firstValues.length) {
firstValues.forEach((fisrtItem, index) => {
const specFirst = createInitProduct(fisrtItem, true);
specFirst.firstSpecId = firstSpecId;
specFirst.firstSpecValue = fisrtItem.firstSpecValue;
if (secondValues.length) {
createSecondProduct(secondValues, specFirst, secondSpecId, dataSource, specSecond => {
if (!countRowSpan[specFirst.firstSpecValue]) {
countRowSpan[specFirst.firstSpecValue] = true;
specSecond.rowSpanCount = secondValues.length;
}
});
return;
}
dataSource.push(specFirst);
});
} else if (secondValues.length) {
// const childData = createInitProduct();
createSecondProduct(secondValues, initData, secondSpecId, dataSource);
} else {
const specFirst = createInitProduct();
dataSource.push(specFirst);
}
return dataSource;
};
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