home_page.dart 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import 'package:deus_app/common/local/StoreHelper.dart';
  2. import 'package:deus_app/common/utils/ConstantString.dart';
  3. import 'package:deus_app/common/utils/DioUtil.dart';
  4. import 'package:deus_app/common/utils/ToastUtils.dart';
  5. import 'package:deus_app/generated/json/personal_data_count_entity_helper.dart';
  6. import 'package:deus_app/model/personal_data_count_entity.dart';
  7. import 'package:deus_app/page/patrol/patrol_job_page.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter/services.dart';
  10. import '../device/device_manage_page.dart';
  11. import '../maint/maint_job_page.dart';
  12. class HomePage extends StatefulWidget {
  13. static var routeName = '/HomePage';
  14. const HomePage({Key? key}) : super(key: key);
  15. @override
  16. _MineViewPageState createState() => _MineViewPageState();
  17. }
  18. class _MineViewPageState extends State<HomePage> {
  19. List items = [
  20. {"name": "今日维保任务", "num": 0},
  21. {"name": "今日巡检任务", "num": 0}
  22. ];
  23. List icons = [
  24. {
  25. "name": "设备管理",
  26. "image": "images/device_manage.png",
  27. 'jump': DeviceManagePage.routeName
  28. },
  29. {
  30. "name": "维保任务",
  31. "image": "images/maintenance.png",
  32. 'jump': MaintJobPage.routeName
  33. },
  34. {
  35. "name": "巡检任务",
  36. "image": "images/patrol_inspect.png",
  37. 'jump': PatrolJobPage.routeName
  38. },
  39. {"name": "保修管理", "image": "images/maintenance_manage.png", 'jump': ''},
  40. ];
  41. int alarmCount = 0;
  42. @override
  43. void initState() {
  44. super.initState();
  45. fetchAlbum();
  46. }
  47. fetchAlbum() async {
  48. var result =
  49. await DioUtil().request("personalData/count", method: DioMethod.post);
  50. PersonalDataCountEntity entity =
  51. personalDataCountEntityFromJson(PersonalDataCountEntity(), result);
  52. if (entity.code == 0) {
  53. setState(() {
  54. items.clear();
  55. items.add({"name": "今日维保任务", "num": entity.data.maintJobCount});
  56. items.add({"name": "今日巡检任务", "num": entity.data.patrolJobCount});
  57. alarmCount = entity.data.alarmCount;
  58. });
  59. } else {
  60. showToast(entity.msg);
  61. }
  62. }
  63. void registerHandler() {}
  64. @override
  65. Widget build(BuildContext context) {
  66. return Scaffold(
  67. extendBodyBehindAppBar: true,
  68. appBar: AppBar(
  69. shadowColor: Colors.transparent,
  70. backgroundColor: Colors.transparent,
  71. systemOverlayStyle: SystemUiOverlayStyle.light
  72. .copyWith(statusBarColor: Colors.transparent),
  73. // title: Text(user != null ? user["nickname"] : "",style:TextStyle(color: Colors.white),),
  74. centerTitle: true,
  75. elevation: 0.0,
  76. toolbarHeight: 0,
  77. ),
  78. backgroundColor: const Color(0xfff4f6ff),
  79. body: Column(
  80. children: [
  81. Container(
  82. padding: EdgeInsets.only(
  83. left: 15,
  84. right: 15,
  85. top: MediaQuery.of(context).padding.top + 10),
  86. height: MediaQuery.of(context).size.width * 0.53,
  87. decoration: BoxDecoration(
  88. image: DecorationImage(
  89. image: AssetImage("images/home_bg.jpg"), fit: BoxFit.cover),
  90. ),
  91. child: Column(
  92. children: [
  93. Row(
  94. mainAxisAlignment: MainAxisAlignment.end,
  95. children: [
  96. IconButton(
  97. icon: Icon(Icons.settings),
  98. color: Colors.white,
  99. onPressed: () => showToast("text"),
  100. ),
  101. ],
  102. ),
  103. Row(
  104. children: [
  105. Image.asset(
  106. "images/head.png",
  107. width: 40,
  108. height: 40,
  109. ),
  110. SizedBox(width: 10),
  111. Text(
  112. StoreHelper.getStorage(ConstantString.name),
  113. style: TextStyle(
  114. color: Colors.white,
  115. fontWeight: FontWeight.bold,
  116. fontSize: 15),
  117. )
  118. ],
  119. ),
  120. SizedBox(height: 20),
  121. Row(
  122. children: [
  123. SizedBox(width: 50),
  124. Text(StoreHelper.getStorage(ConstantString.phone),
  125. style: TextStyle(
  126. color: Colors.white,
  127. fontWeight: FontWeight.bold,
  128. fontSize: 18))
  129. ],
  130. ),
  131. SizedBox(height: 10),
  132. Row(
  133. children: [
  134. SizedBox(width: 50),
  135. Text(StoreHelper.getStorage(ConstantString.orgName),
  136. style:
  137. TextStyle(color: Color(0xffaaaaaa), fontSize: 15))
  138. ],
  139. ),
  140. ],
  141. ),
  142. ),
  143. Container(
  144. padding: EdgeInsets.all(10),
  145. margin: EdgeInsets.all(15),
  146. decoration: BoxDecoration(
  147. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  148. child: Column(
  149. crossAxisAlignment: CrossAxisAlignment.start,
  150. children: [
  151. SizedBox(height: 15),
  152. Container(
  153. width: double.infinity,
  154. height: 40,
  155. alignment: Alignment.center,
  156. decoration: BoxDecoration(
  157. color:
  158. alarmCount > 0 ? Colors.red : Color(0xff74b900),
  159. borderRadius: BorderRadius.circular(10)),
  160. child: Text(
  161. alarmCount > 0 ? '今日告警数量:$alarmCount' : "当前设备运行正常",
  162. style: TextStyle(
  163. color: Color(0xffffffff), fontSize: 15))),
  164. SizedBox(
  165. height: 20,
  166. ),
  167. Text("待办任务",
  168. style: TextStyle(color: Color(0xff000000), fontSize: 18)),
  169. SizedBox(
  170. height: 10,
  171. ),
  172. GridView.builder(
  173. shrinkWrap: true,
  174. padding: const EdgeInsets.only(
  175. top: 10,
  176. ),
  177. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  178. crossAxisCount: 1,
  179. mainAxisSpacing: 10,
  180. crossAxisSpacing: 10,
  181. childAspectRatio: MediaQuery.of(context).size.width / 30,
  182. ),
  183. itemBuilder: (context, index) {
  184. Map item = items[index];
  185. return Row(
  186. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  187. children: [
  188. Text(item["name"],
  189. style: TextStyle(
  190. color: Color(0xff000000), fontSize: 13)),
  191. Text(item["num"].toString(),
  192. style: TextStyle(
  193. color: Color(0xff000000), fontSize: 13))
  194. ],
  195. );
  196. },
  197. itemCount: items.length,
  198. )
  199. ],
  200. ),
  201. ),
  202. Container(
  203. margin: EdgeInsets.only(left: 15, right: 15),
  204. decoration:
  205. BoxDecoration(borderRadius: BorderRadius.circular(10)),
  206. child: Column(
  207. crossAxisAlignment: CrossAxisAlignment.start,
  208. children: [
  209. GridView.builder(
  210. shrinkWrap: true,
  211. padding: const EdgeInsets.only(
  212. top: 0,
  213. ),
  214. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  215. crossAxisCount: 3,
  216. mainAxisSpacing: 10,
  217. crossAxisSpacing: 10,
  218. childAspectRatio:
  219. (MediaQuery.of(context).size.width / 3 - 60 / 3) /
  220. 120,
  221. ),
  222. itemBuilder: (context, index) {
  223. Map item = icons[index];
  224. return GestureDetector(
  225. onTap: () => Navigator.pushNamed(context, item['jump']),
  226. child: Container(
  227. padding: EdgeInsets.all(5),
  228. decoration: BoxDecoration(
  229. color: Color(0xffffffff),
  230. borderRadius: BorderRadius.circular(10)),
  231. child: Column(
  232. crossAxisAlignment: CrossAxisAlignment.center,
  233. mainAxisAlignment: MainAxisAlignment.center,
  234. children: [
  235. Image.asset(
  236. item["image"],
  237. width: 60,
  238. height: 60,
  239. ),
  240. SizedBox(height: 10),
  241. Text(item["name"].toString(),
  242. style: TextStyle(
  243. color: Color(0xff000000), fontSize: 13))
  244. ],
  245. ),
  246. ),
  247. );
  248. },
  249. itemCount: icons.length,
  250. )
  251. ],
  252. ),
  253. ),
  254. ],
  255. ));
  256. }
  257. }