YSCoupon.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. import 'dart:convert';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  5. import 'package:flutterappfuyou/code/version3/YSCouponHelp.dart';
  6. import 'package:flutterappfuyou/code/version3/YSInstitution.dart';
  7. import 'package:flutterappfuyou/code/version3/YSWriteOff.dart';
  8. import 'package:flutterappfuyou/code/version3/view/YSCommunityListItemView.dart';
  9. import 'package:flutterappfuyou/code/version3/view/YSCouponCardView.dart';
  10. import 'package:flutterappfuyou/code/version3/view/YSCouponChild.dart';
  11. import 'package:flutterappfuyou/code/version3/view/YSCouponCommunity.dart';
  12. import 'package:flutterappfuyou/code/version3/view/YSCouponMom.dart';
  13. import 'package:shared_preferences/shared_preferences.dart';
  14. import '../base/YSBase.dart';
  15. import '../base/YSTools.dart';
  16. class YSCoupon extends StatefulWidget {
  17. const YSCoupon({Key key}) : super(key: key);
  18. @override
  19. _YSCouponState createState() => _YSCouponState();
  20. }
  21. class _YSCouponState extends State<YSCoupon> {
  22. List _titles = [];
  23. List _dataArray= [];
  24. List _imageArray = [];
  25. Future<void> _getCommunityData() async{
  26. Map request = {};
  27. request['idcard'] = User().idCard;
  28. request['pageSize'] = 10;
  29. request['pageNum'] = 1;
  30. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getCommunityVouchers', request);
  31. if(dict!=null){
  32. if(dict['data'] is List){
  33. _getPicturesData();
  34. return;
  35. }
  36. _dataArray = dict['data']['data']['datas']??[];
  37. if(_dataArray.isEmpty){
  38. _getPicturesData();
  39. return;
  40. }
  41. _imageArray.clear();
  42. // LogUtil.d(dict['data']['show']);
  43. bool show = dict['data']['show']??false;
  44. _titles = [
  45. {'title':'母亲两筛电子券','type':1,'icon':'母亲信息备份'},
  46. {'title':'儿童两筛电子券','type':2,'icon':'婴儿票支持备份 3'},
  47. if(show){'title':'社区体检券','type':3,'icon':'我的体验卷'}
  48. ];
  49. _dataArray = dict['data']['datas']??[];
  50. setState(() {});
  51. _getKnowData();
  52. }
  53. }
  54. // Future<void> _getCouponData() async{
  55. // Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getUserCouponList', {'idcard':User().idCard});
  56. // if(dict!=null){
  57. // if(dict['data'] is List){
  58. // _getPicturesData();
  59. // return;
  60. // }
  61. // _imageArray.clear();
  62. // _titles = [
  63. // {'title':'母亲两筛电子券','type':1,'icon':'母亲信息备份'},
  64. // {'title':'儿童两筛电子券','type':2,'icon':'婴儿票支持备份 3'},
  65. // {'title':'社区体检券','type':3,'icon':'我的体验卷'}
  66. // ];
  67. // Map data = dict['data']??{};
  68. // data.forEach((key, value) {
  69. // String title = '';
  70. // bool isHelp = false;
  71. // if(key=='pregnantWoman'){
  72. // title = '母亲筛查服务券';
  73. // isHelp = true;
  74. // }else if(key=='infant'){
  75. // title = '新生儿筛查服务券';
  76. // isHelp = false;
  77. // }
  78. // List keyArray = data[key]??[];
  79. // Map map = {'title':title,'isHelp':isHelp};
  80. // List array = [];
  81. // for(Map element in keyArray){
  82. // List receivedCouponVoList = element['receivedCouponVoList']??[];
  83. // Map receivedCouponVoL = receivedCouponVoList.first;
  84. // receivedCouponVoL['count'] = '${receivedCouponVoList.length}';
  85. // array.add(receivedCouponVoL);
  86. // }
  87. // map['array'] = array;
  88. // _dataArray.add(map);
  89. // });
  90. // setState(() {});
  91. // LogUtil.d(_dataArray);
  92. // }
  93. // }
  94. _getPicturesData() async{
  95. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getPictures', {'idcard':User().idCard,'type':'PROPAGATE'});
  96. if(dict!=null){
  97. _imageArray = dict['data']??[];
  98. setState(() {});
  99. }
  100. }
  101. @override
  102. void initState() {
  103. Future.delayed(Duration(seconds: 0)).then((value) {
  104. // _getCouponData();
  105. _getCommunityData();
  106. });
  107. super.initState();
  108. }
  109. @override
  110. Widget build(BuildContext context) {
  111. return YSBase(
  112. ystitle: '券包',
  113. isBack: false,
  114. yschild: Container(
  115. width: ysWidth(context),
  116. child: RefreshIndicator(
  117. onRefresh: _getCommunityData,
  118. child: _imageArray.isNotEmpty?ListView.builder(
  119. itemBuilder: (context,index){
  120. String url = _imageArray[index];
  121. return GestureDetector(
  122. onTap: (){
  123. },
  124. child: Image.network(url,fit: BoxFit.fill,),
  125. );
  126. },
  127. itemCount: _imageArray.length,
  128. padding: EdgeInsets.all(0),
  129. ):ListView.builder(
  130. itemBuilder: (context,index){
  131. Map item = _titles[index];
  132. return GestureDetector(
  133. onTap: (){
  134. int type = item['type'];
  135. Navigator.of(context,rootNavigator: true).push(
  136. CupertinoPageRoute(builder: (context){
  137. return type==1?YSCouponMom():type==2?YSCouponChild():YSCouponCommunity();
  138. })
  139. ).then((value) {
  140. _getCommunityData();
  141. });
  142. },
  143. behavior: HitTestBehavior.opaque,
  144. child: Container(
  145. height: 50,
  146. decoration: BoxDecoration(
  147. border: Border(bottom: BorderSide(width: 1,color: Color(0xFFEBEDF0)))
  148. ),
  149. child: Row(
  150. children: [
  151. Image.asset('lib/images/${item['icon']}.png',height: 20,width: 20,),
  152. Expanded(child: Text(' ${item['title']}',style: TextStyle(fontSize: 17,color: Color(0xFF323233)),)),
  153. Icon(Icons.chevron_right,size: 20,color: Color(0xFF969799),)
  154. ],
  155. ),
  156. ),
  157. );
  158. },
  159. itemCount: _titles.length,
  160. padding: EdgeInsets.only(left: 15,right: 15,top: 10,bottom: 10),
  161. ),
  162. ),
  163. ),
  164. );
  165. }
  166. _getKnowData() async{
  167. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getClarionLetter', {'idcard':User().idCard});
  168. if(dict!=null){
  169. Map data = dict['data'];
  170. if(data['show']==true){
  171. showNegotiate3AlertDio(
  172. context,
  173. title: '告知书',
  174. content: data['data']??'',
  175. agree: () async{
  176. Map dict2 = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getClarionLetterAgree', {'idcard':User().idCard});
  177. if(dict2!=null){
  178. LogUtil.d(dict2);
  179. bool isAgree = dict2['data']??false;
  180. if(isAgree){}
  181. }
  182. },
  183. );
  184. }
  185. }
  186. // SharedPreferences preferences = await SharedPreferences.getInstance();
  187. // bool isKnow = preferences.getBool('isKnow')??false;
  188. // if(!isKnow){}
  189. }
  190. }
  191. class YSCoupon3 extends StatefulWidget {
  192. const YSCoupon3({Key key}) : super(key: key);
  193. @override
  194. _YSCoupon3State createState() => _YSCoupon3State();
  195. }
  196. class _YSCoupon3State extends State<YSCoupon3> with SingleTickerProviderStateMixin{
  197. List _titles = [
  198. {'title':'母亲两筛电子券','type':1},
  199. {'title':'儿童两筛电子券','type':2},
  200. {'title':'社区体检券','type':3}
  201. ];
  202. List _dataArray= [];
  203. List _imageArray = [];
  204. List _dataArray2= [
  205. {'status': 1,'depart':'郭杜卫生院','getDate':'2023-07-31 15:32','useDate':'2023-07-31 15:32','name':'社区免费体验券','tips':'19周进行胎儿的检查'},
  206. {'status': 2,'depart':'郭杜卫生院','getDate':'2023-07-31 15:32','useDate':'2023-07-31 15:32','name':'社区免费体验券','tips':'19周进行胎儿的检查'}
  207. ];
  208. TabController _tabController;
  209. @override
  210. void initState() {
  211. _tabController = TabController(
  212. vsync: this,
  213. length: _titles.length,
  214. );
  215. Future.delayed(Duration(seconds: 0)).then((value) {
  216. _getCouponData();
  217. });
  218. super.initState();
  219. }
  220. _getCouponData() async{
  221. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getUserCouponList', {'idcard':User().idCard});
  222. if(dict!=null){
  223. if(dict['data'] is List){
  224. _getPicturesData();
  225. return;
  226. }
  227. Map data = dict['data']??{};
  228. data.forEach((key, value) {
  229. String title = '';
  230. bool isHelp = false;
  231. if(key=='pregnantWoman'){
  232. title = '母亲筛查服务券';
  233. isHelp = true;
  234. }else if(key=='infant'){
  235. title = '新生儿筛查服务券';
  236. isHelp = false;
  237. }
  238. List keyArray = data[key]??[];
  239. Map map = {'title':title,'isHelp':isHelp};
  240. List array = [];
  241. for(Map element in keyArray){
  242. List receivedCouponVoList = element['receivedCouponVoList']??[];
  243. Map receivedCouponVoL = receivedCouponVoList.first;
  244. receivedCouponVoL['count'] = '${receivedCouponVoList.length}';
  245. array.add(receivedCouponVoL);
  246. }
  247. map['array'] = array;
  248. _dataArray.add(map);
  249. });
  250. setState(() {});
  251. }
  252. }
  253. _getPicturesData() async{
  254. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getPictures', {'idcard':User().idCard,'type':'PROPAGATE'});
  255. if(dict!=null){
  256. _imageArray = dict['data']??[];
  257. setState(() {});
  258. }
  259. }
  260. @override
  261. Widget build(BuildContext context) {
  262. return YSBase(
  263. ystitle: '券包',
  264. isBack: false,
  265. yschild: DefaultTabController(
  266. length: _titles.length,
  267. child: SingleChildScrollView(
  268. child: Column(
  269. children: [
  270. Container(
  271. height: 50,
  272. child: TabBar(
  273. controller: _tabController,
  274. indicatorColor: Color(0xFFEE6B8F),
  275. labelColor: Color(0xFFEE6B8F),
  276. indicatorWeight: 3,
  277. indicatorSize: TabBarIndicatorSize.label,
  278. labelStyle: TextStyle(fontSize: 14),
  279. unselectedLabelColor: Color(0xFFC8C9CC),
  280. // onTap: (value){
  281. // Navigator.of(context,rootNavigator: true).push(
  282. // CupertinoPageRoute(builder: (context){
  283. // return YSCouponHelp();
  284. // })
  285. // );
  286. // },
  287. tabs: _titles.map((f) {
  288. return Tab(
  289. child: Row(
  290. mainAxisSize: MainAxisSize.min,
  291. children: [
  292. Text(f['title'])
  293. ],
  294. ),
  295. );
  296. }).toList(),
  297. ),
  298. ),
  299. Container(
  300. height: ysHeight(context)-ysTOP(context)-142,
  301. child: TabBarView(
  302. controller: _tabController,
  303. children: _titles.map((f) {
  304. return f['type']==2?ListView.separated(
  305. itemBuilder: (context,index){
  306. Map item = _dataArray2[index];
  307. return YSCommunityListItemView(item: item);
  308. },
  309. separatorBuilder: (context,index){
  310. return Container(height: 10,);
  311. },
  312. itemCount: _dataArray2.length,
  313. padding: EdgeInsets.only(top: 15,bottom: 15),
  314. ):(_imageArray.isNotEmpty?ListView.builder(
  315. itemBuilder: (context,index){
  316. String url = _imageArray[index];
  317. return Image.network(url,fit: BoxFit.fill,);
  318. },
  319. itemCount: _imageArray.length,
  320. padding: EdgeInsets.all(0),
  321. ):ListView.builder(itemBuilder: (context,index){
  322. Map item = _dataArray[index];
  323. List array = item['array']??[];
  324. return Column(
  325. children: [
  326. Container(
  327. alignment: Alignment.centerLeft,
  328. height: 42,
  329. child: Row(
  330. children: [
  331. SizedBox(
  332. child: Text(item['title'],style: TextStyle(fontSize: 14,color: Color(0xFF515050)),),
  333. width: ysWidth(context)-160,
  334. ),
  335. if(item['isHelp']==true)SizedBox(
  336. child: Row(
  337. children: [
  338. GestureDetector(
  339. child: SizedBox(
  340. child: Text('使用帮助',style: TextStyle(fontSize: 12,color: Color(0xFF515050)),),
  341. width: 60,
  342. ),
  343. onTap: (){
  344. Navigator.of(context,rootNavigator: true).push(
  345. CupertinoPageRoute(builder: (context){
  346. return YSCouponHelp();
  347. })
  348. );
  349. },
  350. behavior: HitTestBehavior.opaque,
  351. ),
  352. PopupMenuButton(
  353. itemBuilder: (BuildContext context){
  354. return [
  355. PopupMenuItem(child: Text("核销记录",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "1",),
  356. PopupMenuItem(child: Text("机构列表",style: TextStyle(fontSize: 12,color: Color(0xFF444444)),),value: "2",),
  357. ];
  358. },
  359. icon: Container(
  360. child: Text('更多',style: TextStyle(fontSize: 12,color: Color(0xFFE78CA9)),),
  361. alignment: Alignment.centerRight,
  362. width: 40,
  363. ),
  364. onSelected: (value){
  365. if(value=='1'){
  366. Navigator.of(context,rootNavigator: true).push(
  367. CupertinoPageRoute(builder: (context){
  368. return YSWriteOff();
  369. })
  370. );
  371. }else{
  372. Navigator.of(context,rootNavigator: true).push(
  373. CupertinoPageRoute(builder: (context){
  374. return YSInstitution();
  375. })
  376. );
  377. }
  378. },
  379. )
  380. // Image.asset('lib/images/fy_help.png',height: 20,width: 20,)
  381. ],
  382. ),
  383. width: 120,
  384. ),
  385. ],
  386. ),
  387. padding: EdgeInsets.only(left: 15,right: 15),
  388. ),
  389. ListView.separated(itemBuilder: (context,indexSub){
  390. Map itemSub = array[indexSub];
  391. if(index==0){
  392. itemSub['type'] = '1';
  393. }else{
  394. itemSub['type'] = '2';
  395. }
  396. return YSCouponCardNewView(item: itemSub,array: array,);
  397. },
  398. separatorBuilder: (context,indexSub){
  399. return Container(height: 15,);
  400. },
  401. itemCount: array.length,
  402. padding: EdgeInsets.only(left: 15,right: 15),
  403. shrinkWrap: true,
  404. physics: NeverScrollableScrollPhysics(),
  405. )
  406. ],
  407. );
  408. },
  409. itemCount: _dataArray.length,
  410. padding: EdgeInsets.only(bottom: 15),
  411. ));
  412. }).toList(),
  413. ),
  414. )
  415. ],
  416. ),
  417. ),
  418. ),
  419. );
  420. }
  421. }
  422. class YSCoupon2 extends StatefulWidget {
  423. const YSCoupon2({Key key}) : super(key: key);
  424. @override
  425. _YSCoupon2State createState() => _YSCoupon2State();
  426. }
  427. class _YSCoupon2State extends State<YSCoupon2> {
  428. List _dataArray= [
  429. {'title':'母亲筛查服务券','array':[
  430. {'name':'产前血清学筛查','count':2,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFE290F9,'index':0},
  431. {'name':'产前常规超声检查','count':1,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFF4DF59,'index':1},
  432. {'name':'产前常规超声检查','count':1,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFACED62,'index':2},
  433. ]},
  434. {'title':'新生儿筛查服务券','array':[
  435. {'name':'新生儿先天性听力障碍筛查','count':2,'no':'131354654646132','month':'孕30-34周红','date':'2024-10-05','color':0xFFFF6D96,'index':0},
  436. {'name':'新生儿遗传代谢病筛查','count':1,'no':'131354654646132','month':'孕30-34周紫','date':'2024-10-05','color':0xFFB9A0FF,'index':1},
  437. {'name':'新生儿先天性心脏病筛查','count':1,'no':'131354654646132','month':'孕30-34周蓝色','date':'2024-10-05','color':0xFF72D2FF,'index':2},
  438. ]}
  439. ];
  440. List _dataArray2= [
  441. {'title':'母亲筛查服务券','array':[
  442. {'name':'产前血清学筛查','count':2,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFE290F9,'index':0},
  443. {'name':'产前常规超声检查','count':1,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFF4DF59,'index':1},
  444. {'name':'产前常规超声检查','count':1,'no':'131354654646132','month':'孕30-34周','date':'2024-10-05','color':0xFFACED62,'index':2},
  445. ]},
  446. {'title':'新生儿筛查服务券','array':[
  447. {'name':'新生儿先天性听力障碍筛查','count':2,'no':'131354654646132','month':'孕30-34周红','date':'2024-10-05','color':0xFFFF6D96,'index':0},
  448. {'name':'新生儿遗传代谢病筛查','count':1,'no':'131354654646132','month':'孕30-34周紫','date':'2024-10-05','color':0xFFB9A0FF,'index':1},
  449. {'name':'新生儿先天性心脏病筛查','count':1,'no':'131354654646132','month':'孕30-34周蓝色','date':'2024-10-05','color':0xFF72D2FF,'index':2},
  450. ]}
  451. ];
  452. @override
  453. Widget build(BuildContext context) {
  454. return YSBase(
  455. ystitle: '两筛电子劵',
  456. isBack: false,
  457. yschild: Column(
  458. children: [
  459. Container(
  460. height: ysHeight(context)-ysTOP(context)-94,
  461. child: SingleChildScrollView(
  462. child: Column(
  463. children: [
  464. ListView.builder(
  465. itemBuilder: (context,index){
  466. Map item = _dataArray[index];
  467. List array = item['array']??[];
  468. return Column(
  469. children: [
  470. Container(
  471. alignment: Alignment.centerLeft,
  472. height: 42,
  473. child: Row(
  474. children: [
  475. SizedBox(
  476. child: Text(item['title'],style: TextStyle(fontSize: 14,color: Color(0xFF515050)),),
  477. width: ysWidth(context)-110,
  478. ),
  479. GestureDetector(//if(index==0)
  480. child: SizedBox(
  481. child: Row(
  482. children: [
  483. SizedBox(
  484. child: Text('使用帮助',style: TextStyle(fontSize: 14,color: Color(0xFF515050)),),
  485. width: 60,
  486. ),
  487. Image.asset('lib/images/fy_help.png',height: 20,width: 20,)
  488. ],
  489. ),
  490. width: 80,
  491. ),
  492. onTap: (){
  493. if(index==0){
  494. Navigator.of(context,rootNavigator: true).push(
  495. CupertinoPageRoute(builder: (context){
  496. return YSInstitution();
  497. })
  498. );
  499. }else{
  500. Navigator.of(context,rootNavigator: true).push(
  501. CupertinoPageRoute(builder: (context){
  502. return YSWriteOff();
  503. })
  504. );
  505. }
  506. },
  507. ),
  508. ],
  509. ),
  510. padding: EdgeInsets.only(left: 15,right: 15),
  511. ),
  512. Stack(
  513. children: [
  514. for (int i =0;i<array.length;i++ )GestureDetector(
  515. child: YSCouponCardView(item: array[i],isShow: i==array.length-1,array: _dataArray2[index]['array'],),
  516. onTap: (){
  517. int endIndex = array.length-1;
  518. if(i==endIndex)return;
  519. Map map = array[i];
  520. List array1 = _dataArray2[index]['array'];
  521. item['array'] = jsonDecode(jsonEncode(array1));
  522. List array2 = item['array'];
  523. Map itemC = array2.firstWhere((element) => element['index']==map['index']);
  524. int cIndex = array2.indexOf(itemC);
  525. Map itemE = array2[endIndex];
  526. array2[endIndex] = itemC;
  527. array2[cIndex] = itemE;
  528. setState(() {});
  529. },
  530. // behavior: HitTestBehavior.opaque,
  531. )
  532. ],
  533. // alignment: AlignmentDirectional.bottomStart,
  534. )
  535. ],
  536. );
  537. },
  538. itemCount: _dataArray.length,
  539. shrinkWrap: true,
  540. physics: NeverScrollableScrollPhysics(),
  541. padding: EdgeInsets.all(0),
  542. )
  543. ],
  544. ),
  545. ),
  546. )
  547. ],
  548. ),
  549. );
  550. }
  551. }