chooseVisitTimeTitle_vm.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:cpt_services/components/chooseVisitTimeContent_vm.dart';
  2. import 'package:cpt_services/modules/services/service_order_confirm/service_order_confirm_vm.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:riverpod_annotation/riverpod_annotation.dart';
  6. import 'package:router/ext/auto_router_extensions.dart';
  7. import 'package:shared/utils/log_utils.dart';
  8. import 'package:widgets/dialog/dialog_content_wrap.dart';
  9. import '../../../respository/services_respository.dart';
  10. import 'chooseVisitTimeTitle_state.dart';
  11. part 'chooseVisitTimeTitle_vm.g.dart';
  12. List<Map<String, dynamic>> dayInfoList = [
  13. {
  14. "id": 1,
  15. "day": 'Tody',
  16. "date": '2022-01-01',
  17. "isSelected": true,
  18. "isIntrady": true,
  19. },
  20. {
  21. "id": 2,
  22. "day": 'Tommorow',
  23. "date": '2022-01-01',
  24. "isSelected": false,
  25. "isIntrady": false,
  26. },
  27. {
  28. "id": 3,
  29. "day": '周三',
  30. "date": '2022-01-01',
  31. "isSelected": false,
  32. "isIntrady": false,
  33. },
  34. {
  35. "id": 4,
  36. "day": '周四',
  37. "date": '2022-01-01',
  38. "isSelected": false,
  39. "isIntrady": false,
  40. },
  41. {
  42. "id": 5,
  43. "day": '周五',
  44. "date": '2022-01-01',
  45. "isSelected": false,
  46. "isIntrady": false,
  47. },
  48. {
  49. "id": 6,
  50. "day": '周六',
  51. "date": '2022-01-01',
  52. "isSelected": false,
  53. "isIntrady": false,
  54. },
  55. {
  56. "id": 7,
  57. "day": '周天',
  58. "date": '2022-01-01',
  59. "isSelected": false,
  60. "isIntrady": false,
  61. },
  62. ];
  63. ChooseVisitTimeTitleState initState(){
  64. Log.d("--------------------------initState---------------------");
  65. List<DayInfoItem> dayInfoListNew = [];
  66. dayInfoList.forEach((item) {
  67. DayInfoItem newItem = DayInfoItem()
  68. ..id = item['id']
  69. ..day = item['day']
  70. ..date = item['date']
  71. ..isSelected = item['isSelected']
  72. ..isIntrady = item['isIntrady'];
  73. dayInfoListNew.add(newItem);
  74. });
  75. return ChooseVisitTimeTitleState(
  76. dayInfoList: dayInfoListNew,
  77. );
  78. }
  79. @riverpod
  80. class ChooseVisitTimeTitleVm extends _$ChooseVisitTimeTitleVm {
  81. late ServicesRespository serviceRespositoryInstance;
  82. @override
  83. ChooseVisitTimeTitleState build(){
  84. // 引入数据仓库
  85. serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
  86. ChooseVisitTimeTitleState state = initState();
  87. Log.d("--------------------------build---------------------");
  88. return state;
  89. }
  90. handlerChangeNum(BuildContext context, int num, int index){
  91. // state.dayInfoList[index].tu = num;
  92. // state = state.copyWith(
  93. // dayInfoList: state.dayInfoList,
  94. // );
  95. }
  96. // 点击某一天
  97. handlerClicKSomeDay(BuildContext context, DayInfoItem dayInfoItem, int index){
  98. state.currentSelectIndex = index;
  99. // 循环 state.dayInfoList 需要索引值为index 的 设置isSelected 为true 其他设置为false
  100. state.dayInfoList?.asMap().forEach((idx, value) {
  101. if(idx == index){
  102. value.isSelected = true;
  103. }else{
  104. value.isSelected = false;
  105. }
  106. });
  107. state = state.copyWith(
  108. currentSelectIndex: state.currentSelectIndex,
  109. dayInfoList: state.dayInfoList,
  110. );
  111. // 触发 chooseVisitTimeContent 的刷新
  112. final chooseVisitTimeContentVm = ref.read(chooseVisitTimeContentVmProvider.notifier);
  113. chooseVisitTimeContentVm?.getVisitTimeList(context);
  114. }
  115. // 点击某一时间段
  116. handlerTimeItemClick(BuildContext context, int index, bool isSelected){
  117. // 修改 状态
  118. // state.dayInfoList[index].isChecked = isSelected;
  119. // state = state.copyWith(
  120. // dayInfoList: state.dayInfoList,
  121. // );
  122. //
  123. // ref.read(serviceOrderConfirmVmProvider.notifier).setConfirmOrderTotalPrice(context);
  124. }
  125. }