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
e64c6bba
Commit
e64c6bba
authored
Mar 30, 2023
by
陈万宝
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/20230315_take_out_goods' into feature/20230327_public_takeaway
parents
6fec3ca3
5470e60a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
280 additions
and
221 deletions
+280
-221
index.jsx
src/pages/GoodsManage/index.jsx
+1
-1
common.less
src/pages/ServiceGoods/common.less
+9
-0
FormInformationBasic.jsx
src/pages/ServiceGoods/components/FormInformationBasic.jsx
+20
-12
FormTakeaway.jsx
src/pages/ServiceGoods/components/FormTakeaway.jsx
+181
-193
index.jsx
src/pages/ServiceGoods/index.jsx
+59
-14
utils.js
src/pages/ServiceGoods/utils.js
+10
-1
No files found.
src/pages/GoodsManage/index.jsx
View file @
e64c6bba
...
...
@@ -78,7 +78,7 @@ class goodsManage extends Component {
componentDidMount
()
{
this
.
props
.
goodsManage
.
tableData
=
{};
this
.
categoryList
();
this
.
categoryList
(
this
.
state
.
productType
);
this
.
categoryListByType
(
this
.
state
.
productType
);
this
.
getVirtualCategory
();
this
.
specList
();
...
...
src/pages/ServiceGoods/common.less
View file @
e64c6bba
...
...
@@ -245,6 +245,15 @@
.specsBetween {
display: flex;
flex-flow: row nowrap;
:global {
.ant-form-item-label{
overflow:inherit;
}
.ant-col-sm-3{
max-width: fit-content;
}
}
}
.specRepertory {
background-color: #319bfe;
...
...
src/pages/ServiceGoods/components/FormInformationBasic.jsx
View file @
e64c6bba
...
...
@@ -12,7 +12,7 @@ import { ServiceContext } from '../context';
import
{
debounce
}
from
'
@/utils/utils
'
;
import
AddMenusModal
from
'
./AddMenusModal
'
;
import
UploadImage
from
'
./UploadImage
'
;
import
{
apiShopIds
,
apiQueryShopList
}
from
'
../service
'
;
import
{
apiShopIds
,
apiQueryShopList
,
getByProductType
}
from
'
../service
'
;
const
CreateSelectOption
=
optionList
=>
optionList
.
map
(
brandItem
=>
(
...
...
@@ -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
);
...
...
@@ -35,6 +34,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
brandList
,
afterAddressList
,
specListData
,
shopGetByProductType
,
}
=
props
;
const
[
form
]
=
Form
.
useForm
();
const
[
noreBrandList
,
setNoreBrandList
]
=
useState
([]);
...
...
@@ -43,6 +43,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
{
...
...
@@ -66,6 +67,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
return
null
;
}
};
// 自定义加入菜单
const
showModal
=
()
=>
{
childAddMenusModalRef
.
current
.
setOpen
(
true
);
...
...
@@ -100,6 +102,7 @@ const FormInformationBasic = forwardRef((props, ref) => {
};
const
getFormValues
=
debounce
(()
=>
{
const
values
=
form
.
getFieldsValue
();
console
.
log
(
'
infoMation
'
,
values
);
props
.
onValuesChange
({
infoMation
:
values
});
},
400
);
// 查询shopIds
...
...
@@ -118,13 +121,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
===
'
虚拟商品
'
);
...
...
@@ -133,15 +140,15 @@ const FormInformationBasic = forwardRef((props, ref) => {
useEffect
(()
=>
{
if
(
!
editData
)
return
;
if
(
editData
.
productType
===
5
&&
editData
.
name
)
{
shopGetByProductType
(
5
);
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 +159,8 @@ const FormInformationBasic = forwardRef((props, ref) => {
name
:
''
,
categoryId
:
[],
description
:
''
,
productRefShopId
:
[],
storageRackIds
:
[],
}
}
scrollToFirstError
onValuesChange=
{
getFormValues
}
...
...
@@ -171,12 +180,12 @@ const FormInformationBasic = forwardRef((props, ref) => {
{
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 +204,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 +214,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 @
e64c6bba
...
...
@@ -36,7 +36,7 @@ import AddSellTimeModal from './AddSellTimeModal';
import
styles
from
'
../common.less
'
;
import
AddRepertoryModal
from
'
./AddRepertoryModal
'
;
import
AddMultiSpecModal
from
'
./AddMultiSpecModal
'
;
import
{
apiTagList
,
apiUnits
,
apiGetShopDetail
}
from
'
../service
'
;
import
{
apiTagList
,
apiUnits
}
from
'
../service
'
;
import
{
localAutoSaveKey
}
from
'
../utils
'
;
import
localStorage
from
'
@/utils/localStorage
'
;
...
...
@@ -47,37 +47,37 @@ const createInitValues = () => ({
saleTimeType
:
0
,
// 售卖时间
singleDelivery
:
0
,
// 单点不送
list
:
1
,
// 列出商品
label
:
''
,
});
const
format
=
'
HH:mm
'
;
const
{
RangePicker
}
=
DatePicker
;
const
TakeawayGoodsInfo
=
forwardRef
((
props
,
ref
)
=>
{
const
{
editData
,
infoMation
}
=
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
);
const
[
saleDates
,
setSaleDates
]
=
useState
({
saleDates
:
[],
saleTimes
:
[],
// saleTimes: [[moment('22-02', 'HH:mm'), moment('23-02', 'HH:mm')]],
});
// 可售日期
const
[
timeType
,
setTimeType
]
=
useState
(
0
);
const
[
repertoryType
,
setRepertoryType
]
=
useState
(
'
1
'
);
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
({});
const
[
repertoryState
,
setRepertoryState
]
=
useState
(
''
);
const
[
repertoryModel
,
setRepertoryModel
]
=
useState
({});
const
[
tempMultiSpu
,
setTempMultiSpu
]
=
useState
([]);
const
[
tempWeight
,
setTempWeight
]
=
useState
([]);
const
[
tempSpecs
,
setTempSpecs
]
=
useState
([]);
const
initialDealValue
=
[
{
specGroupName
:
''
,
...
...
@@ -104,10 +104,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const
takeawayCalc
=
takeawayData
=>
{
// 商品基本信息编辑商品名称
const
{
infoMation
:
name
,
infoMation
,
takeawayItem
}
=
takeawayData
;
console
.
log
(
'
i========
'
,
infoMation
,
takeawayItem
,
repertoryType
);
// weight 份量 specs规格 生成sku规则 weight * specs
const
{
specs
=
[]
,
weight
=
[]
,
specs
=
tempSpecs
,
weight
=
tempWeight
,
description
,
detailImageList
,
list
,
...
...
@@ -116,17 +117,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
maxStock
=
0
,
saleTimes
=
[],
label
,
unit
=
[]
,
unit
,
quantity
,
productStock
=
0
,
salePrice
,
singleDelivery
,
saleTimeType
,
autoStock
=
0
,
skuList
,
id
,
categoryId
,
}
=
takeawayItem
;
console
.
log
(
'
skuList====
'
,
infoMation
,
takeawayItem
,
skuList
);
const
singularSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 单规格
const
multiSpecList
=
[{
specGroupName
:
'
份量
'
,
generateSku
:
1
,
specs
:
[]
}];
// 多规格
// const multiSpu = customer.isEdit ? skuList:[]; // 多库存spu、
const
multiSpu
=
[];
// 多库存spu、
let
singularSpu
=
[];
// 单库存spu
const
saleTimesTemp
=
[];
let
initIndex
=
0
;
...
...
@@ -141,6 +148,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice
:
salePrice
||
0
,
productStock
,
list
:
1
,
id
:
skuList
?.
length
===
1
?
skuList
[
0
].
id
:
''
,
// 单规格默认取第一个
serviceItem
:
{
description
,
// 商品描述
maxStock
,
// 最大库存
...
...
@@ -162,7 +170,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
salePrice
,
maxStock
,
quantity
,
unit
:
(
unit
&&
unit
.
splice
(
unit
.
length
-
1
)[
0
])
||
''
,
unit
:
(
Array
.
isArray
(
unit
)
&&
unit
?.
length
&&
unit
?.
splice
(
unit
?.
length
-
1
)[
0
])
||
unit
,
productStock
,
specGroupName
:
'
份量
'
,
};
...
...
@@ -172,13 +180,13 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
}
// 多规格
if
(
+
repertoryType
===
2
)
{
if
(
name
)
{
console
.
log
(
'
weight
'
,
weight
);
if
(
name
||
editData
.
name
)
{
if
(
weight
.
length
)
{
weight
.
forEach
((
item
,
weightIndex
)
=>
{
console
.
log
(
'
eee====
'
,
item
);
if
(
item
?.
unit
&&
item
.
unit
.
length
)
{
item
.
unit
=
item
.
unit
.
slice
(
item
.
unit
.
length
-
1
).
toString
();
if
(
item
?.
unit
&&
item
?.
unit
.
length
)
{
item
.
unit
=
item
?.
unit
&&
(
Array
.
isArray
(
item
?.
unit
)
?
item
.
unit
.
slice
(
item
.
unit
.
length
-
1
)[
0
]
:
item
.
unit
);
}
if
(
item
&&
!
item
.
specGroupName
)
{
item
.
specGroupName
=
'
份量
'
;
...
...
@@ -244,27 +252,24 @@ 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) => {
if (item.unique === itm.unique) {
item.serviceItem = objectComparison(item.serviceItem, itm);
item.id = itm.id;
}
});
});
}
// debugger
console.log('multiSpu===2222', multiSpu);
console.log(multiSpu, tempMultiSpu, 'multiSpumultiSpu');
setMultiSpu(multiSpu);
}
// debugger
// +repertoryType === 1 单规格 2多规格
const intactDataTemp = {
...takeawayItem,
id,
type: 5, // 外卖类型
...infoMation,
label: label && label.toString(),
...
...
@@ -274,12 +279,16 @@ 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() ||
// (Array.isArray(categoryId) && categoryId?.slice(categoryId?.length - 1)?.toString()),
};
console.log('intactData======>', intactData);
setIntactData(intactDataTemp);
console.log('intactData======>', form.getFieldsValue(), intactDataTemp);
return intactData;
};
// 过滤对象
...
...
@@ -287,24 +296,21 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
let {
serviceItem: { maxStock, autoStock, productStock },
} = itm;
let params = { maxStock, autoStock, productStock };
let params = { maxStock, autoStock, productStock
: productStock || itm.productStock
};
let temp = { ...item, ...params };
return temp;
};
const onChange = () => {};
const onDealFinish = values => {
console.log('Received values of form:', values);
};
const getFormValues = debounce(() => {
const values = form.getFieldsValue();
console.log('values========', values);
props.onValuesChange({ takeawayItem: values });
const takeawayData = localStorage.get(localAutoSaveKey);
console.log('takeawayData', takeawayData);
console.log('values', values);
props.onValuesChange({ takeawayItem: JSON.parse(JSON.stringify(values)) });
const takeawayData = customer.isEdit
? { takeawayItem: Object.assign({}, editData, values) }
: localStorage.get(localAutoSaveKey) || {};
setTakeawayData(takeawayData);
takeawayCalc(takeawayData);
}, 400);
// 设置库存
const modifiedInventory = (type, idx, values) => {
const { productStock, maxStock, autoStock } = values;
...
...
@@ -321,41 +327,23 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu);
setMultiSpu(temp);
console.log('33333========>', multiSpu, tempMultiSpu);
// if (intactData?.items.length) {
// intactData.items[+idx].serviceItem.productStock = productStock;
// intactData.items[+idx].serviceItem.autoStock = autoStock;
// intactData.items[+idx].serviceItem.maxStock = maxStock;
// console.log('index===2222', +idx, intactData);
// const temp = { ...intactData };
// setIntactData(temp);
// }
}
if (type === 'all') {
if (intactData?.items.length) {
intactData?.items.forEach(item => {
multiSpu.map(item => {
item.serviceItem.productStock = productStock;
item.serviceItem.autoStock = autoStock;
item.serviceItem.maxStock = maxStock;
return item;
});
const temp = { ...intactData };
setIntactData(temp);
}
let temp = JSON.parse(JSON.stringify(multiSpu));
tempMultiSpu.push(...temp);
setTempMultiSpu(tempMultiSpu);
setMultiSpu(multiSpu);
}
console.log('=========', multiSpu, tempMultiSpu);
getFormValues();
return false;
};
const querGetShopDetail = async () => {
let params = {
id: '638899799727110',
shopId: 15,
};
const result = await apiGetShopDetail(params);
console.log('result', result);
};
const fileterBrandOptions = (input, options) => options.children.includes(input);
const filterCategoryOptions = (inputValue, path) =>
path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
...
...
@@ -377,13 +365,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
detailImageList: imgList,
});
};
const radioChangeEvent = key => {
const value = form.getFieldValue(key);
setInitValue({
...initValue,
[key]: value,
});
};
// 自定义菜单下拉
const dropdownRender = menus => (
<div>
...
...
@@ -440,7 +421,6 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
};
// 自动补全
const onChangeAutoStock = e => {
console.log('e=======', e);
form.setFieldsValue({
autoStock: e ? 1 : 0,
});
...
...
@@ -472,17 +452,91 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
const res = await apiUnits();
setUnitsList(res.data || []);
}
querGetShopDetail();
setTempMultiSpu([])
setTempMultiSpu([])
;
return false;
};
useEffect(() => {
if (customer.isEdit || customer.isUseCache) {
if (!editData) return;
let { label, firstCategoryId, secondCategoryId, thirdCategoryId, id } = editData;
editData.label = label.split(',');
if (editData?.skuList.length) {
editData.minPurchaseNum = editData?.skuList[0]?.serviceItem.minPurchaseNum;
// 单规格
if (editData?.skuList.length === 1) {
let {
productStock,
shopId,
specs,
serviceItem: { maxStock, saleTimeType, saleDates, saleTimes, id },
} = 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];
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;
editData.skuId = id;
form.setFieldsValue(editData);
setInitValue({ ...editData });
setTimeType(saleTimeType);
} else {
// 多规格
setRepertoryType(`
2
`);
let {
serviceItem: { saleTimeType, saleDates, saleTimes },
} = editData?.skuList[0];
let specList = editData?.specList;
let weight = specList.filter(item => item.specGroupName === '份量');
let specs = specList.filter(item => item.specGroupName !== '份量');
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 });
console.log('editData?.skuList', editData?.skuList);
const tempMultiSpu = editData?.skuList.map(item => {
if (item) {
let weightIdx = item.specs.findIndex(itm => itm.specGroupName === '份量');
console.log('weightIdx', weightIdx);
let specsIdx = item.specs.findIndex(itm => itm.specGroupName !== '份量');
console.log('specsIdx', specsIdx);
item.unique = `
$
{
item
.
specs
[
weightIdx
]?.
specName
}
-
$
{
item
.
specs
[
specsIdx
]?.
specGroupName
}
-
$
{
item
.
specs
[
specsIdx
]?.
specName
}
`;
}
return item;
});
setTempMultiSpu(tempMultiSpu || []);
}
form.setFieldsValue({ productRefShopId: editData.shopId });
onCardSuccessImageList(editData?.detailImageList);
getFormValues();
// setInitValue({ ...editData });
}
}, [customer.isEdit, customer.isUseCache, editData]);
}
}, [customer.isEdit, editData]);
useEffect(() => {
setIntactData(intactData);
}, [intactData]);
...
...
@@ -555,32 +609,14 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
<Form.Item label="售卖时段">
<Form.List
name="saleTimes"
initialValue={[[]]}
// rules={[
// {
// validator: async (_, times) => {
// if (!times || times.length < 2) {
// return Promise.reject(new Error('At least 2 passengers'));
// }
// },
// },
// ]}
>
<Form.List name="saleTimes" initialValue={[[]]}>
{(fields, { add, remove }) => (
<>
{fields.map((field, index) => (
<Form.Item
// {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
required={false}
key={field.key}
className={styles.deal}
>
<Form.Item required={false} key={field.key} className={styles.deal}>
<Form.Item
className={styles.deal}
{...field}
// validateTrigger={['onChange', 'onBlur']}
rules={[
{
required: true,
...
...
@@ -635,11 +671,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
</>
)}
<Form.Item
name="label"
label="商品标签"
// rules={[{ type: 'array', required: true, message: '请输入售卖时间!' }]}
>
<Form.Item name="label" label="商品标签">
<Select
mode="multiple"
allowClear
...
...
@@ -665,16 +697,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Radio.Group>
</Form.Item>
<Title title="规格信息" />
{/* <Form.Item label="限购" name="limitPurchase" valuePropName="checked">
<Checkbox onChange={() => radioChangeEvent('limitPurchase')}>
<b style={{ marginLeft: 10 }}>启用限购</b>
<span style={{ marginLeft: 10 }} className="ant-form-text">
限制每人可购买数量
</span>
</Checkbox>
</Form.Item> */}
{!customer.isEdit && (
<Form.Item label="库存" name="stock">
<Radio.Group
options={ENUM_REPERTORY}
...
...
@@ -684,7 +707,8 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
optionType="button"
/>
</Form.Item>
)}
{/* 单规格 */}
{repertoryType === '1' && (
<>
<Form.Item label="份量" className={styles.required}>
...
...
@@ -699,7 +723,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',
...
...
@@ -710,7 +735,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>
...
...
@@ -767,7 +792,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</Form.Item>
<div className={styles.rowWarp}>
{singularSpu.length > 0 &&
takeawayData?.infoMation?.name
&&
(takeawayData?.infoMation?.name || takeawayData.takeawayItem.name)
&&
singularSpu.map((item, index) => (
<div className={styles.specsBetween}>
<Form.Item label={calcLabelName(intactData, item, 'singular')}>
...
...
@@ -790,41 +815,11 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div>
</>
)}
{/* 多规格 */}
{repertoryType === '2' && (
<>
<Form.Item>
<div>份量(如大小/小份、微辣/特辣等)</div>
{/* <Form.List name="deal">
{(dealFields, { add, remove }) => (
<>
{dealFields.map((field, index) => (
<Form.Item key={field.key} className={styles.conBg}>
<Form.Item
{...field}
validateTrigger={['onChange', 'onBlur']}
name={[field.name, 'specGroupName']}
rules={[
{
required: true,
whitespace: true,
message: '请输入名称例如(份量)',
},
]}
noStyle
>
<Input
placeholder="请输入名称"
style={{
width: '60%',
}}
/>
</Form.Item>
{dealFields.length > 1 ? (
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(field.name)}
/>
) : null} */}
<Form.List name="weight" initialValue={[{}]}>
{(weightFields, { add: weightAdd, remove: weightRemove }) => (
<>
...
...
@@ -861,7 +856,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
name={[weightField.name, 'unit']}
rules={[
{
type: 'array',
//
type: 'array',
required: true,
message: '请选择单位',
},
...
...
@@ -876,7 +871,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
value: 'name',
children: 'children',
}}
onChange={props.onCategoryChange}
//
onChange={props.onCategoryChange}
options={unitsList}
/>
</Form.Item>
...
...
@@ -922,38 +917,31 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</>
)}
</Form.List>
{/* </Form.Item>
))} */}
{/* <Form.Item>
<Button
type="primary"
onClick={() => add()}
style={{
width: '400px',
}}
icon={<PlusOutlined />}
>
添加份量
</Button>
</Form.Item> */}
{/* </>
)}
</Form.List> */}
</Form.Item>
{takeawayData?.takeawayItem?.weight?.length > 0 && (
{/* takeawayData?.takeawayItem?.weight?.length > 0 && */}
{
<>
<Form.Item>
<div>添加规格(如加料、甜度、辣度等)</div>
<Form.List name="specs">
<Form.List
name="specs"
initialValue={
[
// {
// specGroupName: '',
// specs: [],
// },
]
}
>
{(specsFields, { add, remove }) => (
<>
{specsFields.map((
f
ield, index) => (
<Form.Item key={
f
ield.key} className={styles.conBg}>
{specsFields.map((
specsF
ield, index) => (
<Form.Item key={
specsF
ield.key} className={styles.conBg}>
<Form.Item
{...
f
ield}
{...
specsF
ield}
validateTrigger={['onChange', 'onBlur']}
name={[
f
ield.name, 'specGroupName']}
name={[
specsF
ield.name, 'specGroupName']}
rules={[
{
required: true,
...
...
@@ -965,15 +953,15 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
>
<Input placeholder="规格名称" className={styles.nameWidth} />
</Form.Item>
{
specsFields.length > 1 ? (
{
/* {specsFields.length > 1 ? ( */}
<MinusCircleOutlined
className="dynamic-delete-button"
onClick={() => remove(f
ield.name)}
onClick={() => remove(specsF
ield.name)}
/>
) : null
}
{/* ) : null} */
}
<Form.List
{...
f
ield}
name={[
f
ield.name, 'specs']}
{...
specsF
ield}
name={[
specsF
ield.name, 'specs']}
initialValue={[
{
specName: '',
...
...
@@ -1097,7 +1085,7 @@ const TakeawayGoodsInfo = forwardRef((props, ref) => {
</div>
</Form.Item>
</>
)
}
}
</>
)}
</Form>
...
...
src/pages/ServiceGoods/index.jsx
View file @
e64c6bba
...
...
@@ -22,7 +22,7 @@ import {
getByProductType
,
apiCreateDraft
,
apiEditDraft
,
api
AddTakeawayProducts
,
api
GetShopDetail
,
}
from
'
./service
'
;
import
{
isUrl
,
filterSendData
,
clearCurrent
,
onAutoSaveValue
,
localAutoSaveKey
}
from
'
./utils
'
;
import
{
ServiceContext
}
from
'
./context
'
;
...
...
@@ -35,12 +35,18 @@ import styles from './common.less';
* @returns ReactDOM
*/
const
ServiceGoods
=
options
=>
{
const
{
SourceData
,
categoryList
,
virtualCategoryList
,
specListData
,
permissions
}
=
options
;
const
{
SourceData
,
categoryList
,
virtualCategoryList
,
specListData
,
permissions
,
takeAway
,
}
=
options
;
const
canAddService
=
permissions
[
GOOD_MANAGE
.
ADD_SERVICE_GOODS
];
const
canAddNormal
=
permissions
[
GOOD_MANAGE
.
ADD_NORMAL_GOODS
];
// const canTakeawayService = permissions[GOOD_MANAGE.ADD_TAKEAWAY_GOODS];
// const canTakeawayService = true
const
basicRef
=
useRef
(
null
);
const
stockRef
=
useRef
(
null
);
const
settingRef
=
useRef
(
null
);
...
...
@@ -62,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
([
...
...
@@ -111,10 +118,44 @@ const ServiceGoods = options => {
},
!
0
,
);
if
(
stockRef
.
current
)
{
stockRef
.
current
.
onFinish
();
}
},
1000
);
};
// 查询外卖商品详情
const
querGetShopDetail
=
async
params
=>
{
const
{
spuId
,
shopId
}
=
params
;
const
temp
=
{
id
:
spuId
,
shopId
,
};
const
{
data
}
=
await
apiGetShopDetail
(
temp
);
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
);
setIsEdit
(
false
);
...
...
@@ -195,7 +236,6 @@ const ServiceGoods = options => {
});
}
};
// 保存商品
const
submitEvent
=
async
()
=>
{
const
checkPromiseList
=
clearCurrent
(
checkFormList
).
map
(({
current
})
=>
current
.
onCheck
());
...
...
@@ -208,14 +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
;
}
const
sendData
=
filterSendData
(
productType
,
params
);
if
(
isEdit
)
{
sendData
.
id
=
pageId
;
}
...
...
@@ -333,6 +370,13 @@ const ServiceGoods = options => {
},
[
specKeyList
],
);
useEffect
(()
=>
{
// 外卖类型
if
(
takeAway
&&
takeAway
.
spuId
)
{
setProductType
(
5
);
querGetShopDetail
(
takeAway
);
}
},
[]);
const
onEventBus
=
(
event
,
params
)
=>
{
if
(
event
===
'
cloneImg
'
)
{
...
...
@@ -411,7 +455,6 @@ const ServiceGoods = options => {
},
});
};
console
.
log
(
'
productType
'
,
productType
);
const
providerValue
=
{
pageId
,
isEdit
,
...
...
@@ -470,6 +513,7 @@ const ServiceGoods = options => {
ref=
{
basicRef
}
editData=
{
editData
.
infoMation
}
newCategoryList=
{
newCategoryList
}
shopGetByProductType=
{
shopGetByProductType
}
categoryList=
{
categoryList
}
virtualCategoryList=
{
virtualCategoryList
}
brandList=
{
brandList
}
...
...
@@ -538,7 +582,8 @@ const ServiceGoods = options => {
<>
<
FormTakeaway
ref=
{
takeawayRef
}
editData=
{
editData
.
takeawayItem
}
takeAway=
{
takeAway
}
editData=
{
takeawayEditData
}
infoMation=
{
editData
.
infoMation
}
supplierIdList=
{
supplierIdList
}
onValuesChange=
{
onValuesChange
}
...
...
src/pages/ServiceGoods/utils.js
View file @
e64c6bba
...
...
@@ -109,7 +109,15 @@ const filterItems = (type, props) => {
};
export
const
filterSendData
=
(
type
,
params
)
=>
{
const
{
infoMation
,
infoImageData
,
attributeApplyList
}
=
params
;
// takeawayItem 外卖商品
const
{
infoMation
,
infoImageData
,
attributeApplyList
,
takeawayItem
}
=
params
;
console
.
log
(
'
infoMation
'
,
infoMation
,
takeawayItem
);
const
temp
=
Object
.
assign
({},
takeawayItem
?.
intactData
,
infoMation
)
temp
.
categoryId
=
(
Array
.
isArray
(
temp
.
categoryId
)
&&
temp
.
categoryId
?.
slice
(
temp
.
categoryId
?.
length
-
1
)?.
toString
())
// 外卖商品
if
(
type
===
5
)
{
return
temp
;
}
const
items
=
filterItems
(
type
,
params
);
const
commonImageList
=
type
===
4
?
[]
:
infoImageData
.
commonImageList
;
const
obj
=
{
...
...
@@ -128,6 +136,7 @@ export const filterSendData = (type, params) => {
if
(
attributeApplyList
&&
attributeApplyList
.
attributeApplyList
)
{
obj
.
attributeApplyList
=
attributeApplyList
.
attributeApplyList
;
}
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