device_manage_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. import 'package:deus_app/common/style/TitleBar.dart';
  2. import 'package:deus_app/common/style/gsy_style.dart';
  3. import 'package:deus_app/common/utils/ConstantString.dart';
  4. import 'package:deus_app/common/utils/DioUtil.dart';
  5. import 'package:deus_app/common/utils/ToastUtils.dart';
  6. import 'package:deus_app/generated/json/equipment_info_entity_helper.dart';
  7. import 'package:deus_app/generated/json/equipment_list_entity_helper.dart';
  8. import 'package:deus_app/model/equipment_info_entity.dart';
  9. import 'package:deus_app/model/equipment_list_entity.dart';
  10. import 'package:deus_app/page/device/device_manage_detail_page.dart';
  11. import 'package:deus_app/widget/MyDrawer.dart';
  12. import 'package:flutter/cupertino.dart';
  13. import 'package:flutter/material.dart';
  14. class DeviceManagePage extends StatefulWidget {
  15. static var routeName = '/DeviceManagePage';
  16. const DeviceManagePage({super.key});
  17. @override
  18. State createState() {
  19. return _DeviceManage();
  20. }
  21. }
  22. class _DeviceManage extends State<DeviceManagePage> {
  23. String deviceNum = "0";
  24. String _device = '', _username = '';
  25. dynamic _satus, _isEnabled;
  26. final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  27. List<EquipmentListDataEquipmentVOS> equipmentVOS =
  28. <EquipmentListDataEquipmentVOS>[];
  29. @override
  30. void initState() {
  31. super.initState();
  32. equipmentList();
  33. }
  34. @override
  35. Widget build(BuildContext contexts) {
  36. return Scaffold(
  37. key: _scaffoldKey,
  38. appBar: TitleBar().drawAppBar(ConstantString.deviceManageText, () {
  39. _scaffoldKey.currentState?.openEndDrawer();
  40. }),
  41. backgroundColor: const Color(0xfff2f2f2),
  42. endDrawer: MyDrawer(
  43. callback:
  44. (String device, String name, dynamic stase, dynamic isEnabled) {
  45. _device = device;
  46. _username = name;
  47. _satus = stase;
  48. _isEnabled = isEnabled;
  49. equipmentList();
  50. },
  51. ),
  52. //抽屉
  53. body: equipmentVOS.isNotEmpty
  54. ? Column(
  55. children: [
  56. SizedBox(
  57. height: 10,
  58. ),
  59. Row(
  60. mainAxisAlignment: MainAxisAlignment.start,
  61. children: [
  62. SizedBox(
  63. width: 15,
  64. ),
  65. Text(ConstantString.deviceNum,
  66. style: GSYConstant.smallActionLightText),
  67. Text(deviceNum, style: GSYConstant.normalTextBigWhiteBold),
  68. ],
  69. ),
  70. Expanded(
  71. child: Container(
  72. // child: SmartRefresher(
  73. // enablePullDown: true,
  74. // enablePullUp: true,
  75. // header: WaterDropHeader(),
  76. // footer: CustomFooter(
  77. // builder: (BuildContext context, LoadStatus? mode) {
  78. // Widget body;
  79. // if (mode == LoadStatus.idle) {
  80. // body = Text("上拉加载");
  81. // } else if (mode == LoadStatus.loading) {
  82. // body = CupertinoActivityIndicator();
  83. // } else if (mode == LoadStatus.failed) {
  84. // body = Text("加载失败!点击重试!");
  85. // } else if (mode == LoadStatus.canLoading) {
  86. // body = Text("松手,加载更多!");
  87. // } else {
  88. // body = Text("没有更多数据了!");
  89. // }
  90. // return Container(
  91. // height: 55.0,
  92. // child: Center(child: body),
  93. // );
  94. // },
  95. // ),
  96. // controller: _refreshController,
  97. // onRefresh: _onRefresh,
  98. // onLoading: _onLoading,
  99. child: ListView.builder(
  100. itemCount: equipmentVOS.length,
  101. itemBuilder: (context, index) {
  102. return Container(
  103. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  104. padding: EdgeInsets.only(top: 12, bottom: 10),
  105. color: Colors.white,
  106. child: ListTile(
  107. title: Column(
  108. children: [
  109. Row(
  110. mainAxisAlignment:
  111. MainAxisAlignment.spaceBetween,
  112. children: [
  113. Container(
  114. child: Text(
  115. equipmentVOS[index].showName,
  116. style: const TextStyle(
  117. color: Colors.black,
  118. fontSize:
  119. GSYConstant.middleTextWhiteSize,
  120. fontWeight: FontWeight.bold,
  121. ),
  122. ),
  123. ),
  124. Container(
  125. padding: EdgeInsets.only(
  126. top: 3,
  127. bottom: 3,
  128. left: 5,
  129. right: 5),
  130. child: Text(
  131. equipmentVOS[index].status == 0
  132. ? '在线'
  133. : equipmentVOS[index].status == 1
  134. ? '离线'
  135. : equipmentVOS[index]
  136. .status ==
  137. 2
  138. ? '未激活'
  139. : '未知',
  140. textAlign: TextAlign.right,
  141. style: TextStyle(
  142. color: equipmentVOS[index].status ==
  143. 0
  144. ? Colors.blue
  145. : equipmentVOS[index].status ==
  146. 1
  147. ? Colors.orange
  148. : equipmentVOS[index]
  149. .status ==
  150. 2
  151. ? Colors.red
  152. : Colors.black,
  153. fontSize: GSYConstant.minTextSize,
  154. ),
  155. ),
  156. decoration: BoxDecoration(
  157. border: new Border.all(
  158. color: equipmentVOS[index].status ==
  159. 0
  160. ? Colors.blue
  161. : equipmentVOS[index].status ==
  162. 1
  163. ? Colors.orange
  164. : equipmentVOS[index]
  165. .status ==
  166. 2
  167. ? Colors.red
  168. : Colors.black, //边框颜色
  169. width: 1.0, //边框粗细
  170. ),
  171. borderRadius: const BorderRadius.all(
  172. const Radius.circular(
  173. 3.0)), //边框的弧度
  174. ),
  175. )
  176. ]),
  177. // SizedBox(
  178. // height: 12,
  179. // ),
  180. // Row(
  181. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  182. // children: [
  183. // Container(
  184. // child: Text(
  185. // 'devicekey:',
  186. // style: TextStyle(
  187. // color: GSYColors.primaryLightValue,
  188. // fontSize: GSYConstant.middleTextWhiteSize,
  189. // ),
  190. // ),
  191. // ),
  192. // Container(
  193. // child: Text(
  194. // 'devicekey',
  195. // textAlign: TextAlign.right,
  196. // style: TextStyle(
  197. // color: GSYColors.primaryLightValue,
  198. // fontSize: GSYConstant.middleTextWhiteSize,
  199. // ),
  200. // ),
  201. // ),
  202. // ]),
  203. // SizedBox(
  204. // height: 10,
  205. // ),
  206. // Row(
  207. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  208. // children: [
  209. // Container(
  210. // child: Text(
  211. // 'IMEI:',
  212. // style: TextStyle(
  213. // color: GSYColors.primaryLightValue,
  214. // fontSize: GSYConstant.middleTextWhiteSize,
  215. // ),
  216. // ),
  217. // ),
  218. // Container(
  219. // child: Text(
  220. // 'IMEI',
  221. // textAlign: TextAlign.right,
  222. // style: TextStyle(
  223. // color: GSYColors.primaryLightValue,
  224. // fontSize: GSYConstant.middleTextWhiteSize,
  225. // ),
  226. // ),
  227. // ),
  228. // ]),
  229. SizedBox(
  230. height: 5,
  231. ),
  232. ],
  233. ),
  234. onTap: () {
  235. equipmentInfo(equipmentVOS[index].id);
  236. },
  237. ));
  238. },
  239. ),
  240. ))
  241. ],
  242. )
  243. : Container(
  244. alignment: Alignment.center,
  245. child: const Text(
  246. '暂无数据',
  247. textAlign: TextAlign.center,
  248. style: TextStyle(
  249. color: GSYColors.primaryLightValue,
  250. fontSize: GSYConstant.middleTextWhiteSize,
  251. ),
  252. )),
  253. );
  254. }
  255. equipmentList() async {
  256. // LoadingDialogHelper.showLoading(context);
  257. var result = await DioUtil()
  258. .request("equipment/equipmentList", method: DioMethod.post, data: {
  259. 'index': 1,
  260. 'size': 50,
  261. 'query': {
  262. 'status': _satus,
  263. 'name': _device,
  264. 'isEnable': _isEnabled,
  265. 'showName': _username
  266. }
  267. });
  268. EquipmentListEntity entity = equipmentListEntityFromJson(
  269. EquipmentListEntity(),
  270. result,
  271. );
  272. // LoadingDialogHelper.dismissLoading(context);
  273. if (entity.code == 0) {
  274. setState(() {
  275. deviceNum = entity.data.total.toString();
  276. equipmentVOS.clear();
  277. equipmentVOS.addAll(entity.data.equipmentVOS);
  278. });
  279. } else {
  280. showToast(entity.msg);
  281. }
  282. }
  283. equipmentInfo(int id) async {
  284. var result = await DioUtil().request("equipment/equipmentInfo",
  285. method: DioMethod.get, params: {'id': id});
  286. EquipmentInfoEntity entity =
  287. equipmentInfoEntityFromJson(EquipmentInfoEntity(), result);
  288. if (entity.code == 0) {
  289. setState(() {
  290. Navigator.push(
  291. context,
  292. MaterialPageRoute(
  293. builder: (context) =>
  294. DeviceManageDetailPage(data: entity.data)));
  295. });
  296. } else {
  297. showToast(entity.msg);
  298. }
  299. }
  300. }