repair_create_page.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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(
  93. item.projectId,
  94. item.liftId,
  95. item.isTrapped,
  96. item.isCritical,
  97. item.repairReason,
  98. _controller.text.toString(),
  99. item.callerName,
  100. item.callerTel,
  101. item.callerDate, onSuccess: (res) {
  102. dismissLoading(context);
  103. showAlert(context, "提示", "保存成功", "确定", () {
  104. NavigatorUtils.goBack(context);
  105. NavigatorUtils.goBack(context);
  106. });
  107. }, onError: (code, msg) {
  108. dismissLoading(context);
  109. toasts(msg);
  110. });
  111. }
  112. @override
  113. Widget build(BuildContext context) {
  114. return Scaffold(
  115. appBar: MyAppBar(
  116. centerTitle: "发起急修",
  117. actions: <Widget>[
  118. FlatButton(
  119. onPressed: () {
  120. _saveAction();
  121. },
  122. child: Text(
  123. "确定",
  124. style: TextStyle(color: Colours.blue_app_main),
  125. ),
  126. textColor: Colours.text,
  127. highlightColor: Colors.transparent)
  128. ],
  129. ),
  130. body: SafeArea(
  131. child: Column(
  132. children: <Widget>[
  133. Expanded(
  134. flex: 1,
  135. child: defaultTargetPlatform == TargetPlatform.iOS
  136. ? FormKeyboardActions(child: _buildBody())
  137. : SingleChildScrollView(child: _buildBody()),
  138. )
  139. ],
  140. ),
  141. ),
  142. );
  143. }
  144. _buildBody() {
  145. return Column(
  146. crossAxisAlignment: CrossAxisAlignment.start,
  147. children: <Widget>[
  148. ClickItem(
  149. title: "项目名称",
  150. content: "${item.projectName.length == 0 ? '请选择' : item.projectName}",
  151. onTap: () {
  152. NavigatorUtils.pushResult(
  153. context, RepairRouter.repairSelectProjectPage, (result) {
  154. setState(() {
  155. List values = result;
  156. ProjectListItem model = values[0];
  157. item.projectName = model.projectName;
  158. item.projectId = model.projectId;
  159. LiftListItem liftmodel = values[1];
  160. item.registrationCode = liftmodel.registrationCode;
  161. item.liftId = liftmodel.id;
  162. // item.registrationCode = "";
  163. // item.liftId = "";
  164. setState(() {});
  165. });
  166. });
  167. },
  168. ),
  169. Offstage(
  170. offstage: item.projectId.length == 0,
  171. child: ClickItem(
  172. title: "电梯",
  173. content:
  174. "${item.registrationCode.length == 0 ? '请选择' : item.registrationCode}",
  175. onTap: () {
  176. NavigatorUtils.pushResult(context,
  177. "${RepairRouter.repairSelectLiftPage}?id=${item.projectId}",
  178. (result) {
  179. setState(() {
  180. LiftListItem model = result;
  181. item.registrationCode = model.registrationCode;
  182. item.liftId = model.id;
  183. setState(() {});
  184. });
  185. });
  186. },
  187. ),
  188. ),
  189. ClickItem(
  190. title: "故障原因",
  191. content:
  192. "${item.repairReason == 0 ? '其他' : item.repairReason == 1 ? '停电' : '故障'}",
  193. onTap: () {
  194. _showBottomSheet(["其他", "停电", "故障"], (index) {
  195. item.repairReason = index;
  196. setState(() {});
  197. });
  198. },
  199. ),
  200. ClickItem(
  201. title: "是否关人",
  202. content: "${item.isTrapped == 0 ? '否' : '是'}",
  203. onTap: () {
  204. _showBottomSheet(["否", "是"], (index) {
  205. item.isTrapped = index;
  206. setState(() {});
  207. });
  208. },
  209. ),
  210. ClickItem(
  211. title: "是否紧急",
  212. content: "${item.isCritical == 0 ? '否' : '是'}",
  213. onTap: () {
  214. _showBottomSheet(["否", "是"], (index) {
  215. item.isCritical = index;
  216. setState(() {});
  217. });
  218. },
  219. ),
  220. ClickItem(
  221. title: "报修时间",
  222. content: "${item.callerDate}",
  223. onTap: () {
  224. _selectTime();
  225. }),
  226. TextFieldItem(
  227. title: "报修人",
  228. content: "${item.callerName}",
  229. controller: TextEditingController(),
  230. hintText: "请填写",
  231. focusNode: FocusNode(),
  232. onChanged: (res) {
  233. print(res);
  234. item.callerName = res;
  235. },
  236. ),
  237. TextFieldItem(
  238. title: "报修人电话",
  239. content: "${item.callerTel}",
  240. controller: TextEditingController(),
  241. hintText: "请填写",
  242. focusNode: FocusNode(),
  243. onChanged: (res) {
  244. print(res);
  245. item.callerTel = res;
  246. },
  247. ),
  248. Container(
  249. color: ThemeUtils.getTabsBg(context),
  250. child: Padding(
  251. padding: const EdgeInsets.only(
  252. top: 5, left: 15.0, right: 15.0, bottom: 8.0),
  253. child: TextField(
  254. maxLength: 30,
  255. maxLines: 3,
  256. controller: _controller,
  257. decoration: InputDecoration(
  258. hintText: "故障描述",
  259. border: InputBorder.none,
  260. hintStyle: TextStyles.textGray14)),
  261. ),
  262. ),
  263. ],
  264. );
  265. }
  266. }