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

fix: 修改库存问题

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