deviation_location_widget.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/base/base_lifecycle_state.dart';
  3. import 'package:lszlgl/main.dart';
  4. import 'package:lszlgl/model/rsp/deviation_loaction_rsp.dart';
  5. import 'package:lszlgl/model/rsp/sample_task_rsp.dart';
  6. import 'package:lszlgl/network/my_api.dart';
  7. import 'package:lszlgl/widget/button.dart';
  8. import 'package:lszlgl/widget/card_item.dart';
  9. class DeviationLocationWidget extends StatefulWidget {
  10. final DeviationLoactionRsp rsp; //
  11. final SampleTaskItem req; // 扦样信息 取区域code用
  12. final Function(SampleTaskItem req) pCodeCallBack;
  13. const DeviationLocationWidget({super.key,required this.rsp, required this.req ,required this.pCodeCallBack});
  14. @override
  15. State<DeviationLocationWidget> createState() => _DeviationLocationWidgetState();
  16. }
  17. class _DeviationLocationWidgetState extends State<DeviationLocationWidget> {
  18. final CityList = <CardMenuData>[].notifier<List<CardMenuData>>();
  19. final citysel = null.notifier<CardMenuData?>();
  20. final QuList = <CardMenuData>[].notifier<List<CardMenuData>>();
  21. final qusel = null.notifier<CardMenuData?>();
  22. /// 获取行政区划列表
  23. Future<List<CardMenuData>?> getDistrictList(num level, {num? id}) async {
  24. MyNavigator.showLoading();
  25. try {
  26. var rsp = await MyApi.get().districtList(level, id: id);
  27. List<CardMenuData> list = (rsp.data ?? []).map((e) => CardMenuData(e.uname, e.id)).toList();
  28. MyNavigator.dismissLoading();
  29. return list;
  30. } catch (e) {
  31. logger.e(e);
  32. }
  33. MyNavigator.dismissLoading();
  34. return null;
  35. }
  36. void getCityList(num? code) async{
  37. var cityList = await getDistrictList(2, id: code);
  38. if (cityList == null) return;
  39. CityList.value = cityList;
  40. }
  41. void getquList(num? code) async{
  42. var quList = await getDistrictList(3, id: code);
  43. if (quList == null) return;
  44. QuList.value = quList;
  45. }
  46. @override
  47. void initState() {
  48. super.initState();
  49. // 获取市列表
  50. if(widget.rsp.errorBj ==2 || widget.rsp.errorBj ==4 ){
  51. getCityList(widget.req.shengXzqh);
  52. }
  53. if(widget.rsp.errorBj ==3){
  54. getquList(widget.req.shiXzqh);
  55. }
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return PopScope(
  60. canPop: false,
  61. child: SafeArea(
  62. child: SingleChildScrollView(
  63. padding: EdgeInsets.fromLTRB(12, 22, 12, MediaQuery.of(context).viewInsets.bottom),
  64. child: Column(
  65. crossAxisAlignment: CrossAxisAlignment.stretch,
  66. mainAxisSize: MainAxisSize.min,
  67. children: [
  68. const Text(
  69. '扦样位置确认',
  70. style: TextStyle(fontSize: 14),
  71. textAlign: TextAlign.center,
  72. ),
  73. const SizedBox(height: 28),
  74. if(widget.rsp.errorBj == 1)
  75. Text(
  76. widget.rsp.errorZn ?? '',
  77. style: const TextStyle(fontSize: 14,fontWeight: FontWeight.bold),
  78. textAlign: TextAlign.center,
  79. ),
  80. if(widget.rsp.errorBj == 2) ...[
  81. const Text('您目前定位所在位置与任务不符,请选择您当前所在的市县',style: TextStyle(fontSize: 14,color: Colors.grey),),
  82. const SizedBox(height: 18),
  83. CardWidgets.buildMenu(
  84. false,
  85. '市/州',
  86. CityList,
  87. citysel,
  88. (_, sel) {
  89. widget.req.shiXzqh = sel.value;
  90. widget.req.quXzqh = null;
  91. qusel.value = null;
  92. getquList(sel.value!);
  93. },
  94. showTopLine: true
  95. ),
  96. CardWidgets.buildMenu(
  97. false,
  98. '区县',
  99. QuList,
  100. qusel,
  101. (_, sel) => widget.req.quXzqh = sel.value,
  102. ),
  103. ],
  104. if(widget.rsp.errorBj == 3) ...[
  105. const Text('您目前定位所在位置与任务不符,请选择您当前所在的区县',style: TextStyle(fontSize: 14,color: Colors.grey),),
  106. const SizedBox(height: 18),
  107. CardWidgets.buildMenu(
  108. false,
  109. '区县',
  110. QuList,
  111. qusel,
  112. (_, sel) => widget.req.quXzqh = sel.value,
  113. showTopLine: true,
  114. ),
  115. ],
  116. if(widget.rsp.errorBj == 4) ...[
  117. const Text('您目前定位所在位置与任务不符,请选择您当前所在的市',style: TextStyle(fontSize: 14,color: Colors.grey),),
  118. const SizedBox(height: 18),
  119. CardWidgets.buildMenu(
  120. false,
  121. '市/州',
  122. CityList,
  123. citysel,
  124. (_, sel) => widget.req.shiXzqh = sel.value,
  125. showTopLine: true
  126. )
  127. ],
  128. const SizedBox(height: 32),
  129. Row(
  130. children: [
  131. Expanded(
  132. child: MyButton(
  133. '返回',
  134. onTap: (){
  135. if(widget.rsp.errorBj == 2){
  136. widget.req.shiXzqh = null;
  137. widget.req.quXzqh = null;
  138. }
  139. if(widget.rsp.errorBj == 3){
  140. widget.req.quXzqh = null;
  141. }
  142. if(widget.rsp.errorBj == 4){
  143. widget.req.shiXzqh = null;
  144. }
  145. Navigator.pop(context);
  146. },
  147. radius: 10,
  148. fountSize: 15,
  149. padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
  150. fountColor: const Color(0xFF25A6EE),
  151. backgroundColor: const Color(0xFFDFF4FD),
  152. border: Border.all(color: const Color(0xFF25A6EE))),
  153. ),
  154. const SizedBox(width: 46),
  155. Expanded(
  156. child: MyButton(
  157. '确定',
  158. onTap: (){
  159. if(widget.rsp.errorBj == 2 && widget.req.shiXzqh ==null){
  160. MyNavigator.showToast('市/州不能为空');
  161. return;
  162. }
  163. if(widget.rsp.errorBj == 2 && widget.req.quXzqh ==null){
  164. MyNavigator.showToast('区县不能为空');
  165. return;
  166. }
  167. if(widget.rsp.errorBj == 3 && widget.req.quXzqh ==null){
  168. MyNavigator.showToast('区县不能为空');
  169. return;
  170. }
  171. if(widget.rsp.errorBj == 4 && widget.req.shiXzqh ==null){
  172. MyNavigator.showToast('市/州不能为空');
  173. return;
  174. }
  175. widget.pCodeCallBack.call(widget.req);
  176. Navigator.pop(context);
  177. },
  178. radius: 10,
  179. fountSize: 15,
  180. padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
  181. gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
  182. ),
  183. ),
  184. ],
  185. ),
  186. const SizedBox(height: 22),
  187. ],
  188. ),
  189. ),
  190. ),
  191. );
  192. }
  193. }