|
|
@@ -169,11 +169,19 @@
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
- const goods = uni.getStorageSync('gm_goods');
|
|
|
+ const goods = uni.getStorageSync('gm_goods') || {};
|
|
|
if (goods.gmMerchantPackageDetails && goods.gmMerchantPackageDetails.length > 0) {
|
|
|
this.form.dishCategories.map(a => {
|
|
|
let items = goods.gmMerchantPackageDetails.filter(b => b.category == a.id);
|
|
|
- if (items.length > 0) a.items = items;
|
|
|
+ if (items.length > 0) {
|
|
|
+ a.items = items.map(item => ({
|
|
|
+ ...item,
|
|
|
+ id: item.id || dishIdCounter++,
|
|
|
+ name: item.name || '',
|
|
|
+ price: item.price === 0 ? 0 : (item.price || ''),
|
|
|
+ description: item.description || ''
|
|
|
+ }));
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
@@ -188,7 +196,7 @@
|
|
|
return !!(dish.name || dish.price || dish.description);
|
|
|
},
|
|
|
isEditedShow(e) {
|
|
|
- const goods = uni.getStorageSync('gm_goods');
|
|
|
+ const goods = uni.getStorageSync('gm_goods') || {};
|
|
|
return goods.gmMerchantPackageDetails && goods.gmMerchantPackageDetails.length > 0 && goods
|
|
|
.gmMerchantPackageDetails.some(b => b.category == e.id);;
|
|
|
},
|
|
|
@@ -269,34 +277,57 @@
|
|
|
},
|
|
|
// 上一步
|
|
|
goBack() {
|
|
|
+ this.saveDishDetails();
|
|
|
uni.navigateBack({
|
|
|
delta: 1
|
|
|
});
|
|
|
},
|
|
|
+ getDishDetails() {
|
|
|
+ const details = [];
|
|
|
+ // 遍历一级分类
|
|
|
+ this.form.dishCategories.forEach(category => {
|
|
|
+ // 检查是否有items属性且为数组
|
|
|
+ if (category.items && Array.isArray(category.items)) {
|
|
|
+ // 遍历二级菜品
|
|
|
+ category.items.forEach(item => {
|
|
|
+ // 创建新对象,只保留需要的属性
|
|
|
+ if (this.isEdited(item)) {
|
|
|
+ details.push({
|
|
|
+ category: category.id,
|
|
|
+ name: item.name,
|
|
|
+ price: item.price,
|
|
|
+ description: item.description
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return details;
|
|
|
+ },
|
|
|
+ saveDishDetails() {
|
|
|
+ const goods = uni.getStorageSync('gm_goods') || {};
|
|
|
+ goods.gmMerchantPackageDetails = this.getDishDetails();
|
|
|
+ uni.setStorageSync('gm_goods', goods);
|
|
|
+ },
|
|
|
+ backToGoodsList() {
|
|
|
+ const pages = getCurrentPages();
|
|
|
+ const listIndex = pages.findIndex(page => page.route === 'pages/groupMeal/goods/list');
|
|
|
+ if (listIndex > -1) {
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: pages.length - 1 - listIndex
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '/pages/groupMeal/goods/list'
|
|
|
+ });
|
|
|
+ },
|
|
|
// 提交审核
|
|
|
submit() {
|
|
|
this.$refs.formRef.validate().then(res => {
|
|
|
- const goods = uni.getStorageSync('gm_goods');
|
|
|
+ const goods = uni.getStorageSync('gm_goods') || {};
|
|
|
const activeCategories = this.form.dishCategories.filter(c => c.items.some(this.isEdited));
|
|
|
- const details = [];
|
|
|
- // 遍历一级分类
|
|
|
- activeCategories.forEach(category => {
|
|
|
- // 检查是否有items属性且为数组
|
|
|
- if (category.items && Array.isArray(category.items)) {
|
|
|
- // 遍历二级菜品
|
|
|
- category.items.forEach(item => {
|
|
|
- // 创建新对象,只保留需要的属性
|
|
|
- if (this.isEdited(item)) {
|
|
|
- details.push({
|
|
|
- category: category.id,
|
|
|
- name: item.name,
|
|
|
- price: item.price,
|
|
|
- description: item.description
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+ const details = this.getDishDetails();
|
|
|
let params = {
|
|
|
...goods,
|
|
|
gmMerchantPackageDetails: [...details]
|
|
|
@@ -309,9 +340,7 @@
|
|
|
// 清除
|
|
|
uni.removeStorageSync('gm_goods');
|
|
|
// 返回列表
|
|
|
- uni.navigateBack({
|
|
|
- delta: 3
|
|
|
- });
|
|
|
+ this.backToGoodsList();
|
|
|
}
|
|
|
});
|
|
|
}).catch(errors => {
|
|
|
@@ -436,4 +465,4 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|