YSMeans.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import 'package:dotted_border/dotted_border.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutterappfuyou/code/YSChapters.dart';
  5. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  6. import 'package:image_picker/image_picker.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. import '../YSPage.dart';
  9. import 'YSChoose.dart';
  10. import 'YSHospital.dart';
  11. import 'YSHospitalDetail.dart';
  12. import 'base/YSBase.dart';
  13. import 'base/YSTools.dart';
  14. class YSMeans extends StatefulWidget {
  15. final bool isEdit;
  16. final bool isFirst;
  17. const YSMeans({Key key, this.isEdit, this.isFirst = false}) : super(key: key);
  18. @override
  19. _YSMeansState createState() => _YSMeansState();
  20. }
  21. class _YSMeansState extends State<YSMeans> {//,{'title':'手机号码:','content':'请输入手机号码'}
  22. final ImagePicker _picker = ImagePicker();
  23. List dataArray = [{'title':'居住地:','content':'请选择居住地址'},{'title':'详细地址:','content':'请输入详细地址'},{'title':'选择卫生院:','content':'请选择卫生院'},
  24. {'title':'女方姓名:','content':'请输入姓名'},{'title':'证件类型:','content':'居民身份证'},{'title':'证件号码:','content':'请输入证件号码'}];
  25. String _place,_hospital,_street;
  26. Map _hospitalDetail = {};
  27. TextEditingController _location = TextEditingController();
  28. TextEditingController _name = TextEditingController();
  29. TextEditingController _number = TextEditingController();
  30. TextEditingController _phone = TextEditingController();
  31. int _hospitalId,_placeId,_streetId;
  32. int _type = 1;
  33. String _cardType = '居民身份证';
  34. bool _isCanChange = true;
  35. @override
  36. void initState() {
  37. Future.delayed(Duration(seconds: 0)).then((value){
  38. getVersionData(context);
  39. if(widget.isEdit==true){
  40. _getUserData();
  41. }
  42. });
  43. super.initState();
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. return YSBase(
  48. isBack: widget.isFirst==false,
  49. ystitle: '完善资料',
  50. yschild: SingleChildScrollView(
  51. child: Column(
  52. children: [
  53. Container(
  54. height: MediaQuery.of(context).size.height-155,
  55. child: SingleChildScrollView(
  56. child: Column(
  57. children: [
  58. Container(
  59. height: 45,
  60. width: MediaQuery.of(context).size.width,
  61. alignment: Alignment.center,
  62. padding: EdgeInsets.all(15),
  63. child: Text('请完善以下信息,信息将用于查询医疗档案!',style: TextStyle(fontSize: 10,color: Color(0xFFEF6E92),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  64. ),
  65. Container(
  66. width: MediaQuery.of(context).size.width,
  67. height: 1.5,
  68. child: Image.asset('lib/images/line.png'),
  69. ),
  70. Container(
  71. height: 51.5*dataArray.length,
  72. child: ListView.separated(
  73. itemBuilder: (context,index){
  74. return Container(
  75. height: 50,
  76. width: MediaQuery.of(context).size.width,
  77. padding: EdgeInsets.only(left: 15,right: 15,top: index==1?5:15,bottom: index==1?5:15),
  78. child: index==1?Column(
  79. crossAxisAlignment: CrossAxisAlignment.start,
  80. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  81. children: [
  82. Text((dataArray[index]['title']).toString(),style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  83. CupertinoTextField(
  84. style: TextStyle(fontSize: 11,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  85. placeholder: (dataArray[index]['content']).toString(),
  86. placeholderStyle: TextStyle(fontSize: 11,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  87. padding: EdgeInsets.all(0),
  88. decoration: BoxDecoration(),
  89. controller: _location,
  90. )
  91. ],
  92. ):Row(
  93. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  94. children: [
  95. Text((dataArray[index]['title']).toString(),style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  96. if (index==0||index==2||index==4) GestureDetector(
  97. child: Row(
  98. children: [
  99. Text((index==0&&_place!=null)?'$_place $_street':(index==2&&_hospital!=null)?_hospital:(index==4&&_cardType!=null)?_cardType:(dataArray[index]['content']).toString(),
  100. style: TextStyle(fontSize: 14,color: (index==2&&_hospital==null)?Colors.red:(index==4&&_isCanChange==false)?Color(0xFF969799).withOpacity(0.5):Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  101. index==4&&_isCanChange==false?Container():Icon(Icons.keyboard_arrow_right,size: 20,color: Color((0xFFAEB3BD)),)
  102. ],
  103. ),
  104. onTap: (){
  105. if(index==4&&_isCanChange==false)return;
  106. Navigator.of(context).push(
  107. CupertinoPageRoute(
  108. builder: (context){
  109. if(index==0){
  110. return YSChooseArea();
  111. }else if(index==2){
  112. return _hospital==null?YSHospital(healthId: _hospitalId, areaId: _placeId,):YSHospitalDetail(healthId: _hospitalId,);
  113. }else{
  114. return YSChooseType();
  115. }
  116. }
  117. )
  118. ).then((value){
  119. if(index==2){
  120. _getUserData2();
  121. }else if(value!=null){
  122. if(index==0){
  123. print('$value');
  124. _hospitalId = null;
  125. _hospital = null;
  126. // _hospitalId = value['healthId'];
  127. _placeId = value['areaId'];
  128. _streetId = value['streetId'];
  129. // _hospital = value['health'];
  130. _place = value['area'];
  131. _street = value['street'];
  132. setState(() {});
  133. // _getHospitalDetail(_hospitalId);
  134. }else if(index==2){
  135. print('$value');
  136. _hospitalId = value['id'];
  137. _hospital = value['name'];
  138. _getHospitalDetail(_hospitalId);
  139. }else{
  140. LogUtil.d(value);
  141. _cardType = value;
  142. _type = _cardType=='居民身份证'?1:_cardType=='军人身份证'?2:_cardType=='护照'?3:_cardType=='港澳居民来往内地通行证'?4:_cardType=='台湾居民来往大陆通行证'?5
  143. :_cardType=='中华人民共和国旅行证'?6:7;
  144. setState(() {
  145. dataArray[4] = {'title':'证件类型:','content':value};
  146. });
  147. }
  148. }
  149. });
  150. },
  151. behavior: HitTestBehavior.opaque,
  152. ) else index==5?Row(
  153. children: [
  154. Container(
  155. height: 20,
  156. width: 170,
  157. child: _isCanChange?CupertinoTextField(
  158. style: TextStyle(fontSize: 14,color: _isCanChange?Color(0xFF77808F):Color(0xFF969799).withOpacity(0.5),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  159. placeholder: dataArray[4]['content']=='居民身份证'?'请拍摄身份证正面照片':(dataArray[index]['content']).toString(),
  160. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  161. padding: EdgeInsets.all(0),
  162. decoration: BoxDecoration(color: Colors.transparent),
  163. textAlign: TextAlign.right,
  164. controller: _number,
  165. enabled: _isCanChange,
  166. keyboardType: TextInputType.number,
  167. ):Text(_number.text,style: TextStyle(fontSize: 14,color: Color(0xFF969799).withOpacity(0.5),
  168. decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  169. alignment: Alignment.centerRight,
  170. ),
  171. dataArray[4]['content']=='居民身份证'&&_isCanChange?CupertinoButton(
  172. child: Image(height: 20,width: 20,image: AssetImage('lib/images/camer.png'),),padding: EdgeInsets.all(0),
  173. onPressed: (){
  174. showCupertinoModalPopup(
  175. context: context,
  176. builder: (context) {
  177. return CupertinoActionSheet(
  178. actions: <Widget>[
  179. CupertinoActionSheetAction(
  180. child: Text('相机'),
  181. onPressed: () {
  182. Navigator.pop(context);
  183. _picker.getImage(source: ImageSource.camera).then((value){
  184. _uploadImageData(value);
  185. });
  186. },
  187. ),
  188. CupertinoActionSheetAction(
  189. child: Text('相册'),
  190. onPressed: () {
  191. Navigator.pop(context);
  192. _picker.getImage(source: ImageSource.gallery).then((value){
  193. _uploadImageData(value);
  194. });
  195. },
  196. ),
  197. ],
  198. cancelButton: CupertinoActionSheetAction(
  199. child: Text('取消'),
  200. onPressed: () {
  201. Navigator.pop(context);
  202. },
  203. ),
  204. );
  205. }
  206. );
  207. },
  208. ):Container()
  209. ],
  210. ):Container(
  211. height: 20,
  212. width: 200,
  213. child: CupertinoTextField(
  214. style: TextStyle(fontSize: 14,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  215. placeholder: (dataArray[index]['content']).toString(),
  216. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  217. padding: EdgeInsets.all(0),
  218. decoration: BoxDecoration(),
  219. textAlign: TextAlign.right,
  220. controller: index==3?_name:_phone,
  221. ),
  222. ),
  223. ],
  224. )
  225. );
  226. },
  227. separatorBuilder: (context,index){
  228. return Container(
  229. width: MediaQuery.of(context).size.width,
  230. height: 1.5,
  231. child: Image.asset('lib/images/line.png'),
  232. );
  233. },
  234. itemCount: dataArray.length,
  235. physics: NeverScrollableScrollPhysics(),
  236. padding: EdgeInsets.all(0),
  237. ),
  238. ),
  239. Container(
  240. width: MediaQuery.of(context).size.width,
  241. height: 1.5,
  242. child: Image.asset('lib/images/line.png'),
  243. ),
  244. if(_hospital!=null)Container(
  245. height: 50,
  246. padding: EdgeInsets.only(left: 15),
  247. alignment: Alignment.center,
  248. child: Text('$_hospital服务范围',
  249. style: TextStyle(fontSize: 14,color: Color(0xFF77808F),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  250. ),
  251. // if(_hospital!=null)Container(
  252. // width: MediaQuery.of(context).size.width,
  253. // height: 1.5,
  254. // child: Image.asset('lib/images/line.png'),
  255. // ),
  256. if(_hospitalDetail.isNotEmpty)Padding(
  257. padding: EdgeInsets.only(left: 15,right: 15),
  258. child: DottedBorder(
  259. color: Color(0xFFFF6D96),
  260. borderType: BorderType.RRect,
  261. radius: Radius.circular(9),
  262. strokeWidth: 1,
  263. child: Container(
  264. height: ysHeight(context)-ysTOP(context)-241.5-51.5*dataArray.length,
  265. alignment: Alignment.center,
  266. decoration: BoxDecoration(
  267. color: Color(0xFFE96D8F).withOpacity(0.1),
  268. borderRadius: BorderRadius.all(Radius.circular(9))
  269. ),
  270. child: SingleChildScrollView(
  271. padding: EdgeInsets.all(10),
  272. child: Column(
  273. crossAxisAlignment: CrossAxisAlignment.start,
  274. children: [
  275. Text(_hospitalDetail['jurisdiction'],style: TextStyle(fontSize: 14,color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  276. Text('\n地址:${_hospitalDetail['address']}\n',style: TextStyle(fontSize: 14,color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  277. Text('咨询电话:${_hospitalDetail['contacts']}\n',style: TextStyle(fontSize: 14,color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  278. ],
  279. ),
  280. )
  281. ),
  282. ),
  283. ),
  284. ],
  285. ),
  286. ),
  287. ),
  288. Container(
  289. height: 70,
  290. child: CupertinoButton(
  291. padding: EdgeInsets.only(bottom: 20),
  292. child: Container(
  293. width: MediaQuery.of(context).size.width-150,
  294. height: 40,
  295. decoration: BoxDecoration(
  296. color: Color(0xFFEA6C8F),
  297. borderRadius: BorderRadius.all(Radius.circular(20))
  298. ),
  299. alignment: Alignment.center,
  300. child: Text('完成',style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  301. ),
  302. onPressed: (){
  303. _postUserInfo();
  304. },
  305. ),
  306. )
  307. ],
  308. ),
  309. ),
  310. );
  311. }
  312. _uploadImageData(var image) async{
  313. ysUploadFile(context,path: image.path,type: 'idcard',setter: (value) async{
  314. Map diction = await ysRequestHttp(context, requestType.post, 'sign/idcard', {'path':value['path']});
  315. if(diction!=null){
  316. _number.text = '${diction['data']['id_card']}';
  317. _name.text = '${diction['data']['name']}';
  318. }
  319. });
  320. // var dict = await ysRequestHttpNoLoading(context, requestType.get, 'upQiniuToken', {'type':'idcard'});
  321. // if(dict!=null){
  322. // var result = await syStorage.upload('${image.path}', '${dict['token']}', '${dict['path']}');
  323. // print('$result');
  324. // if(result.success==true){
  325. // Map diction = await ysRequestHttp(context, requestType.post, 'sign/idcard', {'path':dict['path']});
  326. // if(diction!=null){
  327. // _number.text = '${diction['data']['id_card']}';
  328. // }
  329. // }
  330. // }
  331. }
  332. _postUserInfo() async{
  333. FocusScope.of(context).unfocus();
  334. Map request = {};
  335. if(_placeId==null){
  336. ysFlutterToast(context, '请选择居住地');
  337. return;
  338. }
  339. if(_location.text.isEmpty){
  340. ysFlutterToast(context, '详细地址不能为空');
  341. return;
  342. }
  343. request['region_id'] = _placeId;
  344. request['area_id'] = _streetId;
  345. if(_location.text!=null||_location.text.isNotEmpty){
  346. request['address'] = _location.text;
  347. }
  348. if(_hospitalId==null){
  349. ysFlutterToast(context, '请选择卫生院');
  350. return;
  351. }
  352. request['health_id'] = _hospitalId;
  353. if(_name.text==null||_name.text.isEmpty){
  354. ysFlutterToast(context, '请输入女方姓名');
  355. return;
  356. }
  357. request['name'] = _name.text;
  358. if(_type!=null){
  359. request['id_card_type'] = _type;
  360. }
  361. if(_number.text==null||_number.text.isEmpty){
  362. ysFlutterToast(context, '请完善证件号码');
  363. return;
  364. }
  365. request['id_card'] = _number.text;
  366. // if(_phone.text==null||_phone.text.isEmpty){
  367. // ysFlutterToast(context, '请输入手机号码');
  368. // return;
  369. // }
  370. // request['phone'] = _phone.text;
  371. Map dict = await ysRequestHttp(context, requestType.post, 'user/info', request);
  372. if(dict!=null){
  373. if(widget.isEdit==true){
  374. Navigator.pop(context);
  375. }else{
  376. SharedPreferences _prefer = await SharedPreferences.getInstance();
  377. int chapters = _prefer.getInt('chapters');
  378. _prefer.setBool('isMeans', true);
  379. if(chapters==null){
  380. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  381. builder: (context){
  382. return YSChapters(isFirst: true,);
  383. }
  384. ), (route) => false);
  385. }else{
  386. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  387. builder: (context){
  388. return YSPage();
  389. }
  390. ), (route) => false);
  391. }
  392. }
  393. }
  394. }
  395. _getUserData() async{
  396. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'user/info', {});
  397. if(dict!=null){
  398. _type = dict['id_card_type'];
  399. _placeId = dict['region_id'];
  400. _hospitalId = dict['health_id'];
  401. _streetId = dict['area_id'];
  402. _isCanChange = dict['is_can_change_id_card']??true;
  403. if(_hospitalId!=null){
  404. _getHospitalDetail(_hospitalId);
  405. }
  406. setState(() {
  407. _street = dict['area_name']!=null?'${dict['area_name']}':'';
  408. _place = dict['region_name']!=null?'${dict['region_name']}':'';
  409. _location.text = dict['address']!=null?'${dict['address']}':'';
  410. _hospital = dict['health_name']!=null?'${dict['health_name']}':'';
  411. _name.text = dict['name']!=null?'${dict['name']}':'';
  412. _cardType = dict['id_card_type']==null?'居民身份证':dict['id_card_type']==1?'居民身份证':dict['id_card_type']==2?'军人身份证':dict['id_card_type']==3?'护照':dict['id_card_type']==4?'港澳居民来往内地通行证'
  413. :dict['id_card_type']==5?'台湾居民来往大陆通行证':dict['id_card_type']==6?'中华人民共和国旅行证':'其它';
  414. dataArray[4] = {'title':'证件类型:','content':_cardType};
  415. _number.text = dict['id_card']!=null?'${dict['id_card']}':'';
  416. _phone.text = dict['phone']!=null?'${dict['phone']}':'';
  417. });
  418. }
  419. }
  420. _getUserData2() async{
  421. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'user/info', {});
  422. if(dict!=null){
  423. if(dict['health_id']!=null){
  424. _hospitalId = dict['health_id'];
  425. _getHospitalDetail(_hospitalId);
  426. // if(User().isNoBind){
  427. // _placeId = dict['region_id'];
  428. // _streetId = dict['area_id'];
  429. // _street = dict['area_name']!=null?'${dict['area_name']}':'';
  430. // _place = dict['region_name']!=null?'${dict['region_name']}':'';
  431. // }
  432. }
  433. setState(() {});
  434. }
  435. }
  436. _getHospitalDetail (int healthId) async{
  437. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'common/healthCenter', {'id':healthId});
  438. if(dict!=null){
  439. _hospitalDetail = dict['data'];
  440. _hospital = _hospitalDetail['name'];
  441. setState(() {});
  442. }
  443. }
  444. }