YSCommunityListItemView.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:qr_flutter/qr_flutter.dart';
  4. import 'package:wakelock/wakelock.dart';
  5. import '../../base/YSNetWorking.dart';
  6. import '../../base/YSTools.dart';
  7. import 'YSCouponCardView.dart';
  8. class YSCommunityListItemView extends StatefulWidget {
  9. final Map item;
  10. const YSCommunityListItemView({Key key, @required this.item}) : super(key: key);
  11. @override
  12. _YSCommunityListItemViewState createState() => _YSCommunityListItemViewState();
  13. }
  14. class _YSCommunityListItemViewState extends State<YSCommunityListItemView> {
  15. @override
  16. Widget build(BuildContext context) {
  17. String statusStr = widget.item['status']==0?'使用':widget.item['status']==1?'已使用':'已废弃';
  18. return GestureDetector(
  19. onTap: (){
  20. if(widget.item['status']==0){
  21. // ysShowCenterAlertView(context, YSTipsAlertView(
  22. // tipsStr: '是否确认使用社区服务体验券?',
  23. // valueSetter: (value){},
  24. // ));
  25. ysShowBottomAlertView(context, YSCommunityAlertView(item: widget.item,callback: (){
  26. CustomerNotification().dispatch(context);
  27. }),isBarr: true);
  28. }
  29. },
  30. behavior: HitTestBehavior.opaque,
  31. child: Container(
  32. height: 150,
  33. width: ysWidth(context)-30,
  34. decoration: BoxDecoration(
  35. image: DecorationImage(image: AssetImage('lib/images/${widget.item['status']==0?'fy_mf_coupon1':'fy_mf_coupon2'}.png'))
  36. ),
  37. child: Column(
  38. children: [
  39. Container(
  40. height: 50,
  41. width: ysWidth(context)-80,
  42. alignment: Alignment.centerLeft,
  43. child: RichText(
  44. maxLines: 1,
  45. text: TextSpan(
  46. text: '${widget.item['couponName']} ',
  47. style: TextStyle(fontSize: 18,color: Colors.white),
  48. children: [
  49. // TextSpan(
  50. // text: '${widget.item['pregnantWomanName']}',
  51. // style: TextStyle(fontSize: 12,color: Colors.white54)
  52. // )
  53. ]
  54. ),
  55. ),
  56. ),
  57. Container(
  58. height: 100,
  59. width: ysWidth(context)-80,
  60. alignment: Alignment.center,
  61. child: Column(
  62. mainAxisSize: MainAxisSize.min,
  63. children: [
  64. Container(
  65. child: Text('可用机构:${widget.item['hospitalName']}',style: TextStyle(fontSize: 14,color: Color(0xFF444444)),),
  66. alignment: Alignment.centerLeft,
  67. height: 20,
  68. ),
  69. Container(
  70. margin: EdgeInsets.only(top: 5,bottom: 5),
  71. child: Text('发券时间:${widget.item['createTime']}',style: TextStyle(fontSize: 14,color: Color(0xFF444444)),),
  72. alignment: Alignment.centerLeft,
  73. height: 20,
  74. ),
  75. Container(
  76. child: Row(
  77. children: [
  78. Container(
  79. child: Text(widget.item['writeOffTime']!=null?'使用时间:${widget.item['writeOffTime']}':'',style: TextStyle(fontSize: 14,color: Color(0xFF444444)),),
  80. width: ysWidth(context)-130,
  81. ),
  82. Container(
  83. width: 50,
  84. height: 20,
  85. decoration: BoxDecoration(
  86. color: widget.item['status']!=0?Color(0xFFBDBDBD):Color(0xFFF07F9E),
  87. borderRadius: BorderRadius.all(Radius.circular(50))
  88. ),
  89. child: Text(statusStr,style: TextStyle(fontSize: 10,color: Colors.white),),
  90. alignment: Alignment.center,
  91. )
  92. ],
  93. ),
  94. alignment: Alignment.centerLeft,
  95. height: 20,
  96. )
  97. ],
  98. ),
  99. )
  100. ],
  101. ),
  102. ),
  103. );
  104. }
  105. }
  106. class YSCommunityAlertView extends StatefulWidget {
  107. final Map item;
  108. final VoidCallback callback;
  109. const YSCommunityAlertView({Key key,this.item, @required this.callback}) : super(key: key);
  110. @override
  111. _YSCommunityAlertViewState createState() => _YSCommunityAlertViewState();
  112. }
  113. class _YSCommunityAlertViewState extends State<YSCommunityAlertView> {
  114. Timer _timer;
  115. String _codeStr = '';
  116. @override
  117. void initState() {
  118. getTimer();
  119. Wakelock.enable();
  120. YSScreenChange().change(255);
  121. Future.delayed(Duration(seconds: 0)).then((value) {
  122. _getCodeData();
  123. });
  124. super.initState();
  125. }
  126. _getCodeData() async{
  127. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getCommunityVerificationCode', {'idcard':User().idCard,'id':widget.item['id']});
  128. if(dict!=null){
  129. _codeStr = dict['message'];
  130. setState(() {});
  131. }
  132. }
  133. @override
  134. void dispose() {
  135. if(_timer!=null){
  136. _timer.cancel();
  137. }
  138. YSScreenChange().change(100);
  139. Wakelock.disable();
  140. super.dispose();
  141. }
  142. getTimer() {
  143. _timer =Timer.periodic(Duration(seconds: 3), (timer) async{
  144. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/verifiedCommunityVoucher', {'idcard':User().idCard,'couponId':widget.item['id']});
  145. if(dict!=null){
  146. bool isCheck = dict['data']??false;
  147. if(isCheck){
  148. ysShowCenterAlertView(context, YSWriteOffView(voidCallback: (){
  149. widget.callback();
  150. Navigator.pop(context);
  151. },),isTrans: true);
  152. // ysFlutterToast(context, '已核销');
  153. // widget.callback();
  154. // Navigator.pop(context);
  155. }
  156. }
  157. });
  158. }
  159. @override
  160. Widget build(BuildContext context) {
  161. return ClipRRect(
  162. borderRadius: BorderRadius.only(topRight: Radius.circular(20),topLeft: Radius.circular(20)),
  163. child: Container(
  164. height: 450,
  165. decoration: BoxDecoration(
  166. color: Color(0xFFF5F5F5),
  167. ),
  168. child: Column(
  169. children: [
  170. Container(
  171. color: Color(0xFFFF6D96),
  172. height: 50,
  173. width: MediaQuery.of(context).size.width,
  174. child: Row(
  175. children: [
  176. Container(
  177. width: ysWidth(context)-40,
  178. padding: EdgeInsets.only(left: 20,right: 20),
  179. child: Text(widget.item['couponName'],style: TextStyle(fontSize: 14,color: Colors.white),),
  180. alignment: Alignment.center,
  181. ),
  182. GestureDetector(
  183. onTap: (){Navigator.pop(context);},
  184. child: Image.asset('lib/images/clear_fy.png',height: 20,width: 20,),
  185. )
  186. ],
  187. ),
  188. ),
  189. SizedBox(
  190. height: 400,
  191. width: MediaQuery.of(context).size.width,
  192. child: Column(
  193. children: [
  194. GestureDetector(
  195. onTap: (){
  196. _getCodeData();
  197. },
  198. behavior: HitTestBehavior.opaque,
  199. child: Container(
  200. height: 200,
  201. width: 200,
  202. color: Colors.white,
  203. margin: EdgeInsets.only(top: 20),
  204. child: _codeStr.isNotEmpty?QrImage(data: _codeStr):SizedBox(),
  205. ),
  206. ),
  207. Container(
  208. height: 20,
  209. // child: Text('$_codeStr',style: TextStyle(fontSize: 16,color: Colors.grey),),
  210. alignment: Alignment.center,
  211. ),
  212. ClipRRect(
  213. child: Container(
  214. height: 160,
  215. color: Colors.white,
  216. width: ysWidth(context),
  217. child: Stack(
  218. children: [
  219. // Transform.rotate(
  220. // angle: 2,
  221. // child: Container(
  222. // color: Colors.red,
  223. // ),
  224. // ),
  225. Column(
  226. children: List.generate(
  227. 2,(index) => Expanded(
  228. child: Row(
  229. children: List.generate(
  230. 2,(index) => Expanded(
  231. child: Center(
  232. child: Transform.rotate(
  233. angle: -0.8,
  234. child: Text(
  235. '${widget.item['hospitalName']}',
  236. style: TextStyle(
  237. color: Color(0xFFC8C9CC).withOpacity(0.5),
  238. fontSize: 14,
  239. decoration: TextDecoration.none,
  240. ),
  241. ),
  242. ),
  243. ),
  244. ),
  245. ),
  246. ),
  247. ),
  248. ),
  249. ),
  250. Container(
  251. alignment: Alignment.center,
  252. padding: EdgeInsets.only(left: 20,right: 20),
  253. child: Column(
  254. mainAxisSize: MainAxisSize.min,
  255. children: [
  256. Container(
  257. height: 35,
  258. child: Text(widget.item['couponName'],style: TextStyle(fontSize: 18,color: Color(0xFF444444)),maxLines: 1,),
  259. alignment: Alignment.center,
  260. ),
  261. Container(
  262. height: 30,
  263. child: Text('发券机构:${widget.item['hospitalName']}',style: TextStyle(fontSize: 14,color: Color(0xFF444444)),maxLines: 1,),
  264. alignment: Alignment.center,
  265. ),
  266. Container(
  267. height: 30,
  268. child: Text('发券时间:${widget.item['createTime']}',style: TextStyle(fontSize: 14,color: Color(0xFF444444)),maxLines: 1,),
  269. alignment: Alignment.center,
  270. ),
  271. ],
  272. ),
  273. )
  274. ],
  275. ),
  276. ),
  277. )
  278. ],
  279. ),
  280. )
  281. ],
  282. ),
  283. ),
  284. );
  285. }
  286. }