repair_create_page.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  5. import 'package:keyboard_actions/keyboard_actions.dart';
  6. import 'package:liftmanager/internal/lift/model/lift_list_entity.dart';
  7. import 'package:liftmanager/internal/project/model/project_list_entity.dart';
  8. import 'package:liftmanager/internal/repair/model/repair_list_entity.dart';
  9. import 'package:liftmanager/internal/repair/repair_router.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/resources.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/theme_utils.dart';
  14. import 'package:liftmanager/utils/toast.dart';
  15. import 'package:liftmanager/widgets/app_bar.dart';
  16. import 'package:liftmanager/widgets/click_item.dart';
  17. import 'package:liftmanager/widgets/text_field_item.dart';
  18. class RepairCreatePage extends StatefulWidget {
  19. @override
  20. State<StatefulWidget> createState() {
  21. return RepairCreatePageState();
  22. }
  23. }
  24. class RepairCreatePageState extends State<RepairCreatePage> {
  25. RepairCreateItem item = RepairCreateItem();
  26. TextEditingController _controller = TextEditingController();
  27. TextEditingController _controller1 = TextEditingController();
  28. TextEditingController _controller2 = TextEditingController();
  29. /// 选择时间
  30. Future<void> _selectTime() async {
  31. DatePicker.showDateTimePicker(context,
  32. showTitleActions: true, onChanged: (date) {}, onConfirm: (date) {
  33. item.callerDate = "${date.toString().split(".")[0]}";
  34. setState(() {});
  35. }, currentTime: DateTime.now(), locale: LocaleType.zh);
  36. }
  37. _showBottomSheet(list, Function callback) {
  38. showModalBottomSheet(
  39. context: context,
  40. builder: (BuildContext context) {
  41. return SizedBox(
  42. height: 360.0,
  43. child: ListView.builder(
  44. itemExtent: 48.0,
  45. itemBuilder: (_, index) {
  46. return InkWell(
  47. child: Container(
  48. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  49. alignment: Alignment.centerLeft,
  50. child: Text(list[index]),
  51. ),
  52. onTap: () {
  53. setState(() {
  54. callback(index);
  55. });
  56. NavigatorUtils.goBack(context);
  57. },
  58. );
  59. },
  60. itemCount: list.length,
  61. ),
  62. );
  63. },
  64. );
  65. }
  66. _saveAction(){
  67. if(item.projectId.length==0){
  68. toasts("请选择项目");
  69. return;
  70. }
  71. if(item.liftId.length==0){
  72. toasts("请选择电梯");
  73. return;
  74. }
  75. if(item.callerDate.length==0){
  76. toasts("请选择报修时间");
  77. return;
  78. }
  79. if(item.callerName.length==0){
  80. toasts("请填写报修人姓名");
  81. return;
  82. }
  83. if(item.callerTel.length==0){
  84. toasts("请填写报修人电话");
  85. return;
  86. }
  87. if(_controller.text.toString().length==0){
  88. toasts("请填写故障描述");
  89. return;
  90. }
  91. showLoading(context, "正在提交...");
  92. ApiService(context: context).repairAdd(item.projectId,item.liftId,item.isTrapped,item.isCritical,item.repairReason,_controller.text.toString(),item.callerName,item.callerTel,item.callerDate,onSuccess: (res){
  93. dismissLoading(context);
  94. showAlert(context, "提示", "保存成功", "确定", () {
  95. NavigatorUtils.goBack(context);
  96. NavigatorUtils.goBack(context);
  97. });
  98. },onError: (code,msg){
  99. dismissLoading(context);
  100. toasts(msg);
  101. });
  102. }
  103. @override
  104. Widget build(BuildContext context) {
  105. return Scaffold(
  106. appBar: MyAppBar(
  107. centerTitle: "发起急修",
  108. actions: <Widget>[
  109. FlatButton(
  110. onPressed: () {
  111. _saveAction();
  112. },
  113. child: Text(
  114. "确定",
  115. style: TextStyle(color: Colors.white),
  116. ),
  117. textColor: Colours.dark_text,
  118. highlightColor: Colors.transparent)
  119. ],
  120. ),
  121. body: SafeArea(
  122. child: Column(
  123. children: <Widget>[
  124. Expanded(
  125. flex: 1,
  126. child: defaultTargetPlatform == TargetPlatform.iOS
  127. ? FormKeyboardActions(child: _buildBody())
  128. : SingleChildScrollView(child: _buildBody()),
  129. )
  130. ],
  131. ),
  132. ),
  133. );
  134. }
  135. _buildBody() {
  136. return Column(
  137. crossAxisAlignment: CrossAxisAlignment.start,
  138. children: <Widget>[
  139. ClickItem(
  140. title: "项目名称",
  141. content: "${item.projectName.length == 0 ? '请选择' : item.projectName}",
  142. onTap: () {
  143. NavigatorUtils.pushResult(
  144. context, RepairRouter.repairSelectProjectPage, (result) {
  145. setState(() {
  146. ProjectListItem model = result;
  147. item.projectName = model.projectName;
  148. item.projectId = model.projectId;
  149. item.registrationCode = "";
  150. item.liftId = "";
  151. setState(() {});
  152. });
  153. });
  154. },
  155. ),
  156. Offstage(
  157. offstage: item.projectId.length == 0,
  158. child: ClickItem(
  159. title: "电梯",
  160. content:
  161. "${item.registrationCode.length == 0 ? '请选择' : item.registrationCode}",
  162. onTap: () {
  163. NavigatorUtils.pushResult(context,
  164. "${RepairRouter.repairSelectLiftPage}?id=${item.projectId}",
  165. (result) {
  166. setState(() {
  167. LiftListItem model = result;
  168. item.registrationCode = model.registrationCode;
  169. item.liftId = model.id;
  170. setState(() {});
  171. });
  172. });
  173. },
  174. ),
  175. ),
  176. ClickItem(
  177. title: "故障原因",
  178. content: "${item.repairReason==0?'其他':item.repairReason==1?'停电':'故障'}",
  179. onTap: () {
  180. _showBottomSheet(["其他","停电","故障"], (index) {
  181. item.repairReason = index;
  182. setState(() {
  183. });
  184. });
  185. },
  186. ),
  187. ClickItem(
  188. title: "是否关人",
  189. content: "${item.isTrapped==0?'否':'是'}",
  190. onTap: () {
  191. _showBottomSheet(["否","是"], (index) {
  192. item.isTrapped = index;
  193. setState(() {
  194. });
  195. });
  196. },
  197. ),
  198. ClickItem(
  199. title: "是否紧急",
  200. content: "${item.isCritical==0?'否':'是'}",
  201. onTap: () {
  202. _showBottomSheet(["否","是"], (index) {
  203. item.isCritical = index;
  204. setState(() {
  205. });
  206. });
  207. },
  208. ),
  209. ClickItem(
  210. title: "报修时间",
  211. content: "${item.callerDate}",
  212. onTap: () {
  213. _selectTime();
  214. }),
  215. TextFieldItem(
  216. title: "报修人",
  217. content: "${item.callerName}",
  218. controller: TextEditingController(),
  219. hintText: "请填写",
  220. focusNode: FocusNode(),
  221. onChanged: (res) {
  222. print(res);
  223. item.callerName = res;
  224. },
  225. ),
  226. TextFieldItem(
  227. title: "报修人电话",
  228. content: "${item.callerTel}",
  229. controller: TextEditingController(),
  230. hintText: "请填写",
  231. focusNode: FocusNode(),
  232. onChanged: (res) {
  233. print(res);
  234. item.callerTel = res;
  235. },
  236. ),
  237. Container(
  238. color: ThemeUtils.getTabsBg(context),
  239. child: Padding(
  240. padding: const EdgeInsets.only(
  241. top: 5, left: 15.0, right: 15.0, bottom: 8.0),
  242. child: TextField(
  243. maxLength: 30,
  244. maxLines: 3,
  245. controller: _controller,
  246. decoration: InputDecoration(
  247. hintText: "故障描述",
  248. border: InputBorder.none,
  249. hintStyle: TextStyles.textGray14)),
  250. ),
  251. ),
  252. ],
  253. );
  254. }
  255. }