Commit aadf31b8 authored by 陈万宝's avatar 陈万宝

fix: 修改库存问题

parent 8f1a428f
...@@ -3,6 +3,7 @@ import { Button, Modal, Radio, Form, InputNumber, Switch, Space, message } from ...@@ -3,6 +3,7 @@ import { Button, Modal, Radio, Form, InputNumber, Switch, Space, message } from
import styles from '../common.less'; import styles from '../common.less';
import { ENUM_SET_REPERTORY } from '../config'; import { ENUM_SET_REPERTORY } from '../config';
import { debounce } from '@/utils/utils'; import { debounce } from '@/utils/utils';
import { isCheckPriceTwoDecimal, isIntegerNotZero } from '@/utils/validator';
const AddRepertoryModal = (props, ref) => { const AddRepertoryModal = (props, ref) => {
const [confirmLoading, setConfirmLoading] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false);
...@@ -28,7 +29,7 @@ const AddRepertoryModal = (props, ref) => { ...@@ -28,7 +29,7 @@ const AddRepertoryModal = (props, ref) => {
form.setFieldsValue({ form.setFieldsValue({
autoStock: e ? 1 : 0, autoStock: e ? 1 : 0,
}); });
setIsRequired(!e) setIsRequired(!e);
}; };
// 勾选库存设置 // 勾选库存设置
const onChangeSetRepertory = e => { const onChangeSetRepertory = e => {
...@@ -60,8 +61,8 @@ const AddRepertoryModal = (props, ref) => { ...@@ -60,8 +61,8 @@ const AddRepertoryModal = (props, ref) => {
const values = await form.validateFields(); const values = await form.validateFields();
values.autoStock = values.autoStock ? 1 : 0; values.autoStock = values.autoStock ? 1 : 0;
if (+values.autoStock === 1 && +values.maxStock === 0) { if (+values.autoStock === 1 && +values.maxStock === 0) {
message.error('最大库存不能为0') message.error('最大库存不能为0');
return return;
} }
// 回调库存 // 回调库存
modifiedInventory(type, idx, values); modifiedInventory(type, idx, values);
...@@ -110,37 +111,51 @@ const AddRepertoryModal = (props, ref) => { ...@@ -110,37 +111,51 @@ const AddRepertoryModal = (props, ref) => {
onCancel={handleCancel} onCancel={handleCancel}
> >
<Form form={form} initialValues={initialValues} onValuesChange={getFormValues}> <Form form={form} initialValues={initialValues} onValuesChange={getFormValues}>
<Space> <Space>
<Form.Item className={styles.itemInlineModal}> <Form.Item className={styles.itemInlineModal}>
<Form.Item <Form.Item
name="productStock" name="productStock"
label="剩余库存" label="剩余库存"
style={{ style={{
display: 'flex', display: 'flex',
marginRight: '8px', marginRight: '8px',
}} }}
rules={[{ required: true, message: '请填写剩余库存' }]} rules={[
> { required: true, message: '请填写剩余库存' },
<InputNumber {
min={0} validator: isIntegerNotZero,
max={999999999} type: 'number',
style={{ width: 200, display: 'inline-block' }} message: '请输入大于0的整数',
placeholder="请输入" },
/> ]}
>
<InputNumber
min={0}
max={999999999}
style={{ width: 200, display: 'inline-block' }}
placeholder="请输入"
/>
</Form.Item>
<Form.Item style={{ width: 200, display: 'inline-block' }}>
<Radio.Group value={repertoryState} onChange={onChangeSetRepertory}>
<Radio.Button value="0">清空</Radio.Button>
<Radio.Button value="1">最大</Radio.Button>
</Radio.Group>
</Form.Item>
</Form.Item> </Form.Item>
<Form.Item style={{ width: 200, display: 'inline-block' }}> </Space>
<Radio.Group value={repertoryState} onChange={onChangeSetRepertory}>
<Radio.Button value="0">清空</Radio.Button>
<Radio.Button value="1">最大</Radio.Button>
</Radio.Group>
</Form.Item>
</Form.Item>
</Space>
<Form.Item <Form.Item
name="maxStock" name="maxStock"
label="最大库存" label="最大库存"
rules={[{ required: isRequired, message: '请填写最大库存' }]} rules={[
{ required: isRequired, message: '请填写最大库存' },
{
validator: isIntegerNotZero,
type: 'number',
message: '请输入大于0的整数',
},
]}
> >
<InputNumber <InputNumber
min={0} min={0}
......
...@@ -167,14 +167,16 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -167,14 +167,16 @@ const FormInformationBasic = forwardRef((props, ref) => {
useEffect(() => { useEffect(() => {
if (!editData) return; if (!editData) return;
if (editData.productType === 5 && editData.name) { if (editData.productType === 5 && editData?.name) {
shopGetByProductType(5); shopGetByProductType(5);
queryShopList({ shopId: editData.productRefShopId }); queryShopList({ shopId: editData?.productRefShopId });
setShopIdSource(editData.productRefShopId); setShopIdSource(editData?.productRefShopId);
setIsEditTakeaway(true); setIsEditTakeaway(true);
} }
form.setFieldsValue(editData); form.setFieldsValue(editData);
onTakeawayImageList(editData.commonImageList); if (editData?.commonImageList?.length) {
onTakeawayImageList(editData?.commonImageList);
}
}, [customer.isEdit, editData]); }, [customer.isEdit, editData]);
useEffect(() => { useEffect(() => {
setShopList([]); setShopList([]);
...@@ -188,9 +190,7 @@ const FormInformationBasic = forwardRef((props, ref) => { ...@@ -188,9 +190,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
productRefShopId: shopId ? [`${shopId}`] : [], productRefShopId: shopId ? [`${shopId}`] : [],
storageRackIds: groupId ? [+groupId] : [], storageRackIds: groupId ? [+groupId] : [],
}; };
setTimeout(() => {
form.setFieldsValue(temp); form.setFieldsValue(temp);
}, []);
}, [groupShopData]); }, [groupShopData]);
return ( return (
<Form <Form
......
...@@ -87,7 +87,7 @@ const ServiceGoods = options => { ...@@ -87,7 +87,7 @@ const ServiceGoods = options => {
const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset()); const resetForm = () => clearCurrent(checkFormList).forEach(({ current }) => current.reset());
const onValuesChange = e => { const onValuesChange = e => {
if (!isEdit) { if (!isEdit && productType !== 5) {
if (visibleCacheEdit) { if (visibleCacheEdit) {
setVisibleCacheEdit(false); setVisibleCacheEdit(false);
localStorage.remove(localAutoSaveKey); localStorage.remove(localAutoSaveKey);
...@@ -102,7 +102,6 @@ const ServiceGoods = options => { ...@@ -102,7 +102,6 @@ const ServiceGoods = options => {
} }
if (productType === 5) { if (productType === 5) {
setTakeawayInfoMation(e); setTakeawayInfoMation(e);
// console.log('takeawayInfoMation', takeawayInfoMation);
} }
}; };
...@@ -253,8 +252,12 @@ const ServiceGoods = options => { ...@@ -253,8 +252,12 @@ const ServiceGoods = options => {
const sendData = filterSendData(productType, params); const sendData = filterSendData(productType, params);
if (productType === 5) { if (productType === 5) {
console.log(sendData, 'sendData'); console.log(sendData, 'sendData');
if (+sendData?.repertoryType === 2 && sendData?.items?.length < 2) {
message.error('最少生成2个sku')
return
}
sendMerchantProductHttpRequest(sendData); sendMerchantProductHttpRequest(sendData);
return false; return;
} }
if (isEdit) { if (isEdit) {
sendData.id = pageId; sendData.id = pageId;
...@@ -374,9 +377,8 @@ const ServiceGoods = options => { ...@@ -374,9 +377,8 @@ const ServiceGoods = options => {
[specKeyList], [specKeyList],
); );
useEffect(() => { useEffect(() => {
console.log('takeAway', takeAway);
// 外卖类型 // 外卖类型
if (Object.keys(takeAway).length) { if (Object.keys(takeAway)?.length) {
const { spuId = '', groupId = '' } = takeAway; const { spuId = '', groupId = '' } = takeAway;
if (spuId) { if (spuId) {
querGetShopDetail(takeAway); querGetShopDetail(takeAway);
...@@ -510,7 +512,7 @@ const ServiceGoods = options => { ...@@ -510,7 +512,7 @@ const ServiceGoods = options => {
> >
<Spin tip="正在加载..." spinning={pageLoading} delay={100}> <Spin tip="正在加载..." spinning={pageLoading} delay={100}>
<WrapperContainer> <WrapperContainer>
{visibleCacheEdit && productType !== 5 && ( {visibleCacheEdit && (
<div className={styles.draftBox}> <div className={styles.draftBox}>
有未保存内容。是否 有未保存内容。是否
<span className={styles.conEdit} onClick={onContinueEdit}> <span className={styles.conEdit} onClick={onContinueEdit}>
......
...@@ -300,6 +300,11 @@ export const createProductData = (props, isEdit, skuList) => { ...@@ -300,6 +300,11 @@ export const createProductData = (props, isEdit, skuList) => {
export const localAutoSaveKey = 'good-info-auto-save'; export const localAutoSaveKey = 'good-info-auto-save';
export const onAutoSaveValue = (e, isClear) => { export const onAutoSaveValue = (e, isClear) => {
// 暂时去掉外卖类型
if (e && e.type === 5) {
localStorage.remove(localAutoSaveKey);
return;
}
const keys = Object.keys(e); const keys = Object.keys(e);
if ( if (
e && e &&
...@@ -314,7 +319,7 @@ export const onAutoSaveValue = (e, isClear) => { ...@@ -314,7 +319,7 @@ export const onAutoSaveValue = (e, isClear) => {
localStorage.set(localAutoSaveKey, Object.assign({}, e)); localStorage.set(localAutoSaveKey, Object.assign({}, e));
} else { } else {
const info = localStorage.get(localAutoSaveKey) || {}; const info = localStorage.get(localAutoSaveKey) || {};
localStorage.set(localAutoSaveKey, Object.assign({ type: 1 }, info, e)); localStorage.set(localAutoSaveKey, Object.assign({ type:e.type }, info, e));
} }
}; };
......
...@@ -419,3 +419,19 @@ export function isCheckPriceOneDecimal(rule, value, callback) { ...@@ -419,3 +419,19 @@ export function isCheckPriceOneDecimal(rule, value, callback) {
callback(); callback();
} }
} }
// 验证价格保留小数点2位
export function isCheckPriceTwoDecimal(rule, value, callback) {
const num = +value;
const arr = `${value}`.split('.');
if (!value) {
callback();
} else if (Number.isNaN(num)) {
callback(new Error('请输入数字'));
} else if (num < 0) {
callback(new Error('请输入大于0的数字'));
} else if (arr.length === 2 && arr[1].length > 2) {
callback(new Error('小数点保留2位'));
} else {
callback();
}
}
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