YSRecord.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:flutterappfuyou/code/base/YSTools.dart';
  5. import 'base/YSBase.dart';
  6. class YSRecord extends StatefulWidget {
  7. @override
  8. _YSRecordState createState() => _YSRecordState();
  9. }
  10. class _YSRecordState extends State<YSRecord> {
  11. List _periodList = [];
  12. List _roomList = [];
  13. @override
  14. void initState() {
  15. Future.delayed(Duration(seconds: 0)).then((value){
  16. _getRecordListData();
  17. });
  18. super.initState();
  19. }
  20. _deletePeriodData(int type,String date) async{
  21. Map dict = await ysRequestHttpNoLoading(context, requestType.delete, 'motherhood/periodDate/delete', {'type':type.toString(),'date':date});
  22. if(dict!=null){
  23. _getRecordListData();
  24. }
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return YSBase(
  29. ystitle: '备孕记录',
  30. ysright: CupertinoButton(
  31. padding: EdgeInsets.all(0),
  32. child: Container(
  33. height: 30,
  34. width: 55,
  35. decoration: BoxDecoration(
  36. color: Color(0xFFFFEB3B),
  37. border: Border.all(color: Color(0xFF292929),width: 1),
  38. borderRadius: BorderRadius.all(Radius.circular(20))
  39. ),
  40. alignment: Alignment.center,
  41. child: Text('刷新',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none),),
  42. ),
  43. onPressed: (){
  44. _getRecordListData();
  45. },
  46. ),
  47. yschild: SingleChildScrollView(
  48. child: Column(
  49. children: [
  50. Container(
  51. height: MediaQuery.of(context).size.height-ysTOP(context)-120,
  52. color: Colors.white,
  53. child: Column(
  54. children: [
  55. Row(
  56. children: [
  57. Container(
  58. width: MediaQuery.of(context).size.width/2,
  59. height: 80,
  60. padding: EdgeInsets.only(top: 15,bottom: 15,left: 25),
  61. child: Row(
  62. children: [
  63. Container(
  64. child: Image.asset('lib/images/yuejing.png'),
  65. height: 45,
  66. width: 45,
  67. ),
  68. Text(' 月经记录',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),)
  69. ],
  70. ),
  71. ),
  72. Container(
  73. width: MediaQuery.of(context).size.width/2,
  74. height: 80,
  75. padding: EdgeInsets.only(top: 15,bottom: 15,left: 25),
  76. child: Row(
  77. children: [
  78. Container(
  79. child: Image.asset('lib/images/tongfang.png'),
  80. height: 45,
  81. width: 45,
  82. ),
  83. Text(' 同房记录',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),)
  84. ],
  85. ),
  86. ),
  87. ],
  88. ),
  89. Container(
  90. height: MediaQuery.of(context).size.height-ysTOP(context)-200,
  91. width: MediaQuery.of(context).size.width,
  92. child: ListView.separated(
  93. itemBuilder: (context,index){
  94. return Row(
  95. children: [
  96. _periodList.length>index?GestureDetector(
  97. child: Container(
  98. margin: EdgeInsets.only(left: 20,right: 20,bottom: 5),
  99. height: 40,
  100. decoration: BoxDecoration(
  101. color: Colors.white,
  102. boxShadow: [
  103. BoxShadow(color: Color(0x1F1D2129),blurRadius: 3,offset: Offset(0.5, 0.5))
  104. ]
  105. ),
  106. child: Row(
  107. children: [
  108. Container(
  109. height: 40,
  110. width: 5,
  111. decoration: BoxDecoration(
  112. color: Color(0xFFDB5278),
  113. borderRadius: BorderRadius.only(topLeft: Radius.circular(3),bottomLeft: Radius.circular(3))
  114. ),
  115. ),
  116. Container(
  117. alignment: Alignment.center,
  118. width: MediaQuery.of(context).size.width/2-45,
  119. child: Text('${_periodList[index]['date']}',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  120. )
  121. ],
  122. ),
  123. ),
  124. onLongPress: () {
  125. ysShowCenterAlertView(context, YSTipsAlertView(
  126. tipsStr: '是否删除此记录?',
  127. valueSetter: (value){
  128. if(value){
  129. _deletePeriodData(1, _periodList[index]['date']);
  130. }
  131. },
  132. ));
  133. },
  134. ):Container(width: MediaQuery.of(context).size.width/2,),
  135. _roomList.length>index?GestureDetector(
  136. child: Container(
  137. margin: EdgeInsets.only(left: 20,right: 20,bottom: 5),
  138. height: 40,
  139. decoration: BoxDecoration(
  140. color: Colors.white,
  141. boxShadow: [
  142. BoxShadow(color: Color(0x1F1D2129),blurRadius: 3,offset: Offset(0.5, 0.5))
  143. ]
  144. ),
  145. child: Row(
  146. children: [
  147. Container(
  148. height: 40,
  149. width: 5,
  150. decoration: BoxDecoration(
  151. color: Color(0xFF7292DB),
  152. borderRadius: BorderRadius.only(topLeft: Radius.circular(3),bottomLeft: Radius.circular(3))
  153. ),
  154. ),
  155. Container(
  156. alignment: Alignment.center,
  157. width: MediaQuery.of(context).size.width/2-45,
  158. child: Text('${_roomList[index]['date']}',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  159. )
  160. ],
  161. )
  162. ),
  163. onLongPress: (){
  164. ysShowCenterAlertView(context, YSTipsAlertView(
  165. tipsStr: '是否删除此记录?',
  166. valueSetter: (value){
  167. if(value){
  168. _deletePeriodData(2, _roomList[index]['date']);
  169. }
  170. },
  171. ));
  172. },
  173. ):Container(width: MediaQuery.of(context).size.width/2,),
  174. ],
  175. );
  176. },
  177. separatorBuilder: (context,index){
  178. return Divider(color: Colors.white,height: 10,thickness: 10,);
  179. },
  180. itemCount: _roomList.length>_periodList.length?_roomList.length:_periodList.length,
  181. padding: EdgeInsets.only(top: 5,bottom: 5),
  182. ),
  183. )
  184. ],
  185. ),
  186. ),
  187. CupertinoButton(
  188. color: Colors.white,
  189. padding: EdgeInsets.all(0),
  190. child: Container(
  191. height: 40,
  192. width: MediaQuery.of(context).size.width-150,
  193. decoration: BoxDecoration(
  194. color: Color(0xFFDB5278),
  195. borderRadius: BorderRadius.all(Radius.circular(20))
  196. ),
  197. alignment: Alignment.center,
  198. child: Text('添加',style: TextStyle(fontSize: 16,color: Colors.white),),
  199. margin: EdgeInsets.only(top: 15,bottom: 15,left: 75,right: 75),
  200. ),
  201. onPressed: (){
  202. showModalBottomSheet(
  203. backgroundColor: Colors.transparent,
  204. context: context,
  205. builder: (context){
  206. return Container(
  207. height: 200,
  208. decoration: BoxDecoration(
  209. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20)),
  210. color: Colors.white
  211. ),
  212. child: Column(
  213. children: [
  214. Container(
  215. width: MediaQuery.of(context).size.width,
  216. height: 49.5,
  217. alignment: Alignment.center,
  218. child: Text('添加',style: TextStyle(fontSize: 16,color: Color(0xFF292929)),),
  219. ),
  220. Divider(color: Color(0xFFE6E6E6),height: 0.5,thickness: 0.5,),
  221. Row(
  222. children: [
  223. CupertinoButton(
  224. child: Container(
  225. height: 100,
  226. width: MediaQuery.of(context).size.width/2,
  227. child: Column(
  228. children: [
  229. Container(
  230. child: Image.asset('lib/images/yuejing.png'),
  231. height: 45,
  232. width: 45,
  233. ),
  234. Text('月经记录',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),)
  235. ],
  236. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  237. ),
  238. ),
  239. padding: EdgeInsets.all(0),
  240. onPressed: (){
  241. _postPeriodData(1);
  242. },
  243. ),
  244. CupertinoButton(
  245. child: Container(
  246. height: 100,
  247. width: MediaQuery.of(context).size.width/2,
  248. child: Column(
  249. children: [
  250. Container(
  251. child: Image.asset('lib/images/tongfang.png'),
  252. height: 45,
  253. width: 45,
  254. ),
  255. Text('同房记录',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),)
  256. ],
  257. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  258. ),
  259. ),
  260. padding: EdgeInsets.all(0),
  261. onPressed: (){
  262. _postPeriodData(2);
  263. },
  264. )
  265. ],
  266. ),
  267. Divider(color: Color(0xFFE6E6E6),height: 0.5,thickness: 0.5,),
  268. CupertinoButton(
  269. child: Container(
  270. width: MediaQuery.of(context).size.width,
  271. height: 49.5,
  272. alignment: Alignment.center,
  273. child: Text('取消',style: TextStyle(fontSize: 16,color: Color(0xFF292929)),),
  274. ),
  275. padding: EdgeInsets.all(0),
  276. onPressed: (){
  277. Navigator.pop(context);
  278. },
  279. ),
  280. ],
  281. ),
  282. );
  283. }
  284. );
  285. },
  286. )
  287. ],
  288. ),
  289. ),
  290. );
  291. }
  292. _getRecordListData() async{
  293. _periodList.clear();
  294. _roomList.clear();
  295. Map dict = await ysRequestHttp(context, requestType.get, 'motherhood/periodDate/list', {});
  296. if(dict!=null){
  297. List array = dict['data'];
  298. array.forEach((element) {
  299. if(element['type']==1){
  300. _periodList.add(element);
  301. }else{
  302. _roomList.add(element);
  303. }
  304. });
  305. setState(() {});
  306. }
  307. }
  308. _postPeriodData(int type) {
  309. Navigator.pop(context);
  310. ysDatePicker(context, (value) async{
  311. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'motherhood/periodDate/add', {'type':type.toString(),'date':value});
  312. if(dict!=null){
  313. _getRecordListData();
  314. }
  315. });
  316. }
  317. }