facility_booking_view_model.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:cs_resources/generated/l10n.dart';
  2. import 'package:riverpod_annotation/riverpod_annotation.dart';
  3. import 'package:shared/utils/log_utils.dart';
  4. import 'package:shared/utils/util.dart';
  5. import 'package:widgets/load_state_layout.dart';
  6. import '../book_confirm/book_confirm_page.dart';
  7. import 'facility_booking_state.dart';
  8. part 'facility_booking_view_model.g.dart';
  9. @riverpod
  10. class FacilityBookingViewModel extends _$FacilityBookingViewModel {
  11. @override
  12. FacilityBookingState build() {
  13. final state = FacilityBookingState(
  14. selectedDate: DateTime.now(),
  15. datas: [],
  16. );
  17. initListener(state);
  18. ref.onDispose(() {
  19. onDispose(state);
  20. });
  21. return state;
  22. }
  23. //修改选中的时间
  24. void changeSelectedDate(DateTime dateTime) {
  25. state = state.copyWith(selectedDate: dateTime);
  26. Log.d("当前选中的日期:$dateTime");
  27. fetchListByDate();
  28. }
  29. //失败的重试
  30. void retryRequest() {
  31. fetchListByDate();
  32. }
  33. /// 获取服务器数据
  34. Future fetchListByDate() async {
  35. state = state.copyWith(loadingState: LoadState.State_Loading);
  36. await Future.delayed(const Duration(milliseconds: 1500));
  37. List<String> list = ["Orange Room", "Purple Room", "Red Room"];
  38. if (list.isNotEmpty) {
  39. //加载成功
  40. state = state.copyWith(datas: list, loadingState: LoadState.State_Success);
  41. } else {
  42. //无数据
  43. state = state.copyWith(datas: [], loadingState: LoadState.State_Empty);
  44. }
  45. }
  46. void initListener(FacilityBookingState state) {}
  47. void onDispose(FacilityBookingState state) {
  48. Log.d("FacilityBookingViewModel - onDispose");
  49. }
  50. //去付款确认页面
  51. void gotoConfirmPage() {
  52. BookConfirmPage.startInstance();
  53. }
  54. }