YSCouponChild.dart 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/version3/view/YSCouponCardView.dart';
  4. import '../../base/YSBase.dart';
  5. import '../../base/YSNetWorking.dart';
  6. import '../../base/YSTools.dart';
  7. import '../YSCouponHelp.dart';
  8. import '../YSInstitution.dart';
  9. import '../YSWriteOff.dart';
  10. class YSCouponChild extends StatefulWidget {
  11. const YSCouponChild({Key key}) : super(key: key);
  12. @override
  13. _YSCouponChildState createState() => _YSCouponChildState();
  14. }
  15. class _YSCouponChildState extends State<YSCouponChild> {
  16. List _array = [];
  17. List _enumArray = [
  18. {'image':'医院列表','title':'医疗机构'},
  19. {'image':'核销记录','title':'核销记录'},
  20. {'image':'使用帮助 (1)','title':'使用帮助'}
  21. ];
  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 NotificationListener<CustomerNotification>(
  76. onNotification: (value){
  77. _getCouponData();
  78. return true;
  79. },
  80. child: YSBase(
  81. ystitle: '儿童两筛电子券',
  82. yschild: Stack(
  83. children: [
  84. Container(
  85. height: 30,
  86. color: Color(0xFFDB5278),
  87. ),
  88. Column(
  89. children: [
  90. Container(
  91. height: 120,
  92. margin: EdgeInsets.only(left: 15,right: 15,bottom: 20),
  93. decoration: BoxDecoration(
  94. color: Colors.white,
  95. borderRadius: BorderRadius.all(Radius.circular(10))
  96. ),
  97. child: GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  98. crossAxisCount: 3
  99. ), itemBuilder: (context,index){
  100. Map item = _enumArray[index];
  101. return GestureDetector(
  102. onTap: (){
  103. Navigator.of(context,rootNavigator: true).push(
  104. CupertinoPageRoute(builder: (context){
  105. return index==0?YSInstitution():index==1?YSWriteOff():YSCouponHelp();
  106. })
  107. );
  108. },
  109. behavior: HitTestBehavior.opaque,
  110. child: Container(
  111. alignment: Alignment.center,
  112. child: LayoutBuilder(
  113. builder: (context,conSize) {
  114. return Column(
  115. mainAxisSize: MainAxisSize.min,
  116. children: [
  117. Image.asset('lib/images/${item['image']}.png',height: conSize.maxWidth/4,width: conSize.maxWidth/4,),
  118. Container(
  119. child: Text(item['title'],style: TextStyle(fontSize: 14,color: Color(0xFF323233)),),
  120. margin: EdgeInsets.only(top: 10),
  121. )
  122. ],
  123. );
  124. },
  125. ),
  126. ),
  127. );
  128. },itemCount: _enumArray.length,padding: EdgeInsets.all(0),),
  129. // alignment: Alignment.centerRight,
  130. // child: Row(
  131. // mainAxisSize: MainAxisSize.min,
  132. // children: [
  133. // GestureDetector(
  134. // child: SizedBox(
  135. // child: Text('使用帮助',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),),
  136. // width: 60,
  137. // ),
  138. // onTap: (){
  139. // Navigator.of(context,rootNavigator: true).push(
  140. // CupertinoPageRoute(builder: (context){
  141. // return YSCouponHelp();
  142. // })
  143. // );
  144. // },
  145. // behavior: HitTestBehavior.opaque,
  146. // ),
  147. // PopupMenuButton(
  148. // itemBuilder: (BuildContext context){
  149. // return [
  150. // PopupMenuItem(child: Text("核销记录",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "1",),
  151. // PopupMenuItem(child: Text("机构列表",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "2",),
  152. // ];
  153. // },
  154. // icon: Container(
  155. // child: Text('更多',style: TextStyle(fontSize: 12,color: Color(0xFFE78CA9)),),
  156. // alignment: Alignment.centerRight,
  157. // width: 40,
  158. // ),
  159. // onSelected: (value){
  160. // if(value=='1'){
  161. // Navigator.of(context,rootNavigator: true).push(
  162. // CupertinoPageRoute(builder: (context){
  163. // return YSWriteOff();
  164. // })
  165. // );
  166. // }else{
  167. // Navigator.of(context,rootNavigator: true).push(
  168. // CupertinoPageRoute(builder: (context){
  169. // return YSInstitution();
  170. // })
  171. // );
  172. // }
  173. // },
  174. // )
  175. // // Image.asset('lib/images/fy_help.png',height: 20,width: 20,)
  176. // ],
  177. // ),
  178. ),
  179. Container(
  180. height: ysHeight(context)-ysTOP(context)-190,
  181. width: ysWidth(context),
  182. child: RefreshIndicator(
  183. onRefresh: _getCouponData,
  184. child: _array.isEmpty?Center(
  185. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  186. ):ListView.separated(itemBuilder: (context,indexSub){
  187. Map itemSub = _array[indexSub];
  188. itemSub['type'] = '2';
  189. return YSCouponCardNewView(item: itemSub,array: _array,);
  190. },
  191. separatorBuilder: (context,indexSub){
  192. return Container(height: 15,);
  193. },
  194. itemCount: _array.length,
  195. padding: EdgeInsets.only(left: 15,right: 15,bottom: 15),
  196. ),
  197. ),
  198. )
  199. ],
  200. )
  201. ],
  202. ),
  203. ),
  204. );
  205. }
  206. }