Commit 02e5e774 authored by 武广's avatar 武广

fix: 修改库存校验

parent 90733548
......@@ -4,6 +4,7 @@ import { Modal, InputNumber, notification, Input, Radio } from 'antd';
import React, { useState } from 'react';
import { apiCreateGoodsLog } from '../service';
import styles from '../style.less';
import { isNumberSection } from '@/utils/validator';
const UpdateStock = props => {
const { getFieldDecorator, validateFields, resetFields, getFieldValue } = props.form;
......@@ -65,14 +66,14 @@ const UpdateStock = props => {
width={500}
>
<Form {...formItemLayout}>
{props.skuIds.length > 1 ? (
<Form.Item label="可修改库存商品数:">
<span>{props.skuIds.length}</span>
</Form.Item>
) : (
{valueInfo.curStock ? (
<Form.Item label="当前库存:">
<span>{valueInfo.curStock}</span>
</Form.Item>
) : (
<Form.Item label="可修改库存商品数:">
<span>{props.skuIds.length}</span>
</Form.Item>
)}
<Form.Item label="变更类型:">
{getFieldDecorator('changeType', {
......@@ -92,6 +93,7 @@ const UpdateStock = props => {
rules: [
{ required: true, message: '请输入库存!' },
{ validator: validatorCallback, message: '减库存,输入库存数不可大于可售库存!' },
{ validator: isNumberSection, min: 1, max: 500, message: '请输入1-500的整数' },
],
validateTrigger: ['onSubmit', 'onChange'],
initialValue: valueInfo.stock,
......@@ -109,7 +111,7 @@ const UpdateStock = props => {
{getFieldDecorator('changeReason', {
rules: [{ required: true, message: '请输入变更原因!' }],
initialValue: valueInfo.changeReason,
})(<Input.TextArea disabled={valueInfo.status === 1} />)}
})(<Input.TextArea disabled={valueInfo.status === 1} maxLength={50} />)}
</Form.Item>
{valueInfo.stateDesc && <div className={styles.stockErrMsg}>{valueInfo.stateDesc}</div>}
</Form>
......
......@@ -234,6 +234,7 @@ class goodsManage extends Component {
if (res.data) {
if (res.data.successSkuIds?.length) {
this.setState({
priceInfo: {},
stockSkuIds: res.data.successSkuIds,
});
this.openModal({}, 1);
......
......@@ -101,7 +101,7 @@
}
.stockTip {
color: #999;
color: #d9363e;
line-height: 1;
}
.stockErrMsg {
......
......@@ -172,6 +172,24 @@ export const isIntegerNotZero = (rule, value, callback) => {
}
};
/**
* 验证 数字区间
* rule.min: 0
* rule.max: 100
*/
export const isNumberSection = (rule, value, callback) => {
if (['', undefined, null].includes(value)) {
callback();
}
if (!Number(value)) {
callback(new Error('请输入数字'));
} else if (rule.min > +value || rule.max < +value) {
callback(new Error(rule.message || `请输入${rule.min}-${rule.max}区间的数字`));
} else {
callback();
}
};
// 验证是否整数,非必填
export function isIntegerNotMust(rule, value, callback) {
if (!value) {
......
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