Commit 12399379 authored by 武广's avatar 武广

fix: 修改自动保存方法

parent d921a692
import { Input, Modal, Button, Form, Table, InputNumber } from 'antd';
import { Input, Modal, Button, Form, Table } from 'antd';
import React, {
useContext,
createContext,
......@@ -9,7 +9,7 @@ import React, {
} from 'react';
import { ServiceContext } from '../context';
import { CreateFormInput } from './CommonTemplate';
import UUID from '../../../utils/uuid';
import { debounce } from '@/utils/utils';
const UpdateSkuName = ({ skuVisble, value, confirmEvent, cancelEvent }) => {
const [skuForm] = Form.useForm();
......@@ -95,6 +95,11 @@ const EditFormTable = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
const rowOnClickEvent = row => {
setSkuVisble(true);
setSkuNameItem({
......@@ -171,7 +176,7 @@ const EditFormTable = forwardRef((props, ref) => {
return (
<>
<Form form={form} scrollToFirstError component={false} onValuesChange={props.onValuesChange}>
<Form form={form} scrollToFirstError component={false} onValuesChange={getFormValues}>
<EditableContext.Provider value={form}>
<Table
scroll={{ y: 300, x: 1000 }}
......
......@@ -6,6 +6,7 @@ import { UpOutlined, DownOutlined } from '@ant-design/icons';
import styles from '../common.less';
import { apiGetAttribute } from '../service';
import CustomSelect from '@/components/CustomSelect';
import { debounce } from '@/utils/utils';
const FormAttr = forwardRef((props, ref) => {
const [form] = Form.useForm();
......@@ -125,6 +126,11 @@ const FormAttr = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
const onCheck = async () => {
try {
const values = await form.validateFields();
......@@ -175,7 +181,7 @@ const FormAttr = forwardRef((props, ref) => {
<>
<div className={styles.attrbox + (isMore ? styles.attrboxMore : '')}>
{categoryAttrs.length > 0 && (
<Form form={form} initialValues={initAttrData} onValuesChange={props.onValuesChange}>
<Form form={form} initialValues={initAttrData} onValuesChange={getFormValues}>
<Row>
{categoryAttrs.map(k => (
<Col span={12} key={k.id}>
......
......@@ -2,6 +2,7 @@ import React, { useState, useContext, useEffect, forwardRef, useImperativeHandle
import { Cascader, Form, Input, Select, Popover, Button, Checkbox } from 'antd';
import { formItemLayout } from '../config';
import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils';
const CreateSelectOption = optionList =>
optionList.map(brandItem => (
......@@ -53,6 +54,11 @@ const FormInformationBasic = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
useImperativeHandle(ref, () => ({
onCheck,
reset: form.resetFields,
......@@ -82,7 +88,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
description: '',
}}
scrollToFirstError
onValuesChange={props.onValuesChange}
onValuesChange={getFormValues}
>
<Form.Item
name="categoryId"
......
......@@ -4,6 +4,7 @@ import { PlusOutlined } from '@ant-design/icons';
import styles from '../common.less';
import { isIntegerNotZero, isCheckPriceOneDecimal } from '@/utils/validator';
import UUID from '@/utils/uuid';
import { debounce } from '@/utils/utils';
const { Option } = Select;
......@@ -176,6 +177,11 @@ const FormPackage = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
// 创建分组
const onCreateGroup = () => {
const str = groupName && groupName.trim();
......@@ -230,6 +236,7 @@ const FormPackage = forwardRef((props, ref) => {
}
setList(arr);
form.setFieldsValue(arrList);
getFormValues();
};
useEffect(() => {
......@@ -270,7 +277,7 @@ const FormPackage = forwardRef((props, ref) => {
return (
<div className={styles.formPackageBox}>
<Form style={{ marginBottom: 10 }} form={form} onValuesChange={props.onValuesChange}>
<Form style={{ marginBottom: 10 }} form={form} onValuesChange={getFormValues}>
<Form.List name="lists">
{(fields, { add, remove }) => (
<>
......
......@@ -19,6 +19,7 @@ import {
fliterSkuListSortData,
filterSkuNotIdList,
} from '../utils';
import { debounce } from '@/utils/utils';
import { ServiceContext } from '../context';
import { SelectTemplate, Title } from './CommonTemplate';
......@@ -255,6 +256,11 @@ const FormPriceOrStock = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
const CreateColumnsEvent = specData => {
const columsData = [];
if (specData.firstSpec && specData.firstSpecValue.length) {
......@@ -389,7 +395,7 @@ const FormPriceOrStock = forwardRef((props, ref) => {
form={form}
autoComplete="off"
initialValues={initSpecReced()}
onValuesChange={props.onValuesChange}
onValuesChange={getFormValues}
>
<SpecificationTemplate
form={form}
......
......@@ -3,7 +3,7 @@ import React, { useEffect, forwardRef, useImperativeHandle, useContext } from 'r
import moment from 'moment';
import { WeeksList, formItemLayout } from '../config';
import { ServiceContext } from '../context';
import { formatTime } from '../../../utils/utils';
import { debounce, formatTime } from '@/utils/utils';
const { Option } = Select;
const { RangePicker } = DatePicker;
......@@ -62,6 +62,11 @@ const FormRuleSetting = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
const nowDateTime = moment(moment().format('YYYY-MM-DD 00:00:00'));
const nowDateTimeEnd = moment(moment().format('YYYY-MM-DD 23:59:59'));
......@@ -89,7 +94,7 @@ const FormRuleSetting = forwardRef((props, ref) => {
tips: '', // 温馨提示
}}
scrollToFirstError
onValuesChange={props.onValuesChange}
onValuesChange={getFormValues}
>
<Form.Item name="purchaseTime" label="购买时间" {...rangeConfig}>
<RangePicker
......
......@@ -4,6 +4,7 @@ import { ServiceContext } from '../context';
import { TaskList, formItemLayout } from '../config';
import UploadImage from './UploadImage';
import commonStyle from '../common.less';
import { debounce } from '@/utils/utils';
const FormRuleVPictures = forwardRef((props, ref) => {
const { editData, specKeyItem } = props;
......@@ -65,6 +66,11 @@ const FormRuleVPictures = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
useImperativeHandle(ref, () => ({
onCheck,
setFieldsValue: form.setFieldsValue,
......@@ -117,7 +123,7 @@ const FormRuleVPictures = forwardRef((props, ref) => {
imageList: {},
detailImageList: [],
}}
onValuesChange={props.onValuesChange}
onValuesChange={getFormValues}
>
<Form.Item
name="commonImageList"
......
......@@ -3,6 +3,7 @@ import { Form, Input, Select, Checkbox, Radio, Space, InputNumber } from 'antd';
import { Title } from './CommonTemplate';
import { formItemLayout } from '../config';
import { ServiceContext } from '../context';
import { debounce } from '@/utils/utils';
const createInitValues = () => ({
settlementMethod: 1,
......@@ -35,6 +36,11 @@ const FormSettlementOthers = forwardRef((props, ref) => {
}
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
props.onValuesChange(values);
}, 400);
useEffect(() => {
if (customer.isEdit) {
if (!editData) return;
......@@ -120,7 +126,7 @@ const FormSettlementOthers = forwardRef((props, ref) => {
name="register"
initialValues={initValue}
scrollToFirstError
onValuesChange={props.onValuesChange}
onValuesChange={getFormValues}
>
<Form.Item
name="appointment"
......
......@@ -72,15 +72,17 @@ const ServiceGoods = options => {
const productChange = task => {
setProductType(task.type);
onAutoSaveValue(
{
type: task.type,
},
!0,
);
setPageLoading(true);
const timer = setTimeout(() => {
setPageLoading(false);
resetForm();
clearTimeout(timer);
onAutoSaveValue(
{
type: task.type,
},
!0,
);
}, 1000);
};
......
......@@ -109,7 +109,6 @@ const filterItems = (type, props) => {
};
export const filterSendData = (type, params) => {
console.log('===============>生成数据', params);
const { infoMation, infoImageData, attributeApplyList } = params;
const items = filterItems(type, params);
const commonImageList = type === 4 ? [] : infoImageData.commonImageList;
......@@ -258,30 +257,44 @@ export const onAutoSaveValue = (e, isClear) => {
localStorage.set(localkey, Object.assign({}, e));
} else {
const info = localStorage.get(localkey) || {};
console.log('e :>> ', e);
const key = Object.keys(e)[0];
if (getObjectType(e[key]) === 'Array') {
e[key].forEach((item, i) => {
if (item !== null) {
if (getObjectType(item) === 'Object') {
const itemkeys = Object.keys(item);
if (itemkeys.length > 1 || info[key][i] === null) {
info[key][i] = item;
} else {
info[key][i][itemkeys[0]] = item[itemkeys[0]];
}
} else {
info[key][i] = item;
}
}
});
localStorage.set(localkey, Object.assign({}, info));
} else if (getObjectType(e[key]) === 'Object') {
const okey = Object.keys(e[key])[0];
info[key][okey] = e[key][okey];
} else {
localStorage.set(localkey, Object.assign({}, info, e));
}
localStorage.set(localkey, Object.assign({}, info, e));
}
message.success('已自动保存至缓存');
};
// export const onAutoSaveValue = (e, isClear) => {
// const localkey = 'good-info-auto-save';
// if (isClear) {
// localStorage.set(localkey, Object.assign({}, e));
// } else {
// const info = localStorage.get(localkey) || {};
// const key = Object.keys(e)[0];
// if (info[key] === undefined) {
// info[key] = e[key];
// localStorage.set(localkey, Object.assign({}, info));
// return;
// }
// if (getObjectType(e[key]) === 'Array' && e[key].length && getObjectType(e[key][0]) === 'Object') {
// e[key].forEach((item, i) => {
// if (item !== null) {
// if (getObjectType(item) === 'Object') {
// const itemkeys = Object.keys(item);
// if (itemkeys.length > 1 || info[key][i] === null) {
// info[key][i] = item;
// } else {
// info[key][i][itemkeys[0]] = item[itemkeys[0]];
// }
// } else {
// info[key][i] = item;
// }
// }
// });
// localStorage.set(localkey, Object.assign({}, info));
// } else if (getObjectType(e[key]) === 'Object') {
// const okey = Object.keys(e[key])[0];
// info[key][okey] = e[key][okey];
// } else {
// localStorage.set(localkey, Object.assign({}, info, e));
// }
// }
// message.success('已自动保存至缓存');
// };
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