12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'package:cs_resources/generated/l10n.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:shared/utils/util.dart';
- import 'package:widgets/load_state_layout.dart';
- import '../book_confirm/book_confirm_page.dart';
- import 'facility_booking_state.dart';
- part 'facility_booking_view_model.g.dart';
- @riverpod
- class FacilityBookingViewModel extends _$FacilityBookingViewModel {
- @override
- FacilityBookingState build() {
- final state = FacilityBookingState(
- selectedDate: DateTime.now(),
- datas: [],
- );
- initListener(state);
- ref.onDispose(() {
- onDispose(state);
- });
- return state;
- }
- //修改选中的时间
- void changeSelectedDate(DateTime dateTime) {
- state = state.copyWith(selectedDate: dateTime);
- Log.d("当前选中的日期:$dateTime");
- fetchListByDate();
- }
- //失败的重试
- void retryRequest() {
- fetchListByDate();
- }
- /// 获取服务器数据
- Future fetchListByDate() async {
- state = state.copyWith(loadingState: LoadState.State_Loading);
- await Future.delayed(const Duration(milliseconds: 1500));
- List<String> list = ["Orange Room", "Purple Room", "Red Room"];
- if (list.isNotEmpty) {
- //加载成功
- state = state.copyWith(datas: list, loadingState: LoadState.State_Success);
- } else {
- //无数据
- state = state.copyWith(datas: [], loadingState: LoadState.State_Empty);
- }
- }
- void initListener(FacilityBookingState state) {}
- void onDispose(FacilityBookingState state) {
- Log.d("FacilityBookingViewModel - onDispose");
- }
- //去付款确认页面
- void gotoConfirmPage() {
- BookConfirmPage.startInstance();
- }
- }
|