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
184bb8b8
Commit
184bb8b8
authored
Mar 28, 2023
by
陈万宝
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 更新回显商品
parent
cdf53e53
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
56 deletions
+112
-56
FormInformationBasic.jsx
src/pages/ServiceGoods/components/FormInformationBasic.jsx
+17
-12
FormTakeaway.jsx
src/pages/ServiceGoods/components/FormTakeaway.jsx
+53
-27
index.jsx
src/pages/ServiceGoods/index.jsx
+37
-13
utils.js
src/pages/ServiceGoods/utils.js
+5
-4
No files found.
src/pages/ServiceGoods/components/FormInformationBasic.jsx
View file @
184bb8b8
...
...
@@ -22,7 +22,6 @@ const CreateSelectOption = optionList =>
));
const
fileterBrandOptions
=
(
input
,
options
)
=>
options
.
children
.
includes
(
input
);
const
filterCategoryOptions
=
(
inputValue
,
path
)
=>
path
.
some
(
option
=>
option
.
name
.
toLowerCase
().
indexOf
(
inputValue
.
toLowerCase
())
>
-
1
);
...
...
@@ -43,6 +42,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
const
[
takeawayImageList
,
setTakeawayImageList
]
=
useState
([]);
const
[
shopIds
,
setShopIds
]
=
useState
([]);
const
[
shopList
,
setShopList
]
=
useState
([]);
const
[
isEditTakeaway
,
setIsEditTakeaway
]
=
useState
(
false
);
const
onCheck
=
async
()
=>
{
try
{
...
...
@@ -118,13 +118,17 @@ const FormInformationBasic = forwardRef((props, ref) => {
};
const
onChangeShopId
=
async
e
=>
{
if
(
e
)
{
queryShopList
({
shopId
:
e
});
// 分组列表
setShopList
([]);
queryShopList
({
shopId
:
e
});
}
};
useImperativeHandle
(
ref
,
()
=>
({
onCheck
,
reset
:
form
.
resetFields
,
}));
useEffect
(()
=>
{
queryShopIds
();
},
[
customer
.
productType
]);
useEffect
(()
=>
{
const
noreList
=
(
brandList
||
[]).
filter
(
item
=>
item
.
name
===
'
虚拟商品
'
);
...
...
@@ -132,16 +136,16 @@ const FormInformationBasic = forwardRef((props, ref) => {
},
[
brandList
]);
useEffect
(()
=>
{
console
.
log
(
'
商品类目
'
,
newCategoryList
[
customer
.
productType
]);
if
(
!
editData
)
return
;
if
(
editData
.
productType
===
5
&&
editData
.
name
)
{
queryShopList
({
shopId
:
editData
.
productRefShopId
});
setIsEditTakeaway
(
true
);
}
form
.
setFieldsValue
(
editData
);
onTakeawayImageList
(
editData
.
commonImageList
);
},
[
customer
.
isEdit
,
editData
]);
useEffect
(()
=>
{
console
.
log
(
'
!customer.isTakeawayService
'
,
customer
);
console
.
log
(
'
newCategoryList[customer.productType]
'
,
newCategoryList
[
customer
.
productType
]);
console
.
log
(
'
newCategoryList[customer.productType]
'
,
shopList
);
queryShopIds
()
},
[
customer
.
productType
]);
return
(
<
Form
{
...
formItemLayout
}
...
...
@@ -152,6 +156,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
name
:
''
,
categoryId
:
[],
description
:
''
,
productRefShopId
:
[
15
],
storageRackIds
:
[],
}
}
scrollToFirstError
onValuesChange=
{
getFormValues
}
...
...
@@ -165,18 +171,18 @@ const FormInformationBasic = forwardRef((props, ref) => {
{
required
:
true
,
min
:
2
,
message
:
'
请输入最少两个字符的商品名称
'
,
whitespace
:
true
},
]
}
>
<
Input
placeholder=
"请输入商品名称"
disabled=
{
customer
.
isDisabled
}
/>
<
Input
placeholder=
"请输入商品名称"
disabled=
{
customer
.
isDisabled
||
isEditTakeaway
}
/>
</
Form
.
Item
>
</
Popover
>
{
customer
.
isTakeawayService
&&
(
<
Form
.
Item
name=
"productRefShopId"
key=
"productRefShopId"
label=
"所属门店"
rules=
{
[{
required
:
true
,
message
:
'
请选择所属门店
'
}]
}
>
<
Select
fieldNames=
{
{
label
:
'
name
'
,
value
:
'
id
'
}
}
filterOption=
{
fileterBrandOptions
}
placeholder=
"请选择所属门店"
options=
{
shopIds
}
onChange=
{
onChangeShopId
}
...
...
@@ -195,7 +201,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
disabled=
{
customer
.
isEdit
&&
customer
.
isNormal
}
showSearch=
{
{
filter
:
filterCategoryOptions
}
}
fieldNames=
{
{
label
:
'
name
'
,
value
:
'
id
'
,
children
:
'
children
'
}
}
onChange=
{
props
.
onCategoryChange
}
//
onChange=
{
props
.
onCategoryChange
}
options=
{
shopList
}
dropdownRender=
{
dropdownRender
}
/>
...
...
@@ -205,7 +211,6 @@ const FormInformationBasic = forwardRef((props, ref) => {
<
AddMenusModal
ref=
{
childAddMenusModalRef
}
queryShopList=
{
queryShopList
}
/>
<
Form
.
Item
name=
"categoryId"
key=
"categoryId"
label=
"商品类目"
rules=
{
[{
type
:
'
array
'
,
required
:
true
,
message
:
'
请输入商品类目
'
}]
}
>
...
...
src/pages/ServiceGoods/components/FormTakeaway.jsx
View file @
184bb8b8
...
...
@@ -47,16 +47,16 @@ const createInitValues = () => ({
saleTimeType
:
0
,
// 售卖时间
singleDelivery
:
0
,
// 单点不送
list
:
1
,
// 列出商品
label
:
''
,
});
const
format
=
'
HH:mm
'
;
const
{
RangePicker
}
=
DatePicker
;
const
TakeawayGoodsInfo
=
forwardRef
((
props
,
ref
)
=>
{
const
{
editData
,
infoMation
,
takeAway
}
=
props
;
const
{
editData
}
=
props
;
const
[
form
]
=
Form
.
useForm
();
const
[
initValue
,
setInitValue
]
=
useState
(
createInitValues
());
const
customer
=
useContext
(
ServiceContext
);
const
[
detailImageList
,
setDetailImageList
]
=
useState
([]);
const
[
newCategoryList
,
setNewCategoryList
]
=
useState
({});
const
addSellTimeRef
=
useRef
(
null
);
const
AddRepertoryRef
=
useRef
(
null
);
const
AddMultiSpecRef
=
useRef
(
null
);
...
...
@@ -69,8 +69,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const
[
tagList
,
setTagList
]
=
useState
([]);
const
[
unitsList
,
setUnitsList
]
=
useState
([]);
const
[
takeawayData
,
setTakeawayData
]
=
useState
({});
// const [multiSpecList, setMultiSpecList] = useState([]);
// const [singularSpecList, setSingularSpecList] = useState([]);
const
[
multiSpu
,
setMultiSpu
]
=
useState
([]);
const
[
singularSpu
,
setSingularSpu
]
=
useState
([]);
const
[
intactData
,
setIntactData
]
=
useState
({});
...
...
@@ -115,14 +113,18 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
maxStock
=
0
,
saleTimes
=
[],
label
,
unit
=
[]
,
unit
,
quantity
,
productStock
=
0
,
salePrice
,
singleDelivery
,
saleTimeType
,
autoStock
=
0
,
categoryId
,
skuList
,
id
,
}
=
takeawayItem
;
console
.
log
(
'
id
'
,
id
,
skuList
);
const
singularSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 单规格
const
multiSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 多规格
const
multiSpu
=
[];
// 多库存spu、
...
...
@@ -161,7 +163,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice
,
maxStock
,
quantity
,
unit
:
(
unit
&&
unit
.
splice
(
unit
.
length
-
1
)[
0
])
||
''
,
// unit: (unit && unit?.length && unit?.splice(unit?.length - 1)[0]) || unit,
unit
,
productStock
,
specGroupName
:
'
份量
'
,
};
...
...
@@ -169,6 +172,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singularSpu
=
[{
...
temp
,
specs
:
[
specs
]
}];
setSingularSpu
(
singularSpu
);
}
console
.
log
(
'
singularSpu
'
,
singularSpu
);
// 多规格
if
(
+
repertoryType
===
2
)
{
if
(
name
)
{
...
...
@@ -245,7 +249,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}
// console.log('multiSpu', multiSpu);
console.log('multiSpu===1111', multiSpu);
if (tempMultiSpu.length) {
multiSpu.forEach((item, index) => {
tempMultiSpu.forEach((itm, idx) => {
...
...
@@ -255,15 +258,12 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
});
});
}
// debugger
console.log('multiSpu===2222', multiSpu);
setMultiSpu(multiSpu);
}
// debugger
// +repertoryType === 1 单规格 2多规格
const intactDataTemp = {
id,
type: 5, // 外卖类型
...infoMation,
label: label && label.toString(),
...
...
@@ -273,12 +273,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
singleDelivery,
specList: +repertoryType === 1 ? singularSpecList : multiSpecList, // 单库存和多库存specList
items: +repertoryType === 1 ? singularSpu : JSON.parse(JSON.stringify(multiSpu)),
categoryId: (
infoMation?.categoryId && infoMation?.categoryId?.slice(infoMation?.categoryId?.length - 1)
)?.toString(),
categoryId:
(
infoMation?.categoryId &&
infoMation?.categoryId?.slice(infoMation?.categoryId?.length - 1)
)?.toString() || categoryId,
};
console.log('intactData======>', intactData);
setIntactData(intactDataTemp);
console.log('intactData======>', intactDataTemp);
return intactData;
};
// 过滤对象
...
...
@@ -296,14 +299,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
console.log('values========', values);
props.onValuesChange({ takeawayItem: values });
const takeawayData = localStorage.get(localAutoSaveKey);
console.log('takeawayData', takeawayData);
props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) });
const takeawayData = customer.isEdit
? { takeawayItem: Object.assign({}, editData, values) }
: localStorage.get(localAutoSaveKey) || {};
console.log('takeawayDatatakeawayData', takeawayData);
setTakeawayData(takeawayData);
takeawayCalc(takeawayData);
}, 400);
// 设置库存
const modifiedInventory = (type, idx, values) => {
const { productStock, maxStock, autoStock } = values;
...
...
@@ -413,7 +416,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
};
// 自动补全
const onChangeAutoStock = e => {
console.log('e=======', e);
form.setFieldsValue({
autoStock: e ? 1 : 0,
});
...
...
@@ -452,12 +454,35 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
useEffect(() => {
if (customer.isEdit || customer.isUseCache) {
if (!editData) return;
let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id } = editData;
console.log('id', id);
editData.label = +label;
if (editData?.skuList.length) {
editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
}
// 单规格
if (editData?.skuList.length === 1) {
let {
productStock,
specs,
serviceItem: { maxStock },
} = editData?.skuList[0];
let { quantity, unit, salePrice } = specs[0];
editData.productStock = productStock;
editData.quantity = quantity;
editData.unit = unit;
editData.salePrice = salePrice;
editData.maxStock = maxStock;
editData.categoryId = [firstCategoryId, secondCategoryId, thirdCategoryId];
}
form.setFieldsValue(editData);
setInitValue({ ...editData });
onCardSuccessImageList(editData?.detailImageList);
getFormValues();
// setInitValue({ ...editData });
}
}, [customer.isEdit,
customer.isUseCache,
editData]);
}, [customer.isEdit, editData]);
useEffect(() => {
setIntactData(intactData);
//
setIntactData(intactData);
}, [intactData]);
useEffect(() => {
init();
...
...
@@ -640,7 +665,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
<Form.Item
name="unit"
rules={[{ type: 'array', required: true, message: '请选择单位' }]}
rules={[{ required: true, message: '请选择单位' }]}
// rules={[{ type: 'array', required: true, message: '请选择单位' }]}
style={{
display: 'inline-block',
margin: '0 8px',
...
...
@@ -651,7 +677,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
disabled={customer.isEdit && customer.isNormal}
showSearch={{ filter: filterCategoryOptions }}
fieldNames={{ label: 'name', value: 'name', children: 'children' }}
onChange={props.onCategoryChange}
//
onChange={props.onCategoryChange}
options={unitsList}
/>
</Form.Item>
...
...
@@ -787,7 +813,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
value: 'name',
children: 'children',
}}
onChange={props.onCategoryChange}
//
onChange={props.onCategoryChange}
options={unitsList}
/>
</Form.Item>
...
...
src/pages/ServiceGoods/index.jsx
View file @
184bb8b8
...
...
@@ -68,6 +68,7 @@ const ServiceGoods = options => {
const
[
specList
,
setSpecList
]
=
useState
([]);
// 规格列表
const
[
editData
,
setEditData
]
=
useState
({});
// 编辑保存数据
const
[
newCategoryList
,
setNewCategoryList
]
=
useState
({});
const
[
takeawayEditData
,
setTakeawayEditData
]
=
useState
({});
// 外卖编辑保存数据
const
[
visibleCacheEdit
,
setVisibleCacheEdit
]
=
useState
(
false
);
// 显示有缓存未保存提示
const
[
checkFormList
]
=
useState
([
...
...
@@ -130,7 +131,30 @@ const ServiceGoods = options => {
shopId
,
};
const
{
data
}
=
await
apiGetShopDetail
(
temp
);
console
.
log
(
data
,
'
=====外卖结果
'
);
const
{
name
,
storageRackIds
,
firstCategoryId
,
secondCategoryId
,
thirdCategoryId
,
commonImageList
,
id
,
}
=
data
;
const
categoryId
=
[
firstCategoryId
,
secondCategoryId
,
thirdCategoryId
];
const
editInfoMation
=
{
infoMation
:
{
name
,
productRefShopId
:
`
${
shopId
}
`
,
commonImageList
,
categoryId
,
storageRackIds
,
productType
:
5
,
},
};
setEditData
(
editInfoMation
);
setTakeawayEditData
(
data
);
setIsEdit
(
true
);
setPageLoading
(
false
);
};
const
onResetData
=
refresh
=>
{
setPageId
(
null
);
...
...
@@ -224,12 +248,11 @@ const ServiceGoods = options => {
origin
[
temp
]
=
other
;
return
origin
;
},
{});
// 外卖商品创建
// if (+productType === 5) {
// console.log('parmas', params);
// const res = await sendMerchantProductHttpRequest(params?.takeawayItem?.intactData);
// }
const
sendData
=
filterSendData
(
productType
,
params
);
if
(
productType
===
5
)
{
sendMerchantProductHttpRequest
(
sendData
);
return
false
;
}
if
(
isEdit
)
{
sendData
.
id
=
pageId
;
}
...
...
@@ -316,12 +339,6 @@ const ServiceGoods = options => {
// 默认生成一条规格数据
stockRef
.
current
.
onFinish
();
}
console
.
log
(
'
takeAway
'
,
takeAway
);
if
(
takeAway
&&
takeAway
.
spuId
)
{
productChange
({
type
:
5
});
querGetShopDetail
(
takeAway
);
setIsEdit
(
true
);
}
setPageLoading
(
false
);
})();
},
[
SourceData
]);
...
...
@@ -353,6 +370,13 @@ const ServiceGoods = options => {
},
[
specKeyList
],
);
useEffect
(()
=>
{
// 外卖类型
if
(
takeAway
&&
takeAway
.
spuId
)
{
setProductType
(
5
);
querGetShopDetail
(
takeAway
);
}
},
[]);
const
onEventBus
=
(
event
,
params
)
=>
{
if
(
event
===
'
cloneImg
'
)
{
...
...
@@ -558,7 +582,7 @@ const ServiceGoods = options => {
<
FormTakeaway
ref=
{
takeawayRef
}
takeAway=
{
takeAway
}
editData=
{
editData
.
takeaway
}
editData=
{
takeawayEditData
}
infoMation=
{
editData
.
infoMation
}
supplierIdList=
{
supplierIdList
}
onValuesChange=
{
onValuesChange
}
...
...
src/pages/ServiceGoods/utils.js
View file @
184bb8b8
...
...
@@ -111,6 +111,10 @@ const filterItems = (type, props) => {
export
const
filterSendData
=
(
type
,
params
)
=>
{
// takeawayItem 外卖商品
const
{
infoMation
,
infoImageData
,
attributeApplyList
,
takeawayItem
}
=
params
;
// 外卖商品
if
(
type
===
5
)
{
return
takeawayItem
?.
intactData
;
}
const
items
=
filterItems
(
type
,
params
);
const
commonImageList
=
type
===
4
?
[]
:
infoImageData
.
commonImageList
;
const
obj
=
{
...
...
@@ -129,10 +133,7 @@ export const filterSendData = (type, params) => {
if
(
attributeApplyList
&&
attributeApplyList
.
attributeApplyList
)
{
obj
.
attributeApplyList
=
attributeApplyList
.
attributeApplyList
;
}
// 外卖商品
if
(
type
===
5
)
{
return
takeawayItem
?.
intactData
;
}
return
obj
;
};
...
...
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