feat:更新美食记录表单
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/models/common_model.dart';
|
||||
import 'package:flutter_common/utils/toast_util.dart';
|
||||
import 'package:food_hub_app/apis/moment.dart';
|
||||
import 'package:food_hub_app/apis/recipe.dart';
|
||||
import 'package:food_hub_app/apis/stats.dart';
|
||||
@@ -7,8 +9,10 @@ import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/models/stats.dart';
|
||||
import 'package:food_hub_app/utils/date_util.dart';
|
||||
import 'package:food_hub_app/utils/index.dart';
|
||||
import 'package:food_hub_app/views/record.dart';
|
||||
|
||||
class FoodProvider with ChangeNotifier {
|
||||
late RecordTab currentRecordTab = RecordTab.recipe;
|
||||
late FoodRecord recordFormItem;
|
||||
late Moment momentFormItem;
|
||||
|
||||
@@ -20,6 +24,7 @@ class FoodProvider with ChangeNotifier {
|
||||
late List<String> categoryList = [];
|
||||
late List<RecipeSummary> recipeSummaryList = [];
|
||||
|
||||
int selectYear = DateTime.now().year;
|
||||
DateTime selectedDay = DateTime.now();
|
||||
DateTime focusedDay = DateTime.now();
|
||||
|
||||
@@ -61,6 +66,18 @@ class FoodProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> onRecordTabChange() async {
|
||||
switch (currentRecordTab) {
|
||||
case RecordTab.recipe:
|
||||
await refreshRecipeList();
|
||||
break;
|
||||
case RecordTab.calendar:
|
||||
case RecordTab.timeline:
|
||||
await refreshRecordList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> queryCategoryList() async {
|
||||
try {
|
||||
error = null;
|
||||
@@ -98,16 +115,31 @@ class FoodProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshRecordList(String? startDate, String? endDate) async {
|
||||
Future<void> refreshRecordList() async {
|
||||
if (isLoading) return;
|
||||
|
||||
if (currentRecordTab == RecordTab.recipe) return;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
startDate ??= getFirstDayOfMonth(focusedDay);
|
||||
endDate ??= getLastDayOfMonth(focusedDay);
|
||||
late String startDate;
|
||||
late String endDate;
|
||||
|
||||
switch (currentRecordTab) {
|
||||
case RecordTab.calendar:
|
||||
startDate = getFirstDayOfMonth(focusedDay);
|
||||
endDate = getLastDayOfMonth(focusedDay);
|
||||
break;
|
||||
case RecordTab.timeline:
|
||||
startDate = '$selectYear-01-01';
|
||||
endDate = '$selectYear-12-31';
|
||||
break;
|
||||
case RecordTab.recipe:
|
||||
break;
|
||||
}
|
||||
|
||||
final result = await queryRecordApi(startDate, endDate);
|
||||
|
||||
@@ -129,6 +161,30 @@ class FoodProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleRecord() async {
|
||||
if (isLoading) return;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
if (isEditing) {
|
||||
await updateRecordApi(recordFormItem.id!, recordFormItem);
|
||||
ToastUtil.success('更新记录成功');
|
||||
} else {
|
||||
await addRecordApi(recordFormItem);
|
||||
ToastUtil.success('上传记录成功');
|
||||
}
|
||||
} catch (e) {
|
||||
error = '处理数据失败: $e';
|
||||
debugPrint('处理数据失败: $e');
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void refreshSelectRecord() {
|
||||
selectRecordList =
|
||||
recordList
|
||||
@@ -136,7 +192,7 @@ class FoodProvider with ChangeNotifier {
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> refreshBlogStats() async {
|
||||
Future<void> refreshFoodStats() async {
|
||||
if (isLoading) return;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user