Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
merchant-manage-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
merchant-manage-ui
Commits
aadf31b8
Commit
aadf31b8
authored
Apr 04, 2023
by
陈万宝
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修改库存问题
parent
8f1a428f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
142 additions
and
77 deletions
+142
-77
AddRepertoryModal.jsx
src/pages/ServiceGoods/components/AddRepertoryModal.jsx
+44
-29
FormInformationBasic.jsx
src/pages/ServiceGoods/components/FormInformationBasic.jsx
+6
-6
FormTakeaway.jsx
src/pages/ServiceGoods/components/FormTakeaway.jsx
+62
-35
index.jsx
src/pages/ServiceGoods/index.jsx
+8
-6
utils.js
src/pages/ServiceGoods/utils.js
+6
-1
validator.js
src/utils/validator.js
+16
-0
No files found.
src/pages/ServiceGoods/components/AddRepertoryModal.jsx
View file @
aadf31b8
...
...
@@ -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
}
...
...
src/pages/ServiceGoods/components/FormInformationBasic.jsx
View file @
aadf31b8
...
...
@@ -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
...
...
src/pages/ServiceGoods/components/FormTakeaway.jsx
View file @
aadf31b8
...
...
@@ -31,6 +31,7 @@ import { Title } from './CommonTemplate';
import
{
formItemLayout
,
ENUM_REPERTORY
,
ENUM_SET_REPERTORY
,
ENUM_WEEK
}
from
'
../config
'
;
import
{
ServiceContext
}
from
'
../context
'
;
import
{
debounce
}
from
'
@/utils/utils
'
;
import
{
isCheckPriceTwoDecimal
,
isIntegerNotZero
}
from
'
@/utils/validator
'
;
import
UploadCropImage
from
'
./UploadCropImage
'
;
// import AddSellTimeModal from './AddSellTimeModal';
import
styles
from
'
../common.less
'
;
...
...
@@ -70,7 +71,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const
[
unitsList
,
setUnitsList
]
=
useState
([]);
const
[
takeawayData
,
setTakeawayData
]
=
useState
({});
let
[
multiSpu
,
setMultiSpu
]
=
useState
([]);
cons
t
[
singularSpu
,
setSingularSpu
]
=
useState
([]);
le
t
[
singularSpu
,
setSingularSpu
]
=
useState
([]);
const
[
intactData
,
setIntactData
]
=
useState
({});
const
[
repertoryState
,
setRepertoryState
]
=
useState
(
''
);
const
[
repertoryModel
,
setRepertoryModel
]
=
useState
({});
...
...
@@ -108,7 +109,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
description
,
detailImageList
,
list
,
minPurchaseNum
=
0
,
minPurchaseNum
=
1
,
saleDates
,
maxStock
=
0
,
saleTimes
=
[],
...
...
@@ -130,9 +131,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const
singularSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 单规格
const
multiSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 多规格
// const multiSpu = customer.isEdit ? skuList:[]; // 多库存spu、
let
singularSpu
=
[];
// 单库存spu
//
let singularSpu = []; // 单库存spu
const
saleTimesTemp
=
[];
let
initIndex
=
0
;
if
(
saleTimes
.
length
)
{
saleTimes
.
forEach
(
item
=>
{
const
startTime
=
item
?
moment
(
item
[
0
]).
format
(
format
)
:
''
;
...
...
@@ -178,6 +178,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singularSpecList
[
0
].
specs
=
[
specs
];
singularSpu
=
[{
...
temp
,
specs
:
[
specs
]
}];
setSingularSpu
(
singularSpu
);
console
.
log
(
'
singularSpu
'
,
singularSpu
);
}
// 多规格
if
(
+
repertoryType
===
2
)
{
...
...
@@ -280,6 +281,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
list
,
description
,
detailImageList
,
repertoryType
,
singleDelivery
,
specList
:
+
repertoryType
===
1
?
singularSpecList
:
multiSpecList
,
// 单库存和多库存specList
items
:
+
repertoryType
===
1
?
singularSpu
:
JSON
.
parse
(
JSON
.
stringify
(
multiSpu
)),
...
...
@@ -311,7 +313,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
props
.
onValuesChange
({
takeawayItem
:
JSON
.
parse
(
JSON
.
stringify
(
values
))
});
const
takeawayData
=
customer
.
isEdit
?
{
takeawayItem
:
Object
.
assign
({},
editData
,
values
)
}
:
localStorage
.
get
(
localAutoSaveKey
)
||
{};
:
{
takeawayItem
:
values
};
// : localStorage.get(localAutoSaveKey) || {};
setTakeawayData
(
takeawayData
);
takeawayCalc
(
takeawayData
);
},
400
);
...
...
@@ -492,7 +495,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
useEffect(() => {
if (customer.isEdit || customer.isUseCache) {
if (!editData) return;
let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id ,saleTimes} = editData;
let {
label,
firstCategoryId,
secondCategoryId,
thirdCategoryId,
id,
saleTimes,
saleTimeType,
} = editData;
editData.label = label && label.split(',')?.map(item => +item);
let specList = editData?.specList;
let weight = specList?.filter(item => item.specGroupName === '份量');
...
...
@@ -508,20 +519,20 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
});
}
});
editData.saleTimes = saleTimes.length
? saleTimes.map(item => {
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: [];
editData.saleTimes = saleTimes
?
.length
? saleTimes.map(item => {
return [moment(item?.startTime, format), moment(item?.endTime, format)];
})
: [];
if (editData?.skuList?.length) {
// editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
// 单规格
if (
specs.length === 0 && !editData?.specList[0]?.specs[0]?.activityPrice
) {
if (
editData?.skuList?.length === 1
) {
let {
productStock,
shopId,
specs,
serviceItem: { maxStock,
saleTimeType, saleDates, saleTimes,
id, autoStock },
serviceItem: { maxStock, id, autoStock },
} = editData?.skuList[0];
let { quantity, unit, salePrice } = specs[0];
editData.productStock = productStock;
...
...
@@ -530,15 +541,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
editData.salePrice = salePrice;
editData.maxStock = maxStock;
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
// editData.saleTimeType = saleTimeType;
// editData.saleDates = saleDates;
editData.autoStock = +autoStock === 1 ? true : false;
editData.productRefShopId = editData.shopId;
editData.skuId = id;
// setSingularSpu(JSON.parse(JSON.stringify(tempMultiSpu)) || []);
form.setFieldsValue(editData);
setTimeType(saleTimeType);
} else {
// 多规格
setRepertoryType(`
2
`);
...
...
@@ -560,20 +567,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
});
}
});
console.log(specs, 'specs');
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
// editData.saleTimeType = saleTimeType;
// editData.saleDates = saleDates;
// editData.saleTimes = saleTimes.length
// ? saleTimes.map(item => {
// return [moment(item?.startTime, format), moment(item?.endTime, format)];
// })
// : [];
editData.productRefShopId = editData.shopId;
// setTempWeight(weight)
// setTempSpecs(specs)
setTimeType(saleTimeType);
form.setFieldsValue({ weight: weight[0].specs });
form.setFieldsValue(editData);
form.setFieldsValue({ specs });
...
...
@@ -590,12 +588,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}
return item;
});
setTempMultiSpu(tempMultiSpu || []);
setMultiSpu(JSON.parse(JSON.stringify(tempMultiSpu)) || []);
}
setTimeType(saleTimeType);
form.setFieldsValue({ productRefShopId: editData.shopId });
onCardSuccessImageList(editData?.detailImageList);
getFormValues();
}
}
}, [customer.isEdit, editData]);
...
...
@@ -659,7 +658,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Radio value={1}>自定义售卖时间</Radio>
</Radio.Group>
</Form.Item>
{timeType === 1 && (
{
+
timeType === 1 && (
<>
<Form.Item name="saleDates" label="售卖时期(可多选)">
<Checkbox.Group>
...
...
@@ -793,7 +792,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
style={{
display: 'inline-block',
}}
rules={[{ required: true, message: '请输入分量' }]}
rules={[
{ required: true, message: '请输入分量!' },
{
validator: isCheckPriceTwoDecimal,
type: 'number',
message: '保留两位小数',
},
]}
>
<InputNumber
min={1}
...
...
@@ -852,7 +858,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
display: 'flex',
marginRight: '8px',
}}
rules={[{ required: true, message: '请填写剩余库存' }]}
rules={[
{ required: true, message: '请填写剩余库存' },
{
validator: isIntegerNotZero,
type: 'number',
message: '请输入大于0的整数',
},
]}
>
<InputNumber
min={0}
...
...
@@ -871,7 +884,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
<Form.Item
name="maxStock"
label="最大库存"
rules={[{ required: isRequired, message: '请填写最大库存' }]}
rules={[{ required: isRequired, message: '请填写最大库存' },
{
validator: isIntegerNotZero,
type: 'number',
message: '请输入大于0的整数',
},
]}
>
<InputNumber
max={999999999}
...
...
@@ -891,7 +910,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
<div className={styles.rowWarp}>
{singularSpu.length > 0 &&
singularSpu[0]?.specs[0]?.unit
&&
singularSpu[0]?.specs[0]?.unit &&
singularSpu.map((item, index) => (
<div className={styles.specsSingularBetween}>
<Form.Item label={calcLabelName(intactData, item, 'singular')}>
...
...
@@ -946,8 +965,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
{form => {
let unit = form.getFieldValue(['weight'])?.[index]?.unit || '';
unit =
(unit && (Array.isArray(unit) && unit?.length && unit?.slice(1).toString())) ||
unit;
(unit &&
(Array.isArray(unit) &&
unit?.length &&
unit?.slice(1).toString())) ||
unit;
if (!peopleUnits.includes(unit)) {
return (
<Form.Item
...
...
@@ -968,6 +990,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
: true,
message: '份量',
},
{
validator: isIntegerNotZero,
type: 'number',
message: '请输入大于0的整数',
},
]}
>
<InputNumber
...
...
src/pages/ServiceGoods/index.jsx
View file @
aadf31b8
...
...
@@ -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
}
>
...
...
src/pages/ServiceGoods/utils.js
View file @
aadf31b8
...
...
@@ -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));
}
};
...
...
src/utils/validator.js
View file @
aadf31b8
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment