Commit 6c9ab49e authored by 武广's avatar 武广

feat: 添加使用缓存功能

parent ede9b518
...@@ -62,33 +62,22 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -62,33 +62,22 @@ const EditFormTable = forwardRef((props, ref) => {
setDataSource([...initData]); setDataSource([...initData]);
}, [initData]); }, [initData]);
// const handleSave = row => {
// form.setFieldsValue({
// tableList: [...row],
// });
// const dataList = [...dataSource];
// dataList[rowIndex][dataIndex] = value;
// setDataSource([...dataList]);
// };
const handleSave = (value, dataIndex, rowIndex) => { const handleSave = (value, dataIndex, rowIndex) => {
// form.setFieldsValue({
// [`tableList[${rowIndex}][${dataIndex}]`]: value,
// });
const dataList = [...dataSource]; const dataList = [...dataSource];
dataList[rowIndex][dataIndex] = value; dataList[rowIndex][dataIndex] = value;
setDataSource([...dataList]); setDataSource([...dataList]);
}; };
const getValues = () =>
[...dataSource].map(item => {
const { rowSpanCount, option, ...childItem } = item;
return childItem;
});
const onCheck = async () => { const onCheck = async () => {
try { try {
await form.validateFields(); await form.validateFields();
const newTableList = [...dataSource].map(item => { return getValues();
const { rowSpanCount, option, ...childItem } = item;
return childItem;
});
console.log('===============>newTableList', newTableList);
return newTableList;
} catch (errorInfo) { } catch (errorInfo) {
console.log(errorInfo); console.log(errorInfo);
return null; return null;
...@@ -96,8 +85,7 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -96,8 +85,7 @@ const EditFormTable = forwardRef((props, ref) => {
}; };
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); props.onValuesChange();
props.onValuesChange({ skuList: values.tableList });
}, 400); }, 400);
const rowOnClickEvent = row => { const rowOnClickEvent = row => {
...@@ -136,6 +124,7 @@ const EditFormTable = forwardRef((props, ref) => { ...@@ -136,6 +124,7 @@ const EditFormTable = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
onCheck, onCheck,
form, form,
getValues,
})); }));
// 根据这里做判断渲染表格 // 根据这里做判断渲染表格
const columns = defaultColumns const columns = defaultColumns
......
...@@ -38,7 +38,10 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -38,7 +38,10 @@ const FormAttr = forwardRef((props, ref) => {
skuAttr.forEach(item => { skuAttr.forEach(item => {
if (item[key].length) { if (item[key].length) {
let values = +item.optionType.code === 1 ? '' : []; let values = [];
if ((item.optionType && +item.optionType.code === 1) || typeof item[key] === 'string') {
values = '';
}
obj[item.productAttributeId] = []; obj[item.productAttributeId] = [];
item[key].forEach(attr => { item[key].forEach(attr => {
const { attributeValueId, attributeValueName } = attr; const { attributeValueId, attributeValueName } = attr;
...@@ -53,7 +56,11 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -53,7 +56,11 @@ const FormAttr = forwardRef((props, ref) => {
obj[item.productAttributeId].push(json); obj[item.productAttributeId].push(json);
} }
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
+item.optionType.code === 1 ? (values = v) : values.push(v); if ((item.optionType && +item.optionType.code === 1) || typeof item[key] === 'string') {
values = v;
} else {
values.push(v);
}
} }
}); });
obj.initValue[item.productAttributeId] = values; obj.initValue[item.productAttributeId] = values;
...@@ -64,6 +71,8 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -64,6 +71,8 @@ const FormAttr = forwardRef((props, ref) => {
// 获取属性 // 获取属性
const getAttribute = async categoryId => { const getAttribute = async categoryId => {
console.log('categoryId :>> ', categoryId);
console.log('props.initData :>> ', props.initData);
const res = await apiGetAttribute(categoryId); const res = await apiGetAttribute(categoryId);
if (res && res.data && res.data.length) { if (res && res.data && res.data.length) {
let initValue = { let initValue = {
...@@ -131,7 +140,22 @@ const FormAttr = forwardRef((props, ref) => { ...@@ -131,7 +140,22 @@ const FormAttr = forwardRef((props, ref) => {
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
props.onValuesChange(values); const arr = Object.keys(values).map(item => {
const obj = {
productAttributeId: item,
};
if (typeof values[item] === 'string') {
obj.productAttributeApplyValueList = JSON.parse(values[item]);
} else {
obj.productAttributeApplyValueList = values[item].map(v => JSON.parse(v));
}
return obj;
});
props.onValuesChange({
productAttributeApplyList: {
productAttributeApplyList: arr,
},
});
}, 400); }, 400);
const onCheck = async () => { const onCheck = async () => {
......
...@@ -5,6 +5,8 @@ import styles from '../common.less'; ...@@ -5,6 +5,8 @@ import styles from '../common.less';
import { isIntegerNotZero, isCheckPriceOneDecimal } from '@/utils/validator'; import { isIntegerNotZero, isCheckPriceOneDecimal } from '@/utils/validator';
import UUID from '@/utils/uuid'; import UUID from '@/utils/uuid';
import { debounce } from '@/utils/utils'; import { debounce } from '@/utils/utils';
import localStorage from '@/utils/localStorage';
import { localAutoSaveKey } from '../utils';
const { Option } = Select; const { Option } = Select;
...@@ -159,11 +161,9 @@ const FormPackage = forwardRef((props, ref) => { ...@@ -159,11 +161,9 @@ const FormPackage = forwardRef((props, ref) => {
const { validateFields, getFieldsValue } = form; const { validateFields, getFieldsValue } = form;
const onCheck = async () => { const onCheck = async () => {
console.log('form :>> ', form);
try { try {
const values = await validateFields(); const values = await validateFields();
const arr = []; const arr = [];
console.log('package values :>> ', values);
if (values && values.lists) { if (values && values.lists) {
values.lists.forEach(item => { values.lists.forEach(item => {
arr.push({ arr.push({
...@@ -177,9 +177,11 @@ const FormPackage = forwardRef((props, ref) => { ...@@ -177,9 +177,11 @@ const FormPackage = forwardRef((props, ref) => {
} }
}; };
const getValues = () => form.getFieldsValue();
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); // const values = form.getFieldsValue();{ setMealContent: values }
props.onValuesChange(values); props.onValuesChange();
}, 400); }, 400);
// 创建分组 // 创建分组
...@@ -273,6 +275,7 @@ const FormPackage = forwardRef((props, ref) => { ...@@ -273,6 +275,7 @@ const FormPackage = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
onCheck, onCheck,
getValues,
})); }));
return ( return (
......
...@@ -334,6 +334,7 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -334,6 +334,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const { inIdList: secndInIdList, noIdList: secndNoIdList } = filterSkuNotIdList( const { inIdList: secndInIdList, noIdList: secndNoIdList } = filterSkuNotIdList(
cleanValues.secondValues, cleanValues.secondValues,
); );
console.log('skuList :>> ', skuList);
const createSkuList = createProductData( const createSkuList = createProductData(
{ {
firstSpecId: cleanValues.firstSpecId, firstSpecId: cleanValues.firstSpecId,
...@@ -371,8 +372,6 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -371,8 +372,6 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const onSpecificationEvent = async () => { const onSpecificationEvent = async () => {
try { try {
const values = await form.validateFields(); const values = await form.validateFields();
console.log('values :>> ', values);
console.log('cleanArray(values.secondSpecValue) :>> ', cleanArray(values.secondSpecValue));
const cleanValues = { const cleanValues = {
firstSpec: values.firstSpec, firstSpec: values.firstSpec,
firstSpecId: values.firstSpecId, firstSpecId: values.firstSpecId,
...@@ -395,6 +394,19 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -395,6 +394,19 @@ const FormPriceOrStock = forwardRef((props, ref) => {
props.onValuesChange({ infoSpecData: cleanValues }); props.onValuesChange({ infoSpecData: cleanValues });
}, 400); }, 400);
const packageValueChange = () => {
const efvalues = editRef.current.getValues();
if (customer.isCard) {
const packageV = packageRef.current.getValues();
efvalues.forEach((item, i) => {
item.serviceItem = {
setMealContent: packageV.lists[i].children,
};
});
}
props.onValuesChange({ skuList: efvalues });
};
const firstOnChangeEvent = async () => { const firstOnChangeEvent = async () => {
const cleanValues = await onSpecificationEvent(); const cleanValues = await onSpecificationEvent();
if (cleanValues) { if (cleanValues) {
...@@ -430,7 +442,6 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -430,7 +442,6 @@ const FormPriceOrStock = forwardRef((props, ref) => {
setSpecInitValue(editData); // 缓存规格数据 setSpecInitValue(editData); // 缓存规格数据
CreateColumnsEvent(editData); CreateColumnsEvent(editData);
setMergeTable(Boolean(editData.secondSpecValue.length)); setMergeTable(Boolean(editData.secondSpecValue.length));
console.log('skuList :>> ', skuList);
setTableData(fliterSkuListSortData(skuList)); setTableData(fliterSkuListSortData(skuList));
// } // }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
...@@ -482,7 +493,7 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -482,7 +493,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
setTableData={setTableData} setTableData={setTableData}
defaultColumns={defaultColumns} defaultColumns={defaultColumns}
initData={tableData} initData={tableData}
onValuesChange={props.onValuesChange} onValuesChange={packageValueChange}
/> />
{customer.isCard && ( {customer.isCard && (
<> <>
...@@ -491,7 +502,7 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -491,7 +502,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
ref={packageRef} ref={packageRef}
initData={tableData} initData={tableData}
key="tc" key="tc"
onValuesChange={props.onValuesChange} onValuesChange={packageValueChange}
/> />
</> </>
)} )}
......
...@@ -34,15 +34,15 @@ const FormRuleSetting = forwardRef((props, ref) => { ...@@ -34,15 +34,15 @@ const FormRuleSetting = forwardRef((props, ref) => {
}; };
useEffect(() => { useEffect(() => {
if (customer.isEdit) { // if (customer.isEdit) {
if (!editData) return; if (!editData) return;
const goodInfo = Object.assign({}, editData); const goodInfo = Object.assign({}, editData);
if (goodInfo.shopIds) { if (goodInfo.shopIds) {
const shopIds = getIsInShops(editData.shopIds); const shopIds = getIsInShops(editData.shopIds);
goodInfo.shopIds = shopIds; goodInfo.shopIds = shopIds;
}
form.setFieldsValue(goodInfo);
} }
form.setFieldsValue(goodInfo);
// }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
const onCheck = async () => { const onCheck = async () => {
......
...@@ -22,27 +22,27 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -22,27 +22,27 @@ const FormRuleVPictures = forwardRef((props, ref) => {
const [{ imgConfig }] = typeConfig.filter(item => item.type === customer.productType); const [{ imgConfig }] = typeConfig.filter(item => item.type === customer.productType);
useEffect(() => { useEffect(() => {
if (customer.isEdit) { // if (customer.isEdit) {
if (editData) { if (editData) {
setImageList(editData.imageList); setImageList(editData.imageList || {});
setCardImageList(editData.cardImageList); setCardImageList(editData.cardImageList || []);
setCommonImageList(editData.commonImageList); // 编辑状态下设置公共图 setCommonImageList(editData.commonImageList || []); // 编辑状态下设置公共图
setDetailImageList(editData.detailImageList); // 编辑状态下设置详情图 setDetailImageList(editData.detailImageList || []); // 编辑状态下设置详情图
const editParams = { const editParams = {
commonImageList: editData.commonImageList, commonImageList: editData.commonImageList,
detailImageList: editData.detailImageList, detailImageList: editData.detailImageList,
}; };
if (customer.isCard) { if (customer.isCard) {
editParams.cardImageList = editData.cardImageList; editParams.cardImageList = editData.cardImageList;
} else { } else {
editParams.imageList = editData.imageList; editParams.imageList = editData.imageList;
}
const timer = setTimeout(() => {
form.setFieldsValue(editParams);
clearTimeout(timer);
});
} }
const timer = setTimeout(() => {
form.setFieldsValue(editParams);
clearTimeout(timer);
});
} }
// }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
useEffect(() => { useEffect(() => {
...@@ -71,6 +71,7 @@ const FormRuleVPictures = forwardRef((props, ref) => { ...@@ -71,6 +71,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
const getFormValues = debounce(() => { const getFormValues = debounce(() => {
const values = form.getFieldsValue(); const values = form.getFieldsValue();
props.onValuesChange({ infoImageData: values }); props.onValuesChange({ infoImageData: values });
// props.onValuesChange(values);
}, 400); }, 400);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
......
...@@ -42,11 +42,11 @@ const FormSettlementOthers = forwardRef((props, ref) => { ...@@ -42,11 +42,11 @@ const FormSettlementOthers = forwardRef((props, ref) => {
}, 400); }, 400);
useEffect(() => { useEffect(() => {
if (customer.isEdit) { // if (customer.isEdit) {
if (!editData) return; if (!editData) return;
form.setFieldsValue(editData); form.setFieldsValue(editData);
setInitValue({ ...editData }); setInitValue({ ...editData });
} // }
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
......
import React, { useState, useRef, useEffect, useCallback } from 'react'; import React, { useState, useRef, useEffect, useCallback } from 'react';
import { Spin, Button, Modal, message, notification } from 'antd'; import { Spin, Button, Modal, message, notification } from 'antd';
import moment from 'moment';
import { Title, WrapperContainer } from './components/CommonTemplate'; import { Title, WrapperContainer } from './components/CommonTemplate';
import { TaskTypeSelect } from './components/TaskTypeSelect'; import { TaskTypeSelect } from './components/TaskTypeSelect';
import FormInformationBasic from './components/FormInformationBasic'; import FormInformationBasic from './components/FormInformationBasic';
...@@ -287,9 +288,21 @@ const ServiceGoods = options => { ...@@ -287,9 +288,21 @@ const ServiceGoods = options => {
const info = localStorage.get(localAutoSaveKey); const info = localStorage.get(localAutoSaveKey);
if (info) { if (info) {
console.log('info :>> ', info); console.log('info :>> ', info);
if (info.serviceItem) {
const ptime = info.serviceItem.purchaseTime;
const utime = info.serviceItem.useTime;
if (ptime && ptime.length === 2) {
ptime[0] = moment(ptime[0]);
ptime[1] = moment(ptime[1]);
}
if (utime && utime.length === 2) {
utime[0] = moment(utime[0]);
utime[1] = moment(utime[1]);
}
}
setProductType(info.type); setProductType(info.type);
setEditData(info); setEditData(info);
if (info.infoMation.categoryId && info.infoMation.categoryId.length) { if (info.infoMation && info.infoMation.categoryId && info.infoMation.categoryId.length) {
setCategoryIds(info.infoMation.categoryId); setCategoryIds(info.infoMation.categoryId);
} }
} }
...@@ -307,6 +320,7 @@ const ServiceGoods = options => { ...@@ -307,6 +320,7 @@ const ServiceGoods = options => {
// 当商品进行编辑 & 类型不为电子卡券 & 商品状态不为驳回 禁用当前功能 // 当商品进行编辑 & 类型不为电子卡券 & 商品状态不为驳回 禁用当前功能
isDisabled: isEdit && productType !== 4 && SourceData.state && SourceData.state !== 4, isDisabled: isEdit && productType !== 4 && SourceData.state && SourceData.state !== 4,
isJDGoods: isEdit && SourceData.pageProductType && +SourceData.pageProductType !== 1, isJDGoods: isEdit && SourceData.pageProductType && +SourceData.pageProductType !== 1,
// isUseCache: false, // 是否使用缓存数据
onEventBus, onEventBus,
}; };
......
...@@ -250,7 +250,7 @@ export const createProductData = (props, isEdit, skuList) => { ...@@ -250,7 +250,7 @@ export const createProductData = (props, isEdit, skuList) => {
const newSecondList = secndInIdList.concat(secndNoIdList || []); const newSecondList = secndInIdList.concat(secndNoIdList || []);
list = createSkuListData(newFirstList, newSecondList, firstSpecId, secondSpecId, skuList); list = createSkuListData(newFirstList, newSecondList, firstSpecId, secondSpecId, skuList);
} else { } else {
list = createSkuListData(fisrtNoIdList, secndNoIdList, firstSpecId, secondSpecId); list = createSkuListData(fisrtNoIdList, secndNoIdList, firstSpecId, secondSpecId, skuList);
} }
return list; return list;
}; };
......
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