repair_safe_page.dart 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import 'dart:convert' as convert;
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  6. import 'package:keyboard_actions/keyboard_actions.dart';
  7. import 'package:liftmanager/internal/repair/model/repair_list_entity.dart';
  8. import 'package:liftmanager/internal/repair/repair_router.dart';
  9. import 'package:liftmanager/net/api_service.dart';
  10. import 'package:liftmanager/res/resources.dart';
  11. import 'package:liftmanager/routers/fluro_navigator.dart';
  12. import 'package:liftmanager/utils/theme_utils.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:liftmanager/widgets/click_item.dart';
  16. import 'package:liftmanager/widgets/my_button.dart';
  17. import 'package:liftmanager/widgets/radio_item.dart';
  18. class RepairSafePage extends StatefulWidget {
  19. RepairSafePage(this.repairItem);
  20. RepairItem repairItem;
  21. @override
  22. State<StatefulWidget> createState() {
  23. return RepairSafePageState();
  24. }
  25. }
  26. class RepairSafePageState extends State<RepairSafePage> {
  27. List<String> groupValue = ["", "", "", "", "", ""];
  28. String _stopTime = "";
  29. ///全选
  30. _allSelected() {
  31. groupValue = ["1", "1", "1", "1", "1", "1"];
  32. setState(() {});
  33. }
  34. /// 选择时间
  35. Future<void> _selectTime() async {
  36. DatePicker.showDateTimePicker(context,
  37. showTitleActions: true, onChanged: (date) {}, onConfirm: (date) {
  38. _stopTime = "${date.toString().split(".")[0]}";
  39. setState(() {});
  40. }, currentTime: DateTime.now(), locale: LocaleType.zh);
  41. }
  42. ///确认
  43. _stopAndSafe() {
  44. if(_stopTime.length == 0){
  45. toasts("请选择停梯时间");
  46. return;
  47. }
  48. showLoading(context, "正在执行...");
  49. ApiService(context: context)
  50. .repairStop(widget.repairItem.id, _stopTime, groupValue.toString(),
  51. onSuccess: (data) {
  52. dismissLoading(context);
  53. if (data != null && data) {
  54. String jsonString = convert.jsonEncode(widget.repairItem);
  55. NavigatorUtils.pushResult(context,"${RepairRouter.repairSubmitPage}?item=${Uri.encodeComponent(jsonString)}",(res){
  56. if(res != null && res){
  57. NavigatorUtils.goBackWithParams(context,res);
  58. }
  59. });
  60. }
  61. }, onError: (code, msg) {
  62. dismissLoading(context);
  63. toasts(msg);
  64. });
  65. }
  66. @override
  67. Widget build(BuildContext context) {
  68. return Scaffold(
  69. //resizeToAvoidBottomPadding: false,
  70. appBar: const MyAppBar(
  71. centerTitle: "安全确认",
  72. ),
  73. body: SafeArea(
  74. child: Container(
  75. color: ThemeUtils.getBackgroundColor(context),
  76. child: Column(
  77. children: <Widget>[
  78. Expanded(
  79. flex: 1,
  80. child: defaultTargetPlatform == TargetPlatform.iOS
  81. ? FormKeyboardActions(child: _buildBody())
  82. : SingleChildScrollView(child: _buildBody()),
  83. ),
  84. Container(
  85. // color: Colours.bg_color,
  86. child: Padding(
  87. padding: const EdgeInsets.all(16),
  88. child: MyButton(
  89. fontSize: 14,
  90. onPressed: () {
  91. _stopAndSafe();
  92. },
  93. text: "确定",
  94. ),
  95. ))
  96. ],
  97. ),
  98. ),
  99. ));
  100. }
  101. _buildBody() {
  102. return Padding(
  103. padding: EdgeInsets.only(bottom: 30),
  104. child: Column(
  105. crossAxisAlignment: CrossAxisAlignment.start,
  106. children: <Widget>[
  107. ClickItem(
  108. title: "停梯时间",
  109. hintText: "请选择",
  110. content: "${_stopTime}",
  111. onTap: () {
  112. _selectTime();
  113. },
  114. ),
  115. Container(
  116. color: ThemeUtils.getTabsBg(context),
  117. padding: EdgeInsets.only(left: 15, right: 15),
  118. height: 32.5,
  119. child: Row(
  120. children: <Widget>[
  121. Expanded(
  122. flex: 1,
  123. child: Text(
  124. "安全防护确认",
  125. style: TextStyle(
  126. fontSize: 12, color: Colours.dark_text_gray),
  127. )),
  128. GestureDetector(
  129. onTap: _allSelected,
  130. child: Text(
  131. "全选",
  132. style: TextStyle(fontSize: 12, color: Colours.app_main),
  133. )),
  134. ],
  135. )),
  136. RadioItem(
  137. title: "用电安全",
  138. value: "1",
  139. groupValue: groupValue[0],
  140. onTap: () {
  141. groupValue[0] = groupValue[0] == "1" ? "0" : "1";
  142. setState(() {});
  143. }),
  144. RadioItem(
  145. title: "护栏",
  146. value: "1",
  147. groupValue: groupValue[1],
  148. onTap: () {
  149. groupValue[1] = groupValue[1] == "1" ? "0" : "1";
  150. setState(() {});
  151. }),
  152. RadioItem(
  153. title: "手套",
  154. value: "1",
  155. groupValue: groupValue[2],
  156. onTap: () {
  157. groupValue[2] = groupValue[2] == "1" ? "0" : "1";
  158. setState(() {});
  159. }),
  160. RadioItem(
  161. title: "安全帽",
  162. value: "1",
  163. groupValue: groupValue[3],
  164. onTap: () {
  165. groupValue[3] = groupValue[3] == "1" ? "0" : "1";
  166. setState(() {});
  167. }),
  168. RadioItem(
  169. title: "电器防护",
  170. value: "1",
  171. groupValue: groupValue[4],
  172. onTap: () {
  173. groupValue[4] = groupValue[4] == "1" ? "0" : "1";
  174. setState(() {});
  175. }),
  176. RadioItem(
  177. title: "照明",
  178. value: "1",
  179. groupValue: groupValue[5],
  180. onTap: () {
  181. groupValue[5] = groupValue[5] == "1" ? "0" : "1";
  182. setState(() {});
  183. }),
  184. Container(
  185. color: ThemeUtils.getTabsBg(context),
  186. padding: EdgeInsets.only(left: 15, right: 15),
  187. height: 32.5,
  188. child: Row(
  189. children: <Widget>[
  190. Expanded(
  191. flex: 1,
  192. child: Text(
  193. "请对已安全防护选项进行勾选,确保已做好安全防护工作",
  194. style: TextStyle(fontSize: 12, color: Colours.blue_app_main),
  195. ))
  196. ],
  197. )),
  198. ],
  199. ),
  200. );
  201. }
  202. }