Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

387 lines
11 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:chat/utils/HttpUtil.dart';
  7. import 'package:chat/utils/MessageMgr.dart';
  8. import 'package:chat/utils/ShadowButton.dart';
  9. import 'package:chat/utils/TokenMgr.dart';
  10. import 'package:city_pickers/city_pickers.dart';
  11. import 'package:city_pickers/modal/result.dart';
  12. import 'package:dio/dio.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:flutter/services.dart';
  15. import 'package:oktoast/oktoast.dart';
  16. class BindBankPage extends StatefulWidget {
  17. @required
  18. final bool isBind;
  19. @required
  20. final Map bankInfo;
  21. BindBankPage({Key key, this.isBind = true, this.bankInfo}) : super(key: key);
  22. _BindBankPageState createState() => _BindBankPageState();
  23. }
  24. class _BindBankPageState extends State<BindBankPage>
  25. with SingleTickerProviderStateMixin {
  26. String bankId;
  27. var bankCatId;
  28. Map bankInfo;
  29. bool isLoading = false;
  30. TextEditingController nickNameController = new TextEditingController();
  31. TextEditingController cardIdController = new TextEditingController();
  32. TextEditingController idController = new TextEditingController();
  33. TextEditingController mobileController = new TextEditingController();
  34. @override
  35. void initState() {
  36. super.initState();
  37. print('BindBankPage initState');
  38. if (widget.bankInfo == null) {
  39. bankInfo = {};
  40. } else {
  41. bankInfo = widget.bankInfo;
  42. }
  43. nickNameController.text = bankInfo['Name'] == null ? '' : bankInfo['Name'];
  44. cardIdController.text =
  45. bankInfo['CardNo'] == null ? '' : bankInfo['CardNo'];
  46. idController.text =
  47. bankInfo['IdNumber'] == null ? '' : bankInfo['IdNumber'];
  48. mobileController.text =
  49. bankInfo['MobileNo'] == null ? '' : bankInfo['MobileNo'];
  50. bankCatId = bankInfo['Bid'] == null ? '' : bankInfo['Bid'];
  51. }
  52. @override
  53. void dispose() {
  54. nickNameController.dispose();
  55. cardIdController.dispose();
  56. idController.dispose();
  57. mobileController.dispose();
  58. super.dispose();
  59. //_cancelTimer();
  60. }
  61. initValue() {
  62. if (!isLoading) {
  63. bankId = bankInfo['Bid'] == null || bankInfo['Bid'] == 0
  64. ? I18n.of(context).choose
  65. : WebData().bankData[bankInfo['Bid'].toString()];
  66. isLoading = true;
  67. setState(() {});
  68. }
  69. }
  70. @override
  71. Widget build(BuildContext context) {
  72. initValue();
  73. return Scaffold(
  74. appBar: AppBar(
  75. title: Text(I18n.of(context).bank_card, textScaleFactor: 1.0),
  76. leading: CustomUI.buildCustomLeading(context),
  77. centerTitle: true,
  78. ),
  79. body: SafeArea(
  80. child: Center(
  81. child: Container(
  82. height: MediaQuery.of(context).size.height,
  83. width: MediaQuery.of(context).size.width,
  84. child: _buildBody(),
  85. ),
  86. )));
  87. }
  88. Widget _buildBody() {
  89. return Column(
  90. children: <Widget>[
  91. _buildInputList(),
  92. _buildBotton(),
  93. ],
  94. );
  95. }
  96. Widget _buildBotton() {
  97. return Container(
  98. margin: EdgeInsets.only(top: 30),
  99. child: Row(
  100. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  101. children: <Widget>[
  102. _buildCancelButton(),
  103. _buildRegisterButton(),
  104. ],
  105. ),
  106. );
  107. }
  108. //构建注册按钮
  109. Widget _buildRegisterButton() {
  110. Text text = new Text(
  111. widget.isBind ? I18n.of(context).determine : I18n.of(context).save,
  112. textScaleFactor: 1.0,
  113. style: TextStyle(fontSize: 15, color: Colors.white));
  114. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  115. Constants.ConfrimButtonColor,
  116. Constants.ConfrimButtonColor
  117. ]);
  118. callback() {
  119. if (nickNameController.text == '') {
  120. showToast(I18n.of(context).enter_name);
  121. return;
  122. }
  123. if (bankCatId == '' || bankCatId == null) {
  124. showToast(I18n.of(context).choose_bank);
  125. return;
  126. }
  127. if (cardIdController.text == '') {
  128. showToast(I18n.of(context).bank_number);
  129. return;
  130. }
  131. if (idController.text == '') {
  132. showToast(I18n.of(context).id_number);
  133. return;
  134. }
  135. if (mobileController.text == '') {
  136. showToast(I18n.of(context).enter_number);
  137. return;
  138. }
  139. widget.isBind ? addBank() : editBank();
  140. }
  141. return new Container(
  142. height: 44,
  143. width: MediaQuery.of(context).size.width * 0.4,
  144. child: ShadowButton().builder(gradientColor, text, callback),
  145. );
  146. }
  147. void addBank() async {
  148. var data = {
  149. "userId": UserData().basicInfo.userId,
  150. "name": nickNameController.text,
  151. "idNumber": idController.text,
  152. };
  153. data['sign'] = TokenMgr().getSign(data);
  154. data['bId'] = bankCatId;
  155. data['cardNo'] = cardIdController.text;
  156. data['mobile'] = mobileController.text;
  157. Response res = await HttpUtil().post('wallet/banding/bankcard', data: data);
  158. if (res == null) {
  159. return;
  160. }
  161. Map resData = res.data;
  162. if (resData['code'] == 0) {
  163. Navigator.of(context).pop();
  164. MessageMgr().emit('bind_bank', {
  165. 'Name': data['name'],
  166. 'Bid': bankCatId,
  167. 'CardNo': data['cardNo'],
  168. 'IdNumber': data['idNumber'],
  169. 'MobileNo': data['mobile']
  170. });
  171. showToast(resData['msg']);
  172. return;
  173. }
  174. }
  175. void editBank() async {
  176. var data = {
  177. "userId": UserData().basicInfo.userId,
  178. "cId": bankInfo['CId'],
  179. "name": nickNameController.text,
  180. "idNumber": idController.text,
  181. };
  182. data['sign'] = TokenMgr().getSign(data);
  183. data['bId'] = bankCatId;
  184. data['mobile'] = mobileController.text;
  185. data['cardNo'] = cardIdController.text;
  186. Response res = await HttpUtil().post('wallet/edit/accountbank', data: data);
  187. if (res == null) {
  188. return ;
  189. }
  190. Map resData = res.data;
  191. if (resData['code'] == 0) {
  192. Navigator.of(context).pop();
  193. MessageMgr().emit('bind_bank', {
  194. 'Name': data['name'],
  195. 'Bid': bankCatId,
  196. 'CardNo': data['cardNo'],
  197. 'IdNumber': data['idNumber'],
  198. 'MobileNo': data['mobile']
  199. });
  200. showToast(resData['msg']);
  201. return;
  202. }
  203. }
  204. //构建注册按钮
  205. Widget _buildCancelButton() {
  206. Text text = new Text(
  207. widget.isBind ? I18n.of(context).cancel : I18n.of(context).cancel,
  208. textScaleFactor: 1.0,
  209. style: TextStyle(fontSize: 15, color: Constants.BlackTextColor));
  210. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  211. Colors.white,
  212. Colors.white,
  213. ]);
  214. callback() {
  215. Navigator.of(context).pop();
  216. }
  217. return new Container(
  218. height: 44,
  219. width: MediaQuery.of(context).size.width * 0.4,
  220. child: ShadowButton().builder(gradientColor, text, callback),
  221. );
  222. }
  223. Widget _buildInputList() {
  224. return Container(
  225. margin: EdgeInsets.only(top: 10),
  226. color: Colors.white,
  227. child: Column(
  228. children: <Widget>[
  229. _buildItem(I18n.of(context).name, nickNameController,
  230. [LengthLimitingTextInputFormatter(8)]),
  231. _buildDivider(),
  232. _buildSelectRank(I18n.of(context).career10, selectBankCat),
  233. _buildDivider(),
  234. _buildItem(I18n.of(context).bank_number2, cardIdController, [
  235. WhitelistingTextInputFormatter.digitsOnly,
  236. LengthLimitingTextInputFormatter(30)
  237. ]),
  238. _buildDivider(),
  239. _buildItem(I18n.of(context).license_number, idController, [
  240. WhitelistingTextInputFormatter.digitsOnly,
  241. LengthLimitingTextInputFormatter(20)
  242. ]),
  243. _buildDivider(),
  244. _buildItem(I18n.of(context).bind_phone, mobileController, [
  245. WhitelistingTextInputFormatter.digitsOnly,
  246. LengthLimitingTextInputFormatter(11)
  247. ]),
  248. // _buildDivider(),
  249. // _buildVerifyCode()
  250. ],
  251. ),
  252. );
  253. }
  254. void selectBankCat() async {
  255. Result temp = await CityPickers.showCityPicker(
  256. context: context,
  257. showType: ShowType.p,
  258. provincesData: WebData().bankData,
  259. citiesData: WebData().bankListData,
  260. height: 400,
  261. );
  262. setState(() {
  263. if (temp == null) return;
  264. bankId = temp.provinceName;
  265. bankCatId = temp.provinceId;
  266. });
  267. }
  268. Widget _buildSelectRank(str, callback) {
  269. return Container(
  270. height: 45,
  271. child: Row(
  272. crossAxisAlignment: CrossAxisAlignment.center,
  273. children: <Widget>[
  274. Container(
  275. width: 100,
  276. padding: EdgeInsets.only(left: 25),
  277. child: Text(
  278. str,
  279. textScaleFactor: 1.0,
  280. ),
  281. ),
  282. Expanded(
  283. child: new InkWell(
  284. highlightColor: Colors.transparent,
  285. radius: 0.0,
  286. onTap: callback,
  287. child: Padding(
  288. padding: EdgeInsets.only(left: 35),
  289. child: new Text(
  290. bankId,
  291. textScaleFactor: 1.0,
  292. style: TextStyle(fontSize: 14),
  293. ),
  294. ),
  295. ))
  296. ],
  297. ),
  298. );
  299. }
  300. Widget _buildItem(str, controller, inputFormatters) {
  301. return Container(
  302. height: 45,
  303. child: Row(
  304. crossAxisAlignment: CrossAxisAlignment.center,
  305. children: <Widget>[
  306. Container(
  307. width: 100,
  308. padding: EdgeInsets.only(left: 25),
  309. child: Text(
  310. str,
  311. textScaleFactor: 1.0,
  312. ),
  313. ),
  314. Expanded(
  315. child: Container(
  316. alignment: Alignment.center,
  317. padding: EdgeInsets.only(left: 25),
  318. child: TextField(
  319. keyboardAppearance: Brightness.light,
  320. style: TextStyle(fontSize: 14,textBaseline: TextBaseline.alphabetic),
  321. controller: controller,
  322. decoration: new InputDecoration(
  323. hintText: I18n.of(context).fill_out,
  324. hintStyle: TextStyle(fontSize: 14),
  325. border: InputBorder.none,
  326. ),
  327. maxLines: 1,
  328. inputFormatters: inputFormatters,
  329. //onChanged: callback,
  330. ),
  331. ),
  332. ),
  333. ],
  334. ),
  335. );
  336. }
  337. //下划线
  338. Widget _buildDivider() {
  339. return new Container(
  340. margin: EdgeInsets.zero,
  341. padding: EdgeInsets.zero,
  342. width: MediaQuery.of(context).size.width * 0.85,
  343. child: new Divider(
  344. color: Colors.grey[300],
  345. height: 0.1,
  346. ),
  347. );
  348. }
  349. }