coupon_page.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:liftmanager/internal/bbs/model/coupon_model_page.dart';
  5. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  6. import 'package:liftmanager/internal/wode/presenter/red_list_presenter.dart';
  7. import 'package:liftmanager/mvp/base_page_state.dart';
  8. import 'package:liftmanager/utils/time_format.dart';
  9. import 'package:liftmanager/widgets/app_bar.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/widgets/my_refresh_list.dart';
  12. import 'package:liftmanager/widgets/state_layout.dart';
  13. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  14. import 'package:provider/provider.dart';
  15. class CouponPage extends StatefulWidget {
  16. @override
  17. CouponPageState createState() => CouponPageState();
  18. }
  19. class CouponPageState extends BasePageState<CouponPage, CoupontListPresenter>
  20. with AutomaticKeepAliveClientMixin {
  21. static const staticList = [
  22. {
  23. "price": "5",
  24. "time": "2019-12-30",
  25. },
  26. {
  27. "price": "5",
  28. "time": "2019-12-30",
  29. },
  30. {
  31. "price": "5",
  32. "time": "2019-12-30",
  33. },
  34. {
  35. "price": "5",
  36. "time": "2019-12-30",
  37. },
  38. {
  39. "price": "5",
  40. "time": "2019-12-30",
  41. },
  42. {
  43. "price": "5",
  44. "time": "2019-12-30",
  45. },
  46. {
  47. "price": "5",
  48. "time": "2019-12-30",
  49. },
  50. {
  51. "price": "5",
  52. "time": "2019-12-30",
  53. },
  54. {
  55. "price": "5",
  56. "time": "2019-12-30",
  57. },
  58. ];
  59. int checkIndex = 0;
  60. // NewsDetailItem item = NewsDetailItem();
  61. BaseListProvider<Records> provider = BaseListProvider<Records>();
  62. int usedFlag = 1; //0失效1可使用
  63. int _page = 1;
  64. ScrollController _scrollController = new ScrollController();
  65. @override
  66. CoupontListPresenter createPresenter() {
  67. return CoupontListPresenter();
  68. }
  69. @override
  70. void dispose() {
  71. _scrollController.dispose();
  72. super.dispose();
  73. }
  74. @override
  75. void initState() {
  76. provider.setStateTypeNotNotify(StateType.loading);
  77. super.initState();
  78. _onRefresh();
  79. print(66666);
  80. }
  81. // getScenario(int type) {
  82. // String str;
  83. // if (type == 0) {
  84. // str = "全场通用";
  85. // } else if (type == 1) {
  86. // str = "仅限出诊问诊服务";
  87. // } else if (type == 2) {
  88. // str = "仅限题库";
  89. // } else if (type == 3) {
  90. // str = "仅限视频";
  91. // }
  92. // return str;
  93. // }
  94. getScenario(int type) {
  95. String str;
  96. if (type == 0) {
  97. str = "全场通用";
  98. } else if (type == 1) {
  99. str = "出诊问诊服务";
  100. } else if (type == 2) {
  101. str = "题库";
  102. } else if (type == 3) {
  103. str = "视频";
  104. }
  105. return str;
  106. }
  107. Future _onRefresh() async {
  108. _page = 1;
  109. await presenter.getRedList(_page, usedFlag);
  110. }
  111. Future _loadMore() async {
  112. _page++;
  113. await presenter.getRedList(_page, usedFlag);
  114. }
  115. bool get wantKeepAlive => true;
  116. @override
  117. Widget build(BuildContext context) {
  118. double width = MediaQuery.of(context).size.width;
  119. return ChangeNotifierProvider<BaseListProvider<Records>>(
  120. create: (_) => provider,
  121. child: Scaffold(
  122. resizeToAvoidBottomPadding: true,
  123. appBar: MyAppBar(centerTitle: "我的优惠券"),
  124. body: Container(
  125. // color: Color(0xFFF1F4FC),
  126. child: Column(
  127. crossAxisAlignment: CrossAxisAlignment.start,
  128. children: <Widget>[
  129. Container(
  130. padding: EdgeInsets.only(bottom: 5),
  131. // color:Color(0xffFAF7FA),
  132. decoration: BoxDecoration(
  133. border: Border(
  134. bottom:
  135. BorderSide(width: 0.5, color: Color(0xffeeeeee)),
  136. ),
  137. // color: Color(0xff9FD1FE),
  138. ),
  139. child: Row(children: <Widget>[
  140. Container(
  141. width: width / 2,
  142. padding: EdgeInsets.only(top: 10),
  143. child: Row(
  144. mainAxisAlignment: MainAxisAlignment.center,
  145. children: <Widget>[
  146. GestureDetector(
  147. onTap: () {
  148. print(6663);
  149. provider.list.clear();
  150. setState(() {
  151. checkIndex = 0;
  152. usedFlag = 1;
  153. });
  154. _onRefresh();
  155. },
  156. child: Container(
  157. padding: EdgeInsets.only(bottom: 6),
  158. decoration: BoxDecoration(
  159. border: Border(
  160. bottom: BorderSide(
  161. width: 2,
  162. color: checkIndex == 0
  163. ? Color(0xff02A0FD)
  164. : Colors.white),
  165. ),
  166. // color: Color(0xff9FD1FE),
  167. ),
  168. child: Text(
  169. '可使用',
  170. style: TextStyle(
  171. color: checkIndex == 0
  172. ? Color(0xff02A0FD)
  173. : Color(0xff666666),
  174. // fontSize:ScreenUtil().setSp(14)
  175. ),
  176. textAlign: TextAlign.center,
  177. ),
  178. ))
  179. ])),
  180. Container(
  181. width: width / 2,
  182. padding:
  183. EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  184. child: Row(
  185. mainAxisAlignment: MainAxisAlignment.center,
  186. children: <Widget>[
  187. GestureDetector(
  188. onTap: () {
  189. // Provider.of<BaseListProvider<Records>>(context,listen: false).list.clear();
  190. provider.list.clear();
  191. setState(() {
  192. checkIndex = 1;
  193. usedFlag = 0;
  194. });
  195. _onRefresh();
  196. },
  197. child: Container(
  198. padding: EdgeInsets.only(bottom: 6),
  199. decoration: BoxDecoration(
  200. border: Border(
  201. bottom: BorderSide(
  202. width: 2,
  203. color: checkIndex == 1
  204. ? Color(0xff02A0FD)
  205. : Colors.transparent),
  206. ),
  207. ),
  208. child: Text(
  209. '已失效',
  210. style: TextStyle(
  211. color: checkIndex == 1
  212. ? Color(0xff02A0FD)
  213. : Color(0xff666666),
  214. // fontSize:ScreenUtil().setSp(14)
  215. ),
  216. textAlign: TextAlign.center,
  217. ),
  218. ))
  219. ])),
  220. ])),
  221. Expanded(
  222. flex: 1,
  223. child: Consumer<BaseListProvider<Records>>(
  224. builder: (_, provider, __) {
  225. return MyListView(
  226. key: Key('coupon_list'),
  227. itemCount: provider.list.length,
  228. stateType: provider.stateType,
  229. onRefresh: _onRefresh,
  230. loadMore: _loadMore,
  231. pageSize: 8,
  232. hasMore: provider.hasMore,
  233. itemBuilder: (_, index) {
  234. return Container(
  235. child: Column(
  236. children: <Widget>[
  237. Container(
  238. child: Row(children: <Widget>[
  239. Container(
  240. padding: EdgeInsets.only(
  241. top: 10,
  242. ),
  243. child: Stack(
  244. children: <Widget>[
  245. Positioned(
  246. top: 0,
  247. left: -10,
  248. // right: -30,
  249. child: Container(
  250. width: width + 10,
  251. height: 122,
  252. child: LoadAssetImage(
  253. // image: AssetImage(i['img']),
  254. checkIndex == 0
  255. ? "wode/bg_front"
  256. : "wode/bg_back",
  257. fit: BoxFit.fill,
  258. // alignment: Alignment.centerLeft,
  259. ),
  260. )),
  261. Container(
  262. // decoration: BoxDecoration(
  263. // border:Border.all(
  264. // width:2,
  265. // color:Colors.red
  266. // )
  267. // ),
  268. width: width,
  269. height: 120,
  270. child: Row(
  271. children: <Widget>[
  272. Container(
  273. padding: EdgeInsets.only(
  274. right: 10, left: 15),
  275. child: Column(
  276. crossAxisAlignment:
  277. CrossAxisAlignment
  278. .start,
  279. mainAxisAlignment:
  280. MainAxisAlignment
  281. .center,
  282. children: <Widget>[
  283. Container(
  284. width: 120,
  285. child: Row(
  286. crossAxisAlignment:
  287. CrossAxisAlignment
  288. .end,
  289. mainAxisAlignment:
  290. MainAxisAlignment
  291. .center,
  292. children: <Widget>[
  293. Text(
  294. '¥',
  295. textAlign:
  296. TextAlign
  297. .center,
  298. style: TextStyle(
  299. fontSize: ScreenUtil()
  300. .setSp(
  301. 16),
  302. color: Colors
  303. .white),
  304. ),
  305. Text(
  306. // '999.0',
  307. provider
  308. .list[index]
  309. .coupon
  310. ?.discount
  311. ?.toString(),
  312. textAlign:
  313. TextAlign
  314. .left,
  315. style: TextStyle(
  316. fontSize: ScreenUtil()
  317. .setSp(
  318. 28),
  319. color: Colors
  320. .white,
  321. fontWeight:
  322. FontWeight
  323. .bold),
  324. ),
  325. SizedBox(
  326. width: 10,
  327. )
  328. ],
  329. ),
  330. ),
  331. Container(
  332. margin:
  333. EdgeInsets.only(
  334. left: 30),
  335. padding: EdgeInsets
  336. .fromLTRB(
  337. 5, 1, 5, 1),
  338. child: Text(
  339. // getScenario(provider
  340. // .list[index]
  341. // .coupon
  342. // ?.scenario ??
  343. // 0),
  344. '代金劵',
  345. textAlign: TextAlign
  346. .center,
  347. style: TextStyle(
  348. fontSize:
  349. ScreenUtil()
  350. .setSp(
  351. 11),
  352. color: Colors
  353. .white),
  354. ),
  355. decoration:
  356. new BoxDecoration(
  357. //背景
  358. // color: Colors.white,
  359. //设置四周圆角 角度
  360. borderRadius:
  361. BorderRadius
  362. .all(Radius
  363. .circular(
  364. 4.0)),
  365. //设置四周边框
  366. border: Border.all(
  367. width: 1,
  368. color: Colors
  369. .white),
  370. ),
  371. ),
  372. ]),
  373. ),
  374. Container(
  375. padding: EdgeInsets.only(
  376. top: 30),
  377. child: Column(
  378. crossAxisAlignment:
  379. CrossAxisAlignment
  380. .start,
  381. children: <Widget>[
  382. Text(
  383. '${getScenario(provider.list[index].coupon?.scenario ?? 0)}${provider.list[index].coupon?.name ?? ""}',
  384. textAlign:
  385. TextAlign.left,
  386. style: TextStyle(
  387. fontSize:
  388. ScreenUtil()
  389. .setSp(
  390. 17),
  391. color: Color(
  392. 0xff333333),
  393. ),
  394. ),
  395. Text(
  396. '有效时间: ' +
  397. DateUtils.instance.getFormartData(
  398. timeSamp: provider
  399. .list[
  400. index]
  401. .coupon
  402. ?.validity,
  403. format:
  404. "yyyy.MM.dd HH:mm"),
  405. textAlign:
  406. TextAlign.left,
  407. style: TextStyle(
  408. fontSize:
  409. ScreenUtil()
  410. .setSp(
  411. 13),
  412. color: Color(
  413. 0xff9F9C9F),
  414. ),
  415. ),
  416. SizedBox(height: 20),
  417. Container(
  418. width: width * 0.5,
  419. height: 0.5,
  420. color: Color(
  421. 0xffeeeeee),
  422. child: null,
  423. ),
  424. SizedBox(height: 3),
  425. Text(
  426. provider
  427. .list[index]
  428. .coupon
  429. ?.remark ??
  430. "",
  431. textAlign:
  432. TextAlign.left,
  433. style: TextStyle(
  434. fontSize:
  435. ScreenUtil()
  436. .setSp(
  437. 13),
  438. color: Color(
  439. 0xff9F9C9F),
  440. ),
  441. ),
  442. ])),
  443. ],
  444. )),
  445. // Positioned(
  446. // top: 0,
  447. // right: 5,
  448. // child: checkIndex == 1
  449. // ? Container(
  450. // child: Icon(
  451. // const IconData(0xe6d9,
  452. // fontFamily: "myfont"),
  453. // size: 50.0,
  454. // color: Color(0xff999999),
  455. // ),
  456. // )
  457. // : Container(child: null))
  458. ],
  459. ),
  460. ),
  461. Container()
  462. ]))
  463. ],
  464. ),
  465. );
  466. },
  467. );
  468. }))
  469. ],
  470. ),
  471. ),
  472. ));
  473. }
  474. }