YSCouponMom.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSBase.dart';
  4. import 'package:flutterappfuyou/code/base/YSTools.dart';
  5. import '../../base/YSNetWorking.dart';
  6. import '../YSCouponHelp.dart';
  7. import '../YSInstitution.dart';
  8. import '../YSWriteOff.dart';
  9. import 'YSCouponCardView.dart';
  10. class YSCouponMom extends StatefulWidget {
  11. const YSCouponMom({Key key}) : super(key: key);
  12. @override
  13. _YSCouponMomState createState() => _YSCouponMomState();
  14. }
  15. class _YSCouponMomState extends State<YSCouponMom> {
  16. List _enumArray = [
  17. {'image':'医院列表','title':'医疗机构'},
  18. {'image':'核销记录','title':'核销记录'},
  19. {'image':'使用帮助 (1)','title':'使用帮助'}
  20. ];
  21. List _array = [];
  22. Future<void> _getCouponData() async{
  23. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getUserCouponList', {'idcard':User().idCard});
  24. if(dict!=null){
  25. if(dict['data'] is List){
  26. _array.clear();
  27. setState(() {});
  28. return;
  29. }
  30. List dataArray = [];
  31. Map data = dict['data']??{};
  32. data.forEach((key, value) {
  33. String title = '';
  34. bool isHelp = false;
  35. if(key=='pregnantWoman'){
  36. title = '母亲筛查服务券';
  37. isHelp = true;
  38. }else if(key=='infant'){
  39. title = '新生儿筛查服务券';
  40. isHelp = false;
  41. }
  42. List keyArray = data[key]??[];
  43. Map map = {'title':title,'isHelp':isHelp};
  44. List array = [];
  45. for(Map element in keyArray){
  46. List receivedCouponVoList = element['receivedCouponVoList']??[];
  47. for(Map elementSub in receivedCouponVoList){
  48. elementSub['count'] = '${receivedCouponVoList.length}';
  49. elementSub['typeId'] = int.parse(element['typeId']);
  50. array.add(elementSub);
  51. }
  52. }
  53. map['array'] = array;
  54. dataArray.add(map);
  55. });
  56. Map item = dataArray.firstWhere((element) => element['title']=='母亲筛查服务券',orElse: ()=>{});
  57. if(item.isNotEmpty){
  58. _array = item['array']??[];
  59. setState(() {});
  60. }else{
  61. _array.clear();
  62. setState(() {});
  63. }
  64. }
  65. }
  66. @override
  67. void initState() {
  68. Future.delayed(Duration(seconds: 0)).then((value) {
  69. _getCouponData();
  70. });
  71. super.initState();
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. return YSBase(
  76. ystitle: '母亲两筛电子券',
  77. ysBgColor: Color(0xFFF1F1F1),
  78. yschild: NotificationListener<CustomerNotification>(
  79. onNotification: (value){
  80. _getCouponData();
  81. return true;
  82. },
  83. child: Stack(
  84. children: [
  85. Container(
  86. height: 30,
  87. color: Color(0xFFDB5278),
  88. ),
  89. Column(
  90. children: [
  91. Container(
  92. height: 120,
  93. margin: EdgeInsets.only(left: 15,right: 15,bottom: 20),
  94. decoration: BoxDecoration(
  95. color: Colors.white,
  96. borderRadius: BorderRadius.all(Radius.circular(10))
  97. ),
  98. child: GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  99. crossAxisCount: 3
  100. ), itemBuilder: (context,index){
  101. Map item = _enumArray[index];
  102. return GestureDetector(
  103. onTap: (){
  104. Navigator.of(context,rootNavigator: true).push(
  105. CupertinoPageRoute(builder: (context){
  106. return index==0?YSInstitution():index==1?YSWriteOff():YSCouponHelp();
  107. })
  108. );
  109. },
  110. behavior: HitTestBehavior.opaque,
  111. child: Container(
  112. alignment: Alignment.center,
  113. child: LayoutBuilder(
  114. builder: (context,conSize) {
  115. return Column(
  116. mainAxisSize: MainAxisSize.min,
  117. children: [
  118. Image.asset('lib/images/${item['image']}.png',height: conSize.maxWidth/4,width: conSize.maxWidth/4,),
  119. Container(
  120. child: Text(item['title'],style: TextStyle(fontSize: 14,color: Color(0xFF323233)),),
  121. margin: EdgeInsets.only(top: 10),
  122. )
  123. ],
  124. );
  125. },
  126. ),
  127. ),
  128. );
  129. },itemCount: _enumArray.length,padding: EdgeInsets.all(0),),
  130. // alignment: Alignment.centerRight,
  131. // child: Row(
  132. // mainAxisSize: MainAxisSize.min,
  133. // children: [
  134. // GestureDetector(
  135. // child: SizedBox(
  136. // child: Text('使用帮助',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),),
  137. // width: 60,
  138. // ),
  139. // onTap: (){
  140. // Navigator.of(context,rootNavigator: true).push(
  141. // CupertinoPageRoute(builder: (context){
  142. // return YSCouponHelp();
  143. // })
  144. // );
  145. // },
  146. // behavior: HitTestBehavior.opaque,
  147. // ),
  148. // PopupMenuButton(
  149. // itemBuilder: (BuildContext context){
  150. // return [
  151. // PopupMenuItem(child: Text("核销记录",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "1",),
  152. // PopupMenuItem(child: Text("机构列表",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "2",),
  153. // ];
  154. // },
  155. // icon: Container(
  156. // child: Text('更多',style: TextStyle(fontSize: 12,color: Color(0xFFE78CA9)),),
  157. // alignment: Alignment.centerRight,
  158. // width: 40,
  159. // ),
  160. // onSelected: (value){
  161. // if(value=='1'){
  162. // Navigator.of(context,rootNavigator: true).push(
  163. // CupertinoPageRoute(builder: (context){
  164. // return YSWriteOff();
  165. // })
  166. // );
  167. // }else{
  168. // Navigator.of(context,rootNavigator: true).push(
  169. // CupertinoPageRoute(builder: (context){
  170. // return YSInstitution();
  171. // })
  172. // );
  173. // }
  174. // },
  175. // )
  176. // // Image.asset('lib/images/fy_help.png',height: 20,width: 20,)
  177. // ],
  178. // ),
  179. ),
  180. Container(
  181. height: ysHeight(context)-ysTOP(context)-190,
  182. width: ysWidth(context),
  183. child: RefreshIndicator(
  184. onRefresh: _getCouponData,
  185. child: _array.isEmpty?Center(
  186. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  187. ):ListView.separated(itemBuilder: (context,indexSub){
  188. Map itemSub = _array[indexSub];
  189. itemSub['type'] = '1';
  190. return YSCouponCardNewView(item: itemSub,array: _array,);
  191. },
  192. separatorBuilder: (context,indexSub){
  193. return Container(height: 15,);
  194. },
  195. itemCount: _array.length,
  196. padding: EdgeInsets.only(left: 15,right: 15,bottom: 15),
  197. ),
  198. ),
  199. )
  200. ],
  201. )
  202. ],
  203. ),
  204. ),
  205. );
  206. }
  207. }