brand_detail.dart 15 KB

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