import 'package:cpt_services/modules/services/service_order_confirm/service_order_confirm_vm.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:router/ext/auto_router_extensions.dart'; import 'package:shared/utils/log_utils.dart'; import 'package:widgets/dialog/dialog_content_wrap.dart'; import 'package:widgets/load_state_layout.dart'; import '../../../respository/services_respository.dart'; import 'chooseVisitTimeContent_state.dart'; part 'chooseVisitTimeContent_vm.g.dart'; List> visitTimeList = [ { "name": "08:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "08:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "09:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "09:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "10:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "10:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "11:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "11:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "12:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "12:30 PM", "id": 1, "price": 40.0, "type": null }, { "name": "13:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "13:30 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "14:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "14:30 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "15:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, ]; @riverpod class ChooseVisitTimeContentVm extends _$ChooseVisitTimeContentVm { late ServicesRespository serviceRespositoryInstance; ChooseVisitTimeContentState initState(){ Log.d("--------------------------initState---------------------"); List visitTimeListNew = []; visitTimeList.forEach((item) { VisitTimeContentItem newItem = VisitTimeContentItem() ..id = item['id'] ..price = item['price'] as double ..name = item['name'] ..type = null ..isDisable = false ..isChecked = false; visitTimeListNew.add(newItem); }); return ChooseVisitTimeContentState( visitTimeList: visitTimeListNew, ); } @override ChooseVisitTimeContentState build(){ // 引入数据仓库 serviceRespositoryInstance = ref.read(servicesRespositoryProvider); state = initState(); Log.d("--------------------------build---------------------"); return state; } void changeLoadingState(LoadState loadState, String? errorMsg) { state = state.copyWith( loadingState: loadState, errorMessage: errorMsg ); } initPageData(BuildContext context){ changeLoadingState(LoadState.State_Success, null); } Future getVisitTimeList(BuildContext context) async{ Log.d("--------------------------getVisitTimeList---------------------"); // 获取数据 // state.visitTimeList = serviceRespositoryInstance.getVisitTimeList(); // state = state.copyWith( // visitTimeList: state.visitTimeList, // ); changeLoadingState(LoadState.State_Loading, null); List> visitTimeList = [ { "name": "10:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "10:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "11:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "11:30 AM", "id": 1, "price": 40.0, "type": null }, { "name": "12:00 AM", "id": 1, "price": 40.0, "type": null }, { "name": "12:30 PM", "id": 1, "price": 40.0, "type": null }, { "name": "13:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "13:30 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "14:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "14:30 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, { "name": "15:00 PM", "id": 1, "price": 50.0, "type": { "text": "Extreme speed", "type": "extremeSpeed", 'code': 1, } }, ]; await Future.delayed(Duration(seconds: 1), (){}); List visitTimeListNew = []; visitTimeList.forEach((item) { VisitTimeContentItem newItem = VisitTimeContentItem() ..id = item['id'] ..price = item['price'] as double ..name = item['name'] ..type = null ..isDisable = false ..isChecked = false; visitTimeListNew.add(newItem); }); state = state.copyWith( visitTimeList: visitTimeListNew, ); Log.d("--------------------------getVisitTimeList END ${state.visitTimeList}---------------------"); changeLoadingState(LoadState.State_Success, null); return ChooseVisitTimeContentState( visitTimeList: visitTimeListNew, ); } handlerChangeNum(BuildContext context, int num, int index){ // state.visitTimeList[index].tu = num; // state = state.copyWith( // visitTimeList: state.visitTimeList, // ); } handlerTimeItemClick(BuildContext context, int index, bool isSelected){ // 修改 状态 state.visitTimeList[index].isChecked = isSelected; state = state.copyWith( visitTimeList: state.visitTimeList, ); ref.read(serviceOrderConfirmVmProvider.notifier).setConfirmOrderTotalPrice(context); } }