|
|
@@ -158,7 +158,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getDietIngredients, refreshDietIngredients, addDietIngredient, removeDietIngredient, generateDietRecommendation, getMealConfig } from '@/utils/api.js'
|
|
|
+import { getDietIngredients, refreshDietIngredients, addDietIngredient, removeDietIngredient, generateDietRecommendation, getMealConfig, searchDietFoods } from '@/utils/api.js'
|
|
|
import { parseDate } from '@/utils/format.js'
|
|
|
|
|
|
export default {
|
|
|
@@ -223,6 +223,7 @@ export default {
|
|
|
self.ingredientsLoading = false
|
|
|
if (res && res.code === 200 && res.data && res.data.ingredients) {
|
|
|
self.ingredients = res.data.ingredients
|
|
|
+ self.selectedIngredients = self.ingredients
|
|
|
if (self.ingredients.length === 0 && !self.uploadPromptShown) {
|
|
|
self.uploadPromptShown = true
|
|
|
uni.showModal({
|
|
|
@@ -249,6 +250,7 @@ export default {
|
|
|
self.ingredientsLoading = false
|
|
|
if (res && res.code === 200 && res.data && res.data.ingredients) {
|
|
|
self.ingredients = res.data.ingredients
|
|
|
+ self.selectedIngredients = self.ingredients
|
|
|
}
|
|
|
}).catch(function() {
|
|
|
self.ingredientsLoading = false
|
|
|
@@ -276,11 +278,13 @@ export default {
|
|
|
meal_type: 'all',
|
|
|
selected_foods: JSON.stringify(foodIds)
|
|
|
}).then(function(res) {
|
|
|
- if (res && res.id) {
|
|
|
+ if (res && res.data && res.data.id) {
|
|
|
uni.showToast({ title: '食谱生成成功', icon: 'success' })
|
|
|
setTimeout(function() {
|
|
|
self.navTo('/pages/diet/recommendation')
|
|
|
}, 1000)
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: (res && res.message) || '生成失败', icon: 'none' })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
@@ -330,11 +334,17 @@ export default {
|
|
|
this.searchResults = []
|
|
|
},
|
|
|
searchFood: function() {
|
|
|
- if (!this.searchQuery) {
|
|
|
+ var self = this
|
|
|
+ var kw = (this.searchQuery || '').trim()
|
|
|
+ if (!kw) {
|
|
|
this.searchResults = []
|
|
|
return
|
|
|
}
|
|
|
- this.searchResults = []
|
|
|
+ searchDietFoods(kw).then(function(res) {
|
|
|
+ if (res && res.code === 200 && res.data && res.data.foods) {
|
|
|
+ self.searchResults = res.data.foods
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
addFood: function(food) {
|
|
|
var self = this
|