Commit 65ffab8e authored by 武广's avatar 武广

fix: 修改库存变动

parent 8ba34eb5
......@@ -8,7 +8,6 @@ import styles from '../style.less';
const UpdateStock = props => {
const { getFieldDecorator, validateFields, resetFields, getFieldValue } = props.form;
const valueInfo = props.info;
getFieldDecorator('changeType', { initialValue: 28 });
const [loading, setLoading] = useState(false);
......@@ -50,7 +49,8 @@ const UpdateStock = props => {
const validatorCallback = (rule, value, callback) => {
// 减库存存时,校验可售库存-输入值>=0,即可售库存不可为负;
const changeType = getFieldValue('changeType');
const increment = valueInfo.stock - value;
const increment = valueInfo.marketableStock - value;
console.log('value :>> ', value, valueInfo.marketableStock);
console.log('valueInfo :>> ', valueInfo, increment);
return +changeType === 29 && increment < 0 ? callback(new Error(rule.message)) : callback();
};
......@@ -59,7 +59,7 @@ const UpdateStock = props => {
<Modal
title="修改库存"
visible={props.visible}
okButtonProps={{ loading }}
okButtonProps={{ loading, disabled: valueInfo.status === 1 }}
onCancel={onCancel}
onOk={submit}
width={500}
......@@ -71,14 +71,15 @@ const UpdateStock = props => {
</Form.Item>
) : (
<Form.Item label="当前库存:">
<span>{valueInfo.stock}</span>
<span>{valueInfo.curStock}</span>
</Form.Item>
)}
<Form.Item label="变更类型:">
{getFieldDecorator('changeType', {
rules: [{ required: true, message: '请选择类型!' }],
initialValue: valueInfo.changeType || 28,
})(
<Radio.Group>
<Radio.Group disabled={valueInfo.status === 1}>
<Radio value={28}>增库存</Radio>
<Radio value={29}>减库存</Radio>
<Radio value={30}>使用新值</Radio>
......@@ -93,15 +94,24 @@ const UpdateStock = props => {
{ validator: validatorCallback, message: '减库存,输入库存数不可大于可售库存!' },
],
validateTrigger: ['onSubmit', 'onChange'],
})(<InputNumber min={0} precision={0} placeholder="请输入库存" style={{ width: 200 }} />)}
initialValue: valueInfo.stock,
})(
<InputNumber
min={0}
precision={0}
placeholder="请输入库存"
disabled={valueInfo.status === 1}
style={{ width: 200 }}
/>,
)}
</Form.Item>
<Form.Item label="变更原因:">
{getFieldDecorator('changeReason', {
rules: [{ required: true, message: '请输入变更原因!' }],
initialValue: valueInfo.changeReason,
})(<Input.TextArea />)}
})(<Input.TextArea disabled={valueInfo.status === 1} />)}
</Form.Item>
{valueInfo.state === 4 && <div className={styles.stockErrMsg}>审核中</div>}
{valueInfo.stateDesc && <div className={styles.stockErrMsg}>{valueInfo.stateDesc}</div>}
</Form>
</Modal>
);
......
......@@ -19,6 +19,7 @@ import {
specList,
queryAllAfterAddress,
apiEnableUpdataStock,
apiQueryLastChangeLog,
} from './service';
import LogModal from './LogModal';
import CreateModal from './createModal';
......@@ -225,13 +226,8 @@ class goodsManage extends Component {
list.filter(item => isEdit || !JDSHOPID.includes(item.id));
// 验证是否可以修改库存
checkEnableUpdateStock = async (row = {}) => {
let ids = '';
if (row && row.skuId) {
ids = row.skuId;
} else {
ids = this.state.selectedRowKeys.join(',');
}
checkEnableUpdateStock = async () => {
const ids = this.state.selectedRowKeys.join(',');
if (ids) {
const res = await apiEnableUpdataStock(ids);
if (res.data) {
......@@ -239,7 +235,7 @@ class goodsManage extends Component {
this.setState({
stockSkuIds: res.data.successSkuIds,
});
this.openModal(row, 1);
this.openModal({}, 1);
} else {
const message = res.data.failedInfoList[0]?.message || '未存在可修改库存的商品';
notification.info({ message });
......@@ -284,6 +280,36 @@ class goodsManage extends Component {
});
};
onShowStockModal = async row => {
console.log('row :>> ', row);
const res = await apiQueryLastChangeLog(row.skuId);
console.log('res :>> ', res);
let priceInfo = {
id: row.skuId,
curStock: row.productStock,
supplierId: row.supplierId,
marketableStock: row.stock,
};
if (res.data && [1, 3].includes(+res.data.status)) {
priceInfo = Object.assign(
{
changeReason: res.data.changeReason,
stock: +res.data.afterChange,
changeType: res.data.changeType,
status: res.data.status,
stateDesc: res.data.statusDesc,
},
priceInfo,
);
}
console.log('priceInfo :>> ', priceInfo);
this.setState({
updateStockVisible: true,
priceInfo,
stockSkuIds: [row.skuId],
});
};
cancel = query => {
this.setState({ updateStockVisible: false });
if (query) {
......
......@@ -224,3 +224,9 @@ export const apiCreateGoodsLog = params =>
data: params,
prefix: goodsApi,
});
// 查询sku最后一条库存变更记录
export const apiQueryLastChangeLog = skuId =>
request.get(`/api/kdsp/sku/last/stockChange/record?skuId=${skuId}`, {
prefix: goodsApi,
});
......@@ -110,11 +110,7 @@ export function column() {
render: (_, row) => {
// const stockView = row.productStock;
const stockView = (
<Button
type="link"
onClick={() => this.checkEnableUpdateStock(row)}
style={{ padding: 0 }}
>
<Button type="link" onClick={() => this.onShowStockModal(row)} style={{ padding: 0 }}>
{row.productStock}
</Button>
);
......
......@@ -106,7 +106,7 @@
}
.stockErrMsg {
box-sizing: border-box;
padding-left: 25%;
padding-left: 30%;
color: #d9363e;
line-height: 1;
}
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