brand_detail.dart 16 KB

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