brand_detail.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/net/api_service.dart';
  3. import 'package:liftmanager/utils/toast.dart';
  4. import 'package:liftmanager/widgets/app_bar.dart';
  5. import 'package:liftmanager/routers/fluro_navigator.dart';
  6. import 'package:liftmanager/widgets/load_image.dart';
  7. import 'package:liftmanager/internal/means/means_router.dart';
  8. import 'package:liftmanager/widgets/bbs_content.dart';
  9. import 'package:liftmanager/net/api_service.dart';
  10. import 'package:liftmanager/internal/bbs/model/brand_model.dart';
  11. import 'package:liftmanager/internal/bbs/model/error_model.dart';
  12. import 'dart:async';
  13. import 'package:flutter_screenutil/flutter_screenutil.dart';
  14. import 'package:liftmanager/utils/url.dart';
  15. import 'package:flutter_spinkit/flutter_spinkit.dart';
  16. import 'package:liftmanager/utils/theme_utils.dart';
  17. class BrandDetail extends StatefulWidget {
  18. BrandDetail(this.id);
  19. final String id;
  20. String index = "1";
  21. int checkIndex = 1; // 1:直梯, 2:扶梯
  22. @override
  23. State<StatefulWidget> createState() {
  24. return BrandDetailState();
  25. }
  26. }
  27. class BrandDetailState extends State<BrandDetail> {
  28. // NewsDetailItem item = NewsDetailItem();
  29. ScrollController _scrollController = new ScrollController();
  30. @override
  31. void dispose() {
  32. _scrollController.dispose();
  33. super.dispose();
  34. }
  35. @override
  36. void initState() {
  37. super.initState();
  38. getBrandDetail();
  39. getFaultCodeList();
  40. getFileCategorysTree();
  41. }
  42. bool _hasData = false;
  43. Records detailObj;
  44. getBrandDetail() {
  45. NewApiService().getBrandDetail(widget.id, onSuccess: (res) {
  46. detailObj = res;
  47. print("获取详情成功");
  48. print(res);
  49. _hasData = true;
  50. setState(() {});
  51. }, onError: (code, msg) {
  52. toasts(msg);
  53. });
  54. }
  55. bool _hasCodeData = false;
  56. List<dynamic> codeList = [];
  57. getFaultCodeList() {
  58. _hasCodeData = false;
  59. NewApiService().getFaultCodeList(widget.id, 0, 12, topFlag: 1, onSuccess: (res) {
  60. codeList = res.records;
  61. _hasCodeData = true;
  62. setState(() {});
  63. }, onError: (code, msg) {
  64. _hasCodeData = true;
  65. toasts(msg);
  66. setState(() {});
  67. });
  68. }
  69. bool _hasTypeData = false;
  70. List<dynamic> typeList = [];
  71. getFileCategorysTree() {
  72. _hasTypeData = false;
  73. NewApiService().getFileCategorysTree(widget.id, onSuccess: (res) {
  74. print("获取分类信息");
  75. // print(res.toList());
  76. typeList = res;
  77. if(typeList.length > 0) {
  78. this.changeTypeIndex(0);
  79. }
  80. _hasTypeData = true;
  81. setState(() {});
  82. }, onError: (code, msg) {
  83. _hasTypeData = true;
  84. toasts(msg);
  85. setState(() {});
  86. });
  87. }
  88. int typeIndex;
  89. List<dynamic> brandFileList = [];
  90. changeTypeIndex(index) {
  91. typeIndex = index;
  92. brandFileList = typeList[index].chilList;
  93. print(brandFileList);
  94. setState(() {});
  95. }
  96. @override
  97. Widget build(BuildContext context) {
  98. double width = MediaQuery.of(context).size.width;
  99. return Scaffold(
  100. appBar: MyAppBar(
  101. centerTitle: "电梯资料库",
  102. ),
  103. body: _hasData
  104. ? Container(
  105. child: Stack(
  106. children: <Widget>[
  107. typeList.length > 0
  108. ? CategorysNav(
  109. lists: typeList,
  110. typeIndex: typeIndex,
  111. fun: changeTypeIndex):Container(child: null,)
  112. ,
  113. Container(
  114. padding: typeList.length > 0?EdgeInsets.only(top: ScreenUtil().setWidth(50)):EdgeInsets.only(top: ScreenUtil().setWidth(0)),
  115. child: ListView(
  116. controller: _scrollController,
  117. children: <Widget>[
  118. LableTitle(
  119. title: "品牌简介",
  120. isMore: false,
  121. ),
  122. Container(
  123. height: 130,
  124. padding: EdgeInsets.only(
  125. left: ScreenUtil().setWidth(15),
  126. right: ScreenUtil().setWidth(15),
  127. bottom: ScreenUtil().setWidth(40)),
  128. child: Row(
  129. crossAxisAlignment: CrossAxisAlignment.center,
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. children: <Widget>[
  132. Container(
  133. width: ScreenUtil().setWidth(90),
  134. height: ScreenUtil().setWidth(80),
  135. // color: Colors.red,
  136. child: LoadNetworkImage(
  137. detailObj.logo,
  138. fit: BoxFit.cover,
  139. ),
  140. ),
  141. SizedBox(width: 10),
  142. Expanded(
  143. child: Text(
  144. detailObj.descr ?? '',
  145. overflow: TextOverflow.ellipsis,
  146. maxLines: 3,
  147. style: TextStyle(
  148. fontSize: ScreenUtil().setSp(15)),
  149. textAlign: TextAlign.start,
  150. ),
  151. )
  152. ]),
  153. ),
  154. Container(
  155. height: 5,
  156. color: Color(0xffF8F8F8),
  157. ),
  158. LableTitle(
  159. title: "品牌资料",
  160. isMore: false,
  161. ),
  162. Container(
  163. padding: EdgeInsets.only(
  164. top: ScreenUtil().setWidth(10),
  165. bottom: ScreenUtil().setWidth(30)),
  166. child: Column(
  167. mainAxisAlignment: MainAxisAlignment.start,
  168. crossAxisAlignment: CrossAxisAlignment.start,
  169. children: <Widget>[
  170. // BrandFile(initList: brandFileList),
  171. brandFileList.length > 0
  172. ? BrandFile(initList: brandFileList, brandId: widget.id)
  173. : Center(child:Text("暂无数据"))
  174. ]),
  175. ),
  176. Container(
  177. height: 5,
  178. color: Color(0xffF8F8F8),
  179. ),
  180. LableTitle(
  181. title: "错误代码库",
  182. userTap: () {
  183. NavigatorUtils.push(context,
  184. "${MeansRouter.errorList}?id=${widget.id.toString()}");
  185. },
  186. ),
  187. _hasCodeData
  188. ? ErrorCode(
  189. lists: codeList,
  190. )
  191. : loadCircle(),
  192. SizedBox(
  193. height: 10,
  194. )
  195. ]),
  196. )
  197. ],
  198. ))
  199. : Center(
  200. child: Text("正在加载..."),
  201. ));
  202. }
  203. Widget loadCircle() {
  204. return Container(
  205. padding: EdgeInsets.only(top: 10, bottom: 10),
  206. color: ThemeUtils.getTabsBg(context),
  207. child: Center(
  208. child: SpinKitFadingCircle(
  209. color: Colors.blueAccent,
  210. size: 30.0,
  211. ),
  212. ),
  213. );
  214. }
  215. Widget detailWidget() {
  216. return Container(
  217. padding: EdgeInsets.only(top: 10, bottom: 10),
  218. color: Colors.white,
  219. child: Center(
  220. child: SpinKitFadingCircle(
  221. color: Colors.blueAccent,
  222. size: 30.0,
  223. ),
  224. ),
  225. );
  226. }
  227. }
  228. class CategorysNav extends StatelessWidget {
  229. CategorysNav({Key key, this.lists, this.typeIndex, this.fun})
  230. : super(key: key);
  231. List<dynamic> lists = [];
  232. int typeIndex;
  233. Function fun;
  234. @override
  235. Widget build(BuildContext context) {
  236. return Positioned(
  237. child: Container(
  238. color: Color(0xffFAF7FA),
  239. child: Row(
  240. children: typeList(context),
  241. )),
  242. );
  243. }
  244. List<Widget> typeList(context) => lists.asMap().keys.map((index) {
  245. double width = MediaQuery.of(context).size.width;
  246. return Container(
  247. width: width / (lists.length),
  248. padding: EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  249. child: Row(
  250. mainAxisAlignment: MainAxisAlignment.center,
  251. children: <Widget>[
  252. GestureDetector(
  253. onTap: () {
  254. fun(index);
  255. },
  256. child: Container(
  257. padding:
  258. EdgeInsets.only(bottom: ScreenUtil().setWidth(10)),
  259. decoration: BoxDecoration(
  260. border: Border(
  261. bottom: BorderSide(
  262. width: 3,
  263. color: typeIndex == index
  264. ? Color(0xff02A0FD)
  265. : Color(0xffFAF7FA)),
  266. ),
  267. ),
  268. child: Text(
  269. lists[index].name,
  270. style: TextStyle(
  271. color: Color(0xfff333333),
  272. fontSize: ScreenUtil().setSp(16)),
  273. textAlign: TextAlign.center,
  274. ),
  275. ))
  276. ]));
  277. }).toList();
  278. }
  279. class ErrorCode extends StatelessWidget {
  280. ErrorCode({Key key, this.lists}) : super(key: key);
  281. List<dynamic> lists = [];
  282. @override
  283. Widget build(BuildContext context) {
  284. return Container(
  285. // margin: EdgeInsets.symmetric(vertical: 5, horizontal: 5),
  286. padding: EdgeInsets.only(
  287. top: ScreenUtil().setWidth(5),
  288. left: ScreenUtil().setWidth(15),
  289. right: ScreenUtil().setWidth(15)),
  290. child: Wrap(
  291. spacing: 13,
  292. runSpacing : 10,
  293. alignment: WrapAlignment.start,
  294. crossAxisAlignment: WrapCrossAlignment.center,
  295. children: errorList(context),
  296. // children: (lists != null && lists.length > 0)
  297. // ? errorList(context)
  298. // : loadCircle(),
  299. ));
  300. }
  301. List<Widget> errorList(context) => lists.map((item) {
  302. double width = MediaQuery.of(context).size.width;
  303. return Container(
  304. // color:Colors.yellow,
  305. height: 30,
  306. width: width*0.28,
  307. padding: EdgeInsets.all(0),
  308. decoration: BoxDecoration(
  309. borderRadius: BorderRadius.circular(2.0),
  310. color: Color(0xff9FD1FE),
  311. ),
  312. child:
  313. GestureDetector(
  314. onTap: () {
  315. NavigatorUtils.push(context,
  316. "${MeansRouter.errorDetail}?id=${item.id.toString()}");
  317. },
  318. child: Container(
  319. // width: 90,
  320. padding: EdgeInsets.only(
  321. left: ScreenUtil().setWidth(10),
  322. right: ScreenUtil().setWidth(10),
  323. top: ScreenUtil().setWidth(5),
  324. // bottom: ScreenUtil().setWidth(5)
  325. ),
  326. child: Text(
  327. item.code,
  328. style: TextStyle(
  329. color: Color(0xffffffff), fontSize: ScreenUtil().setSp(15)),
  330. textAlign: TextAlign.center,
  331. maxLines: 1,
  332. overflow: TextOverflow.ellipsis,
  333. ),
  334. ),
  335. )
  336. // GestureDetector(
  337. // child: Container(
  338. // // width: 90,
  339. // margin: EdgeInsets.all(4),
  340. // // padding: EdgeInsets.only(
  341. // // left: ScreenUtil().setWidth(10),
  342. // // right: ScreenUtil().setWidth(10),
  343. // // top: ScreenUtil().setWidth(5),
  344. // // // bottom: ScreenUtil().setWidth(5)
  345. // // ),
  346. // child: Text(
  347. // item.code,
  348. // style: TextStyle(
  349. // color: Color(0xffffffff), fontSize: ScreenUtil().setSp(15)),
  350. // textAlign: TextAlign.center,
  351. // ),
  352. // ),
  353. // onTap: () {
  354. // NavigatorUtils.push(context,
  355. // "${MeansRouter.errorDetail}?id=${item.id.toString()}");
  356. // },
  357. // ),
  358. );
  359. }).toList();
  360. Widget loadCircle(context) {
  361. return Container(
  362. padding: EdgeInsets.only(top: 10, bottom: 10),
  363. color: ThemeUtils.getTabsBg(context),
  364. child: Center(
  365. child: SpinKitFadingCircle(
  366. color: Colors.blueAccent,
  367. size: 30.0,
  368. ),
  369. ),
  370. );
  371. }
  372. }
  373. class BrandFile extends StatelessWidget {
  374. BrandFile({Key key, this.initList, this.brandId}) : super(key: key);
  375. List<dynamic> initList;
  376. String brandId;
  377. List<Widget> brandList(context) => initList.map((item) {
  378. double width = MediaQuery.of(context).size.width;
  379. return Container(
  380. width: width / 3,
  381. child: FlatButton(
  382. padding: EdgeInsets.all(0),
  383. highlightColor: Colors.white,
  384. splashColor: Colors.white,
  385. child: Container(
  386. // width: 90,
  387. height: ScreenUtil().setWidth(80),
  388. // color: Colors.red,
  389. padding: EdgeInsets.only(
  390. left: ScreenUtil().setWidth(10),
  391. right: ScreenUtil().setWidth(10),
  392. top: ScreenUtil().setWidth(10)),
  393. child: Column(
  394. mainAxisAlignment: MainAxisAlignment.start,
  395. children: <Widget>[
  396. Container(
  397. child: LoadNetworkImage(
  398. item.icon,
  399. width: ScreenUtil().setWidth(50),
  400. height: ScreenUtil().setWidth(30),
  401. // alignment: Alignment.centerLeft,
  402. ),
  403. ),
  404. SizedBox(height: 10),
  405. Container(
  406. child: Text(
  407. item.name ?? '',
  408. style: TextStyle(
  409. color: Color(0xff666666),
  410. fontSize: ScreenUtil().setSp(14)),
  411. textAlign: TextAlign.center,
  412. overflow: TextOverflow.ellipsis,
  413. ),
  414. ),
  415. ]),
  416. ),
  417. onPressed: () {
  418. NavigatorUtils.push(context, "${MeansRouter.meansList}?catagoryId=${item.id.toString()}&dataTable=2&brandId=${brandId}");
  419. },
  420. ),
  421. );
  422. }).toList();
  423. @override
  424. Widget build(BuildContext context) {
  425. return Container(
  426. padding: EdgeInsets.only(top: 5),
  427. child: Wrap(
  428. children: brandList(context),
  429. ));
  430. }
  431. }