chooseVisitTimeContent_vm.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import 'package:cpt_services/modules/services/service_order_confirm/service_order_confirm_vm.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:riverpod_annotation/riverpod_annotation.dart';
  5. import 'package:router/ext/auto_router_extensions.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:widgets/dialog/dialog_content_wrap.dart';
  8. import 'package:widgets/load_state_layout.dart';
  9. import '../../../respository/services_respository.dart';
  10. import 'chooseVisitTimeContent_state.dart';
  11. part 'chooseVisitTimeContent_vm.g.dart';
  12. List<Map<String, dynamic>> visitTimeList = [
  13. {
  14. "name": "08:00 AM",
  15. "id": 1,
  16. "price": 40.0,
  17. "type": null
  18. },
  19. {
  20. "name": "08:30 AM",
  21. "id": 1,
  22. "price": 40.0,
  23. "type": null
  24. },
  25. {
  26. "name": "09:00 AM",
  27. "id": 1,
  28. "price": 40.0,
  29. "type": null
  30. },
  31. {
  32. "name": "09:30 AM",
  33. "id": 1,
  34. "price": 40.0,
  35. "type": null
  36. },
  37. {
  38. "name": "10:00 AM",
  39. "id": 1,
  40. "price": 40.0,
  41. "type": null
  42. },
  43. {
  44. "name": "10:30 AM",
  45. "id": 1,
  46. "price": 40.0,
  47. "type": null
  48. },
  49. {
  50. "name": "11:00 AM",
  51. "id": 1,
  52. "price": 40.0,
  53. "type": null
  54. },
  55. {
  56. "name": "11:30 AM",
  57. "id": 1,
  58. "price": 40.0,
  59. "type": null
  60. },
  61. {
  62. "name": "12:00 AM",
  63. "id": 1,
  64. "price": 40.0,
  65. "type": null
  66. },
  67. {
  68. "name": "12:30 PM",
  69. "id": 1,
  70. "price": 40.0,
  71. "type": null
  72. },
  73. {
  74. "name": "13:00 PM",
  75. "id": 1,
  76. "price": 50.0,
  77. "type": {
  78. "text": "Extreme speed",
  79. "type": "extremeSpeed",
  80. 'code': 1,
  81. }
  82. },
  83. {
  84. "name": "13:30 PM",
  85. "id": 1,
  86. "price": 50.0,
  87. "type": {
  88. "text": "Extreme speed",
  89. "type": "extremeSpeed",
  90. 'code': 1,
  91. }
  92. },
  93. {
  94. "name": "14:00 PM",
  95. "id": 1,
  96. "price": 50.0,
  97. "type": {
  98. "text": "Extreme speed",
  99. "type": "extremeSpeed",
  100. 'code': 1,
  101. }
  102. },
  103. {
  104. "name": "14:30 PM",
  105. "id": 1,
  106. "price": 50.0,
  107. "type": {
  108. "text": "Extreme speed",
  109. "type": "extremeSpeed",
  110. 'code': 1,
  111. }
  112. },
  113. {
  114. "name": "15:00 PM",
  115. "id": 1,
  116. "price": 50.0,
  117. "type": {
  118. "text": "Extreme speed",
  119. "type": "extremeSpeed",
  120. 'code': 1,
  121. }
  122. },
  123. ];
  124. @riverpod
  125. class ChooseVisitTimeContentVm extends _$ChooseVisitTimeContentVm {
  126. late ServicesRespository serviceRespositoryInstance;
  127. ChooseVisitTimeContentState initState(){
  128. Log.d("--------------------------initState---------------------");
  129. List<VisitTimeContentItem> visitTimeListNew = [];
  130. visitTimeList.forEach((item) {
  131. VisitTimeContentItem newItem = VisitTimeContentItem()
  132. ..id = item['id']
  133. ..price = item['price'] as double
  134. ..name = item['name']
  135. ..type = null
  136. ..isDisable = false
  137. ..isChecked = false;
  138. visitTimeListNew.add(newItem);
  139. });
  140. return ChooseVisitTimeContentState(
  141. visitTimeList: visitTimeListNew,
  142. );
  143. }
  144. @override
  145. ChooseVisitTimeContentState build(){
  146. // 引入数据仓库
  147. serviceRespositoryInstance = ref.read(servicesRespositoryProvider);
  148. state = initState();
  149. Log.d("--------------------------build---------------------");
  150. return state;
  151. }
  152. void changeLoadingState(LoadState loadState, String? errorMsg) {
  153. state = state.copyWith(
  154. loadingState: loadState,
  155. errorMessage: errorMsg
  156. );
  157. }
  158. initPageData(BuildContext context){
  159. changeLoadingState(LoadState.State_Success, null);
  160. }
  161. Future<ChooseVisitTimeContentState> getVisitTimeList(BuildContext context) async{
  162. Log.d("--------------------------getVisitTimeList---------------------");
  163. // 获取数据
  164. // state.visitTimeList = serviceRespositoryInstance.getVisitTimeList();
  165. // state = state.copyWith(
  166. // visitTimeList: state.visitTimeList,
  167. // );
  168. changeLoadingState(LoadState.State_Loading, null);
  169. List<Map<String, dynamic>> visitTimeList = [
  170. {
  171. "name": "10:00 AM",
  172. "id": 1,
  173. "price": 40.0,
  174. "type": null
  175. },
  176. {
  177. "name": "10:30 AM",
  178. "id": 1,
  179. "price": 40.0,
  180. "type": null
  181. },
  182. {
  183. "name": "11:00 AM",
  184. "id": 1,
  185. "price": 40.0,
  186. "type": null
  187. },
  188. {
  189. "name": "11:30 AM",
  190. "id": 1,
  191. "price": 40.0,
  192. "type": null
  193. },
  194. {
  195. "name": "12:00 AM",
  196. "id": 1,
  197. "price": 40.0,
  198. "type": null
  199. },
  200. {
  201. "name": "12:30 PM",
  202. "id": 1,
  203. "price": 40.0,
  204. "type": null
  205. },
  206. {
  207. "name": "13:00 PM",
  208. "id": 1,
  209. "price": 50.0,
  210. "type": {
  211. "text": "Extreme speed",
  212. "type": "extremeSpeed",
  213. 'code': 1,
  214. }
  215. },
  216. {
  217. "name": "13:30 PM",
  218. "id": 1,
  219. "price": 50.0,
  220. "type": {
  221. "text": "Extreme speed",
  222. "type": "extremeSpeed",
  223. 'code': 1,
  224. }
  225. },
  226. {
  227. "name": "14:00 PM",
  228. "id": 1,
  229. "price": 50.0,
  230. "type": {
  231. "text": "Extreme speed",
  232. "type": "extremeSpeed",
  233. 'code': 1,
  234. }
  235. },
  236. {
  237. "name": "14:30 PM",
  238. "id": 1,
  239. "price": 50.0,
  240. "type": {
  241. "text": "Extreme speed",
  242. "type": "extremeSpeed",
  243. 'code': 1,
  244. }
  245. },
  246. {
  247. "name": "15:00 PM",
  248. "id": 1,
  249. "price": 50.0,
  250. "type": {
  251. "text": "Extreme speed",
  252. "type": "extremeSpeed",
  253. 'code': 1,
  254. }
  255. },
  256. ];
  257. await Future.delayed(Duration(seconds: 1), (){});
  258. List<VisitTimeContentItem> visitTimeListNew = [];
  259. visitTimeList.forEach((item) {
  260. VisitTimeContentItem newItem = VisitTimeContentItem()
  261. ..id = item['id']
  262. ..price = item['price'] as double
  263. ..name = item['name']
  264. ..type = null
  265. ..isDisable = false
  266. ..isChecked = false;
  267. visitTimeListNew.add(newItem);
  268. });
  269. state = state.copyWith(
  270. visitTimeList: visitTimeListNew,
  271. );
  272. Log.d("--------------------------getVisitTimeList END ${state.visitTimeList}---------------------");
  273. changeLoadingState(LoadState.State_Success, null);
  274. return ChooseVisitTimeContentState(
  275. visitTimeList: visitTimeListNew,
  276. );
  277. }
  278. handlerChangeNum(BuildContext context, int num, int index){
  279. // state.visitTimeList[index].tu = num;
  280. // state = state.copyWith(
  281. // visitTimeList: state.visitTimeList,
  282. // );
  283. }
  284. handlerTimeItemClick(BuildContext context, int index, bool isSelected){
  285. // 修改 状态
  286. state.visitTimeList[index].isChecked = isSelected;
  287. state = state.copyWith(
  288. visitTimeList: state.visitTimeList,
  289. );
  290. ref.read(serviceOrderConfirmVmProvider.notifier).setConfirmOrderTotalPrice(context);
  291. }
  292. }