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

fix: 修改库存校验

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