YSPerfectChapterInfo.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/YSPage.dart';
  4. import 'package:flutterappfuyou/code/YSMeans.dart';
  5. import 'package:flutterappfuyou/code/base/YSBase.dart';
  6. import 'package:flutterappfuyou/code/base/YSTools.dart';
  7. import 'package:flutterappfuyou/code/version3/view/YSChapterInputView.dart';
  8. import 'package:shared_preferences/shared_preferences.dart';
  9. import '../base/YSNetWorking.dart';
  10. class YSPerfectChapterInfo extends StatefulWidget {
  11. final bool isFirst;
  12. const YSPerfectChapterInfo({Key key, this.isFirst = false}) : super(key: key);
  13. @override
  14. _YSPerfectChapterInfoState createState() => _YSPerfectChapterInfoState();
  15. }
  16. class _YSPerfectChapterInfoState extends State<YSPerfectChapterInfo> {
  17. List _titleArray = [
  18. {'title':'备孕篇'},
  19. {'title':'孕产篇'},
  20. {'title':'儿童篇'}
  21. ];
  22. int _pageIndex = 1;
  23. List _showArray = [
  24. [{'title':'月经一般持续天数','type':1,'image':'母血补采'},{'title':'月经周期天数','type':1,'image':'时钟 2'}],
  25. [{'title':'预产期','type':2,'image':'日历 2'}],
  26. [{'title':'宝宝姓名','type':1,'image':'编组 9备份 6'},{'title':'宝宝生日','type':2,'image':'生日 2'},
  27. {'title':'宝宝性别','type':2,'image':'男女 2'},{'title':'保健册号','type':1,'image':'手册 2'}]
  28. ];
  29. SharedPreferences _prefs;
  30. @override
  31. void initState() {
  32. _getSharedPreferences();
  33. // Future.delayed(Duration(seconds: 0)).then((value) {
  34. // _getInfoData();
  35. // });
  36. super.initState();
  37. }
  38. _getSharedPreferences() async{
  39. _prefs = await SharedPreferences.getInstance();
  40. }
  41. _getInfoData() async{
  42. Map dict1 = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', {'category_id':1});
  43. if(dict1!=null){
  44. Map data = dict1['data']??{};
  45. List array1 = _showArray[0];
  46. array1.clear();
  47. array1.addAll([
  48. {'title':'月经一般持续天数','type':1,'image':'母血补采','value':'${data['duration']??''}'},{'title':'月经周期天数','type':1,'image':'时钟 2','value':'${data['duration']??''}'}
  49. ]);
  50. setState(() {});
  51. }
  52. Map dict2 = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', {'category_id':2});
  53. if(dict2!=null){
  54. Map data = dict2['data']??{};
  55. List array2 = _showArray[1];
  56. array2.clear();
  57. array2.addAll([
  58. {'title':'预产期','type':2,'image':'日历 2','value':data['expected_time']}
  59. ]);
  60. }
  61. // Map dict3 = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/info', {'category_id':3});
  62. // if(dict3!=null){
  63. // Map data = dict3['data']??{};
  64. // List array2 = _showArray[1];
  65. // array2.clear();
  66. // array2.addAll([
  67. // {'title':'预产期','type':2,'image':'日历 2','value':data['expected_time']}
  68. // ]);
  69. // }
  70. }
  71. @override
  72. Widget build(BuildContext context) {
  73. List array = _showArray[_pageIndex];
  74. return YSBase(
  75. ystitle: '选择篇章',
  76. isBack: widget.isFirst==false,
  77. yschild: Container(
  78. margin: EdgeInsets.only(left: 30,right: 30),
  79. child: SingleChildScrollView(
  80. child: Column(
  81. children: [
  82. Container(
  83. margin: EdgeInsets.only(top: 30,bottom: 30),
  84. height: 120,
  85. child: GridView.builder(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  86. crossAxisCount: _titleArray.length,
  87. childAspectRatio: (ysWidth(context)-60)/3/120
  88. ), itemBuilder: (context,index){
  89. Map item = _titleArray[index];
  90. return GestureDetector(
  91. onTap: (){
  92. _pageIndex = index;
  93. setState(() {});
  94. },
  95. behavior: HitTestBehavior.opaque,
  96. child: Container(
  97. child: LayoutBuilder(builder: (context,conSize){
  98. return Column(
  99. children: [
  100. Image.asset('lib/images/fy_chapter${index+1}_${_pageIndex==index?'2':'1'}.png',height: 90,width: 90,),
  101. Container(
  102. height: 30,
  103. child: Text(item['title'],style: TextStyle(fontSize: 18,color: Color(0xFF444444)),),
  104. )
  105. ],
  106. );
  107. }),
  108. ),
  109. );
  110. },itemCount: _titleArray.length,padding: EdgeInsets.all(0),physics: NeverScrollableScrollPhysics(),),
  111. ),
  112. DashLine(width: 5,color: Color(0xFF979797),height: 1,),
  113. Container(
  114. height: ysHeight(context)-ysTOP(context)-261,
  115. key: Key('$_pageIndex'),
  116. margin: EdgeInsets.all(15),
  117. child: SingleChildScrollView(
  118. child: Column(
  119. children: [
  120. if(_pageIndex==1)Container(
  121. child: Text('请输入产检时医生告知的预产期,如尚未产检可以使用“计算预产期”',style: TextStyle(fontSize: 12,color: Color(0xFF8A8A8A)),),
  122. padding: EdgeInsets.only(top: 20),
  123. ),
  124. array.isNotEmpty?ListView.separated(
  125. itemBuilder: (context,indexSub){
  126. Map item = array[indexSub];
  127. int type = item['type'];
  128. return type==1?YSChapterInputView(
  129. item: item,
  130. ):YSChapterChooseView(
  131. item: item,
  132. );
  133. },
  134. separatorBuilder: (context,index){
  135. return Container(height: 30,);
  136. },
  137. itemCount: array.length,
  138. shrinkWrap: true,
  139. physics: NeverScrollableScrollPhysics(),
  140. padding: EdgeInsets.only(top: 20),
  141. ):Container(height: 100,),
  142. if (_pageIndex==1) GestureDetector(
  143. onTap: (){
  144. ysShowCenterAlertView(context, YSCountDateView(postDate: (value){
  145. array[0]['value'] = value;
  146. setState(() {});
  147. },));
  148. },
  149. child: Container(
  150. margin: EdgeInsets.only(top: 10,bottom: 60),
  151. height: 20,
  152. alignment: Alignment.centerRight,
  153. child: Row(
  154. mainAxisSize: MainAxisSize.min,
  155. children: [
  156. Text('计算预产期 ',style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  157. Image(height: 15,width: 15,image: AssetImage('lib/images/calculte.png'),),
  158. ],
  159. ),
  160. ),
  161. ) else Container(height: 60,),
  162. YSSubmitView(callback: (){
  163. if(_pageIndex==0){
  164. _postPeriodData();
  165. }else if(_pageIndex==1){
  166. _postDueData();
  167. }else if(_pageIndex==2){
  168. _postChildData();
  169. }
  170. },title: _pageIndex==1?'下一步':'完成',)
  171. ],
  172. ),
  173. ),
  174. ),
  175. ],
  176. ),
  177. ),
  178. ),
  179. );
  180. }
  181. _postPeriodData() async{
  182. List array0 = _showArray[0];
  183. if(array0.isEmpty)return;
  184. Map cxMap = array0[0];
  185. Map zqdMap = array0[1];
  186. if(zqdMap['value']==null){
  187. ysFlutterToast(context, '请输入周期时间');
  188. return;
  189. }
  190. if(int.parse(zqdMap['value'])>51){
  191. ysFlutterToast(context, '周期时间过长');
  192. return;
  193. }
  194. if(cxMap['value']==null){
  195. ysFlutterToast(context, '请输入持续时间');
  196. return;
  197. }
  198. if(int.parse(cxMap['value'])>51){
  199. ysFlutterToast(context, '持续时间过长');
  200. return;
  201. }
  202. Map dict = await ysRequestHttp(context,requestType.put, 'motherhood/period', {'cycle':zqdMap['value'],'duration':cxMap['value']});
  203. if(dict!=null){
  204. _jumpPage();
  205. }
  206. }
  207. _postDueData() async{
  208. List array1 = _showArray[1];
  209. if(array1.isEmpty)return;
  210. Map ycMap = array1[0];
  211. if(ycMap['value']==null){
  212. ysFlutterToast(context, '请选择预产期');
  213. return;
  214. }
  215. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'phase/dueDate', {'expected_time':ycMap['value']});
  216. if(dict!=null){
  217. _jumpPage();
  218. }
  219. }
  220. _postChildData() async{
  221. List array2 = _showArray[2];
  222. if(array2.isEmpty)return;
  223. Map xmMap = array2[0];
  224. Map srMap = array2[1];
  225. Map xbMap = array2[2];
  226. Map bjMap = array2[3];
  227. if(xmMap['value']==null){
  228. ysFlutterToast(context, '请完善宝宝姓名');
  229. return;
  230. }
  231. if(srMap['value']==null){
  232. ysFlutterToast(context, '请完善宝宝生日');
  233. return;
  234. }
  235. if(xbMap['value']==null){
  236. ysFlutterToast(context, '请完善宝宝性别');
  237. return;
  238. }
  239. if(bjMap['value']==null){
  240. ysFlutterToast(context, '请完善保健册号');
  241. return;
  242. }
  243. DateTime now = DateTime.now();
  244. DateTime expected = DateTime.parse('${srMap['value']} ${now.hour.toString().padLeft(2,'0')}:${now.minute.toString().padLeft(2,'0')}:${now.second.toString().padLeft(2,'0')}');
  245. bool isBefore = now.isBefore(expected);
  246. if(isBefore){
  247. ysFlutterToast(context, '宝宝生日不能大于当前日期');
  248. return;
  249. }
  250. Map pragma = Map();
  251. pragma['name'] = xmMap['value'];
  252. pragma['health_book'] = bjMap['value'];
  253. pragma['birthday'] = srMap['value'];
  254. if(xbMap['value']=='男'){
  255. pragma['gender'] = 1;
  256. }else{
  257. pragma['gender'] = 2;
  258. }
  259. Map dict = await ysRequestHttp(context,requestType.post, 'child/chapter/addOrUp', pragma);
  260. if(dict!=null){
  261. _prefs.setInt('childId', dict['data']['child_id']);
  262. _jumpPage();
  263. }
  264. }
  265. _jumpPage() {
  266. if(true){//widget.isFirst
  267. _prefs.setInt('chapters', _pageIndex);
  268. if(true){//_pageIndex==1
  269. Navigator.of(context).pushAndRemoveUntil(CupertinoPageRoute(builder: (context){
  270. return YSMeans(isFirst: true,);
  271. }), (route) => false);
  272. }else{
  273. Navigator.of(context).pushAndRemoveUntil(CupertinoPageRoute(builder: (context){
  274. return YSPage();
  275. }), (route) => false);
  276. }
  277. }else{
  278. Navigator.of(context).pop('完成');
  279. }
  280. }
  281. }
  282. class YSCountDateView extends StatefulWidget {
  283. final ValueSetter postDate;
  284. const YSCountDateView({Key key, this.postDate}) : super(key: key);
  285. @override
  286. _YSCountDateViewState createState() => _YSCountDateViewState();
  287. }
  288. class _YSCountDateViewState extends State<YSCountDateView> {
  289. String _dateStr = '';
  290. @override
  291. Widget build(BuildContext context) {
  292. return Center(
  293. child: Container(
  294. width: MediaQuery.of(context).size.width-60,
  295. padding: EdgeInsets.all(15),
  296. height: 150,
  297. decoration: BoxDecoration(
  298. color: Colors.white,
  299. borderRadius: BorderRadius.all(Radius.circular(10))
  300. ),
  301. child: Column(
  302. crossAxisAlignment: CrossAxisAlignment.start,
  303. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  304. children: [
  305. Text('计算预产期',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  306. CupertinoButton(
  307. padding: EdgeInsets.all(0),
  308. child: Container(
  309. height: 30,
  310. width: MediaQuery.of(context).size.width-30,
  311. child: Text(_dateStr.isNotEmpty?_dateStr:'请选择末次月经时间进行计算',style: TextStyle(fontSize: 13,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  312. decoration: BoxDecoration(
  313. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFD7D7D7)))
  314. ),
  315. ),
  316. onPressed: (){
  317. ysDatePicker(context, (value){
  318. setState(() {
  319. _dateStr = value;
  320. });
  321. },lastDate: DateTime.now().subtract(Duration(days: 1)),initDate: DateTime.now().subtract(Duration(days: 1)));
  322. },
  323. ),
  324. Row(
  325. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  326. children: [
  327. Container(),
  328. Row(
  329. children: [
  330. CupertinoButton(
  331. padding: EdgeInsets.all(0),
  332. child: Text('取消',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  333. onPressed: (){
  334. Navigator.pop(context);
  335. },
  336. ),
  337. CupertinoButton(
  338. padding: EdgeInsets.all(0),
  339. child: Text('计算',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  340. onPressed: () async{
  341. if(_dateStr.isEmpty){
  342. ysFlutterToast(context, '请选择时间后进行计算');
  343. return;
  344. }
  345. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'phase/dueDateQuery', {'date':_dateStr});
  346. if(dict!=null){
  347. Navigator.pop(context);
  348. String dueDate = dict['data']['data'];
  349. widget.postDate(dueDate);
  350. }
  351. },
  352. )
  353. ],
  354. )
  355. ],
  356. )
  357. ],
  358. ),
  359. ),
  360. );
  361. }
  362. }