Browse Source

'添加银行卡99%

李志伟 3 years ago
parent
commit
9f091eb8f3

+ 7
- 0
lib/models/bankCardList.dart View File

@@ -0,0 +1,7 @@
1
+import 'package:get/get.dart';
2
+import 'package:worker_client/models/entities/BankCard.dart';
3
+
4
+class BankCardListController extends GetxController{
5
+  static BankCardListController t=Get.find();
6
+  final bankCardList=Rx<List<BankCardModel>>([]);
7
+}

+ 3
- 0
lib/models/index.dart View File

@@ -1,6 +1,8 @@
1 1
 
2 2
 export 'app.dart';
3 3
 
4
+import 'package:worker_client/models/bankCardList.dart';
5
+
4 6
 import '../models/app.dart';
5 7
 import 'package:get/get.dart';
6 8
 
@@ -8,6 +10,7 @@ class AppBindings implements Bindings {
8 10
   @override
9 11
   void dependencies() {
10 12
     Get.put(AppController());
13
+    Get.put(BankCardListController());
11 14
   }
12 15
 }
13 16
 

+ 245
- 224
lib/pages/addBankCard/index.dart View File

@@ -1,252 +1,273 @@
1
-import 'dart:convert';
2
-
3 1
 import 'package:flutter/material.dart';
4 2
 import 'package:flutter_screenutil/flutter_screenutil.dart';
5 3
 import 'package:fluttertoast/fluttertoast.dart';
6 4
 import 'package:get/get.dart';
7
-import '../../widgets/MyButton/index.dart';
8
-import '../../widgets/MyCard/widgets/CardCell.dart';
9
-import '../../widgets/layout/BasicPage.dart';
5
+import 'package:worker_client/models/app.dart';
6
+import 'package:worker_client/models/bankCardList.dart';
7
+import 'package:worker_client/models/entities/Bank.dart';
8
+import 'package:worker_client/models/entities/BankCard.dart';
9
+import 'package:worker_client/services/bank.dart';
10
+import 'package:worker_client/widgets/MyButton/index.dart';
11
+import 'package:worker_client/widgets/layout/BasicPage.dart';
10 12
 import 'package:flutter_picker/flutter_picker.dart';
11 13
 
12 14
 class AddBankPage extends BasicPage {
13 15
   AddBankPage({Key? key}) : super(key: key) {
14
-    naviTitle = '绑定银行卡';
16
+    naviTitle = '我的银行卡';
15 17
   }
18
+  final bankList = Rx<List<Bank>>([]);
19
+  dynamic pickerData = [];
20
+  int index = 0;
21
+  final bankCard = Rx<Map>({});
22
+  AppController store = AppController.t;
23
+  BankCardListController bankCardListStore = BankCardListController.t;
24
+  RegExp exp = RegExp(r'^1[3456789]\d{9}$');
16 25
 
17
-  // late Map  bankBrand;
18
-  final bankBrand = Rx<Map>({});
26
+  //表单校验
27
+  bool handleRule() {
28
+    if (bankCard.value['owerName'] == null) {
29
+      Fluttertoast.showToast(msg: '请输入持卡人姓名');
30
+      return false;
31
+    }
32
+    if (bankCard.value['cardNo'] == null) {
33
+      Fluttertoast.showToast(msg: '请输入卡号');
34
+      return false;
35
+    }
36
+    if (bankCard.value['ownerBank'] == null) {
37
+      Fluttertoast.showToast(msg: '请选择开户行');
38
+      return false;
39
+    }
40
+    if (bankCard.value['phone'] == null ||
41
+        !exp.hasMatch(bankCard.value['phone'])) {
42
+      Fluttertoast.showToast(msg: '请输入正确手机号');
43
+      return false;
44
+    }
45
+    bankCard.value['personId'] = store.user().personId;
46
+    return true;
47
+  }
19 48
 
20
-  TextEditingController _unameController = TextEditingController();
21
-  TextEditingController _bankController = TextEditingController();
22
-  TextEditingController _phoneController = TextEditingController();
23
-  GlobalKey _formKey = GlobalKey<FormState>();
49
+  showPicker(BuildContext context) {
50
+    Picker picker = Picker(
51
+        height: 295.w,
52
+        itemExtent: 40.h,
53
+        adapter: PickerDataAdapter<String>(pickerdata: pickerData),
54
+        selecteds: [index],
55
+        changeToFirst: true,
56
+        onCancel: () {},
57
+        confirmText: '确定',
58
+        cancelText: '取消',
59
+        cancelTextStyle:
60
+            const TextStyle(color: Color(0xff7f7f7f), fontSize: 20),
61
+        confirmTextStyle:
62
+            const TextStyle(color: Color(0xff07c160), fontSize: 20),
63
+        textStyle: const TextStyle(color: Color(0xff191919), fontSize: 20),
64
+        selectedTextStyle:
65
+            const TextStyle(color: Color(0xff191919), fontSize: 20),
66
+        onConfirm: (Picker picker, List<int> value) {
67
+          index = value.first;
68
+          bankCard({
69
+            ...bankCard(),
70
+            'ownerBank': bankList.value[index].name.toString()
71
+          });
72
+        });
73
+    picker.showModal(context);
74
+  }
24 75
 
76
+  @override
77
+  void beforeShow() {
78
+    super.beforeShow();
79
+    getBankList({'pageSize': 500}).then(
80
+      (res) {
81
+        var list = <Bank>[];
82
+        res['records'].forEach((item) {
83
+          list.add(Bank.fromJson(item));
84
+          pickerData.add(Bank.fromJson(item).name);
85
+        });
86
+        bankList(list);
87
+      },
88
+    );
89
+  }
25 90
 
26 91
   @override
27 92
   Widget builder(BuildContext context) {
28
-    return Container(
29
-      // alignment: Alignment.bottomLeft,
30
-      child: Form(
31
-        key: _formKey, //设置globalKey,用于后面获取FormState
32
-        autovalidateMode: AutovalidateMode.onUserInteraction,
33
-        child: Column(
34
-          crossAxisAlignment: CrossAxisAlignment.start,
35
-          children: <Widget>[
36
-            Padding(
37
-                padding: EdgeInsets.fromLTRB(15, 15, 0, 5),
93
+    return Column(
94
+      crossAxisAlignment: CrossAxisAlignment.start,
95
+      children: [
96
+        Padding(
97
+          padding: EdgeInsets.fromLTRB(15.w, 10.h, 0, 0),
98
+          child: Text(
99
+            '请绑定持卡人本人的银行卡',
100
+            style: TextStyle(
101
+                fontSize: 14.sp,
102
+                fontWeight: FontWeight.w500,
103
+                color: const Color(0xff323232)),
104
+          ),
105
+        ),
106
+        Container(
107
+          margin: EdgeInsets.only(top: 10.h),
108
+          padding: EdgeInsets.symmetric(horizontal: 15.w),
109
+          color: Colors.white,
110
+          height: 54.h,
111
+          child: Row(
112
+            children: [
113
+              Padding(
114
+                padding: EdgeInsets.only(right: 25.w),
38 115
                 child: Text(
39
-                  '请绑定持卡人本人的银行卡',
116
+                  '持 卡 人 姓 名:',
40 117
                   style: TextStyle(
41
-                    fontSize: 16.sp,
42
-                  ),
43
-                )),
44
-            Container(
45
-              margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
46
-              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
47
-              color: Colors.white,
48
-              height: 54.w,
49
-              child: Row(
50
-                children: [
51
-                  Padding(padding: EdgeInsets.fromLTRB(0, 0, 18, 0),
52
-                    child:Text(
53
-                      '持卡人姓名:',
54
-                      style: TextStyle(
55
-                          fontSize: 18.sp,
56
-                          color: const Color(0xFF606060),
57
-                          fontWeight: FontWeight.bold,
58
-                          letterSpacing: 0),
59
-                    ),
60
-                  ),
61
-                  Expanded(
62
-                    child: TextFormField(
63
-                      controller: _unameController,
64
-                      decoration: InputDecoration(
65
-                        contentPadding:
66
-                            const EdgeInsets.symmetric(vertical: 4.0),
67
-                        hintText: '请输入真实姓名',
68
-                        border: OutlineInputBorder(
69
-                            borderRadius: BorderRadius.circular(15),
70
-                            borderSide: BorderSide.none),
71
-                      ),
72
-                      // 校验用户名
73
-                      validator: (v) {
74
-                        return v!.trim().isNotEmpty ? null : "真实姓名不能为空";
75
-                      },
76
-                    ),
77
-                  ),
78
-                ],
118
+                      fontSize: 16.sp,
119
+                      color: const Color(0xFF333333),
120
+                      fontWeight: FontWeight.w500),
121
+                ),
79 122
               ),
80
-            ),
81
-            Container(
82
-              color: Colors.white,
83
-              height: 54.w,
84
-              margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
85
-              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
86
-              child: Row(
87
-                children: [
88
-                  Padding(padding: EdgeInsets.fromLTRB(0, 0, 15, 0),
89
-                    child:Text(
90
-                      '卡号:',
91
-                      textAlign: TextAlign.left,
92
-                      style: TextStyle(
93
-                        fontSize: 18.sp,
94
-                        color: const Color(0xFF606060),
95
-                        fontWeight: FontWeight.bold,
96
-                        letterSpacing: 17,
97
-                      ),
98
-                    ),
99
-                  ),
100
-                  Expanded(
101
-                    child: TextFormField(
102
-                      controller: _bankController,
103
-                      decoration: InputDecoration(
104
-                        contentPadding:
105
-                            const EdgeInsets.symmetric(vertical: 4.0),
106
-                        hintText: '请输入有效卡号',
107
-                        border: OutlineInputBorder(
108
-                            borderRadius: BorderRadius.circular(15),
109
-                            borderSide: BorderSide.none),
110
-                      ),
111
-                      // obscureText: true,
112
-                      //校验密码
113
-                      validator: (v) {
114
-                        return v!.trim().isNotEmpty ? null : "卡号不能为空";
115
-                      },
116
-                    ),
123
+              Expanded(
124
+                child: TextFormField(
125
+                  decoration: const InputDecoration(
126
+                    contentPadding: EdgeInsets.symmetric(vertical: 4.0),
127
+                    hintText: '请输入真实姓名',
128
+                    border: OutlineInputBorder(borderSide: BorderSide.none),
117 129
                   ),
118
-                ],
130
+                  onChanged: (e) {
131
+                    bankCard.value['owerName'] = e;
132
+                  },
133
+                ),
119 134
               ),
120
-            ),
121
-            Container(
122
-              color: Colors.white,
123
-              height: 54.w,
124
-              margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
125
-              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
126
-              child: Row(
127
-                children: [
128
-                  Text(
129
-                    '开户行:',
130
-                    textAlign: TextAlign.left,
131
-                    style: TextStyle(
132
-                      fontSize: 18.sp,
133
-                      color: const Color(0xFF606060),
134
-                      fontWeight: FontWeight.bold,
135
-                      letterSpacing: 8,
136
-                    ),
137
-                  ),
138
-                  Expanded(
139
-                      child: ListTile(
140
-                        title:Obx(()=>Text(bankBrand.value.length==0?'请选择银行':bankBrand.value['name'])),
141
-                        onTap: () {
142
-                          showPicker(context);
143
-                        },
144
-                      ),
145
-
146
-                  ),
147
-                ],
135
+            ],
136
+          ),
137
+        ),
138
+        Container(
139
+          margin: EdgeInsets.only(top: 10.h),
140
+          padding: EdgeInsets.symmetric(horizontal: 15.w),
141
+          color: Colors.white,
142
+          height: 54.h,
143
+          child: Row(
144
+            children: [
145
+              Padding(
146
+                padding: EdgeInsets.only(right: 25.w),
147
+                child: Text(
148
+                  '卡                号:',
149
+                  style: TextStyle(
150
+                      fontSize: 16.sp,
151
+                      color: const Color(0xFF333333),
152
+                      fontWeight: FontWeight.w500),
153
+                ),
148 154
               ),
149
-            ),
150
-            Container(
151
-              color: Colors.white,
152
-              height: 54.w,
153
-              margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
154
-              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
155
-              child: Row(
156
-                children: [
157
-                  Padding(padding: EdgeInsets.fromLTRB(0, 0, 18, 0),
158
-                      child: Text(
159
-                        '预留手机号:',
160
-                        style: TextStyle(
161
-                            fontSize: 18.sp,
162
-                            color: const Color(0xFF606060),
163
-                            fontWeight: FontWeight.bold,
164
-                            letterSpacing: 0),
165
-                      ),
166
-                  ),
167
-
168
-                  Expanded(
169
-                    child: TextFormField(
170
-                      controller: _phoneController,
171
-                      decoration: InputDecoration(
172
-                        contentPadding:
173
-                            const EdgeInsets.symmetric(vertical: 4.0),
174
-                        hintText: '请输入银行卡预留手机号',
175
-                        border: OutlineInputBorder(
176
-                            borderRadius: BorderRadius.circular(15),
177
-                            borderSide: BorderSide.none),
178
-                      ),
179
-                      //校验密码
180
-                      validator: (v) {
181
-                        return v!.trim().isNotEmpty ? null : "预留手机号不能为空";
182
-                      },
183
-                    ),
155
+              Expanded(
156
+                child: TextFormField(
157
+                  keyboardType: TextInputType.number,
158
+                  decoration: const InputDecoration(
159
+                    contentPadding: EdgeInsets.symmetric(vertical: 4.0),
160
+                    hintText: '请输入有效卡号',
161
+                    border: OutlineInputBorder(borderSide: BorderSide.none),
184 162
                   ),
185
-                ],
163
+                  onChanged: (e) {
164
+                    bankCard.value['cardNo'] = e;
165
+                  },
166
+                ),
186 167
               ),
187
-            ),
188
-
189
-            // 登录按钮
190
-            Padding(
191
-              padding: const EdgeInsets.only(top: 35.0),
192
-              child: Row(
193
-                children: <Widget>[
194
-                  Container(
195
-                    width:360.w,
196
-
197
-                    height:65.w ,
198
-                    alignment:Alignment.center,
199
-                    child:   MyButton(
200
-                        text: '绑定',
201
-                        type:  0,
202
-                        disable: false,
203
-                        onClick: (){
204
-                          if ((_formKey.currentState as FormState).validate()&&bankBrand.value.length!=0) {
205
-                            print('ok');
206
-                            //验证通过提交数据
207
-                          }else{
208
-                            Fluttertoast.showToast(
209
-                                msg: '请完整填写表单内容'
210
-                            );
211
-                          }
212
-                        }
213
-                    ),
214
-                  )
215
-
216
-                ],
168
+            ],
169
+          ),
170
+        ),
171
+        Container(
172
+          margin: EdgeInsets.only(top: 10.h),
173
+          padding: EdgeInsets.symmetric(horizontal: 15.w),
174
+          color: Colors.white,
175
+          height: 54.h,
176
+          child: Row(
177
+            children: [
178
+              Padding(
179
+                padding: EdgeInsets.only(right: 25.w),
180
+                child: Text(
181
+                  '开      户      行:',
182
+                  style: TextStyle(
183
+                      fontSize: 16.sp,
184
+                      color: const Color(0xFF333333),
185
+                      fontWeight: FontWeight.w500),
186
+                ),
187
+              ),
188
+              Expanded(
189
+                child: GestureDetector(
190
+                  child: Obx(() => Text(bankCard.value['ownerBank'] == null
191
+                      ? '请选择银行'
192
+                      : bankCard.value['ownerBank'].toString())),
193
+                  onTap: () {
194
+                    showPicker(context);
195
+                  },
196
+                ),
197
+              ),
198
+            ],
199
+          ),
200
+        ),
201
+        Container(
202
+          margin: EdgeInsets.only(top: 10.h),
203
+          padding: EdgeInsets.symmetric(horizontal: 15.w),
204
+          color: Colors.white,
205
+          height: 54.h,
206
+          child: Row(
207
+            children: [
208
+              Padding(
209
+                padding: EdgeInsets.only(right: 25.w),
210
+                child: Text(
211
+                  '预 留 手 机 号:',
212
+                  style: TextStyle(
213
+                      fontSize: 16.sp,
214
+                      color: const Color(0xFF333333),
215
+                      fontWeight: FontWeight.w500),
216
+                ),
217 217
               ),
218
-            )
219
-          ],
218
+              Expanded(
219
+                child: TextFormField(
220
+                  keyboardType: TextInputType.number,
221
+                  maxLength: 11,
222
+                  decoration: const InputDecoration(
223
+                    counterText: '',
224
+                    //有就行了  如果文本框不设padding就会向右上偏移
225
+                    contentPadding: EdgeInsets.symmetric(vertical: 1),
226
+                    hintText: '请输入银行卡预留手机号',
227
+                    border: OutlineInputBorder(borderSide: BorderSide.none),
228
+                  ),
229
+                  onChanged: (e) {
230
+                    bankCard.value['phone'] = e;
231
+                  },
232
+                ),
233
+              ),
234
+            ],
235
+          ),
236
+        ),
237
+        const Spacer(),
238
+        Container(
239
+          margin: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 30.h),
240
+          child: MyButton(
241
+            pwith: 30.w,
242
+            text: '绑定',
243
+            type: 0,
244
+            disable: false,
245
+            onClick: () {
246
+              if (handleRule()) {
247
+                addBankCard(bankCard.value).then(
248
+                  (e) {
249
+                    bankList.value.forEach((item) {
250
+                      if (item.name == e['ownerBank']) {
251
+                        e['color1'] = item.color1;
252
+                        e['color2'] = item.color2;
253
+                        e['bankCode'] = item.bankCode;
254
+                      }
255
+                    });
256
+                    List<BankCardModel> list = [];
257
+                    for (var e in bankCardListStore.bankCardList()) {
258
+                      list.add(e);
259
+                    }
260
+                    list.add(BankCardModel.fromJson(e));
261
+                    bankCardListStore.bankCardList(list);
262
+                    Get.back();
263
+                    Fluttertoast.showToast(msg: '添加成功');
264
+                  },
265
+                );
266
+              }
267
+            },
268
+          ),
220 269
         ),
221
-      ),
270
+      ],
222 271
     );
223 272
   }
224
-  showPicker(BuildContext context) {
225
-    const PickerData = ['中国建设银河','8s鱼就是','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打','阿三大苏打'];
226
-    Picker picker = Picker(
227
-      height: 230.w,
228
-        adapter: PickerDataAdapter<String>(
229
-            pickerdata: PickerData),
230
-        changeToFirst: false,
231
-        onCancel: (){
232
-          print('object');
233
-        },
234
-        confirmText: '确定',
235
-        cancelText: '取消',
236
-        textAlign: TextAlign.left,
237
-        textStyle: TextStyle(color: Colors.blue, ),
238
-        selectedTextStyle: TextStyle(color: Colors.red),
239
-        columnPadding: const EdgeInsets.all(8.0),
240
-        onConfirm: (Picker picker, List<int> value) {
241
-          print('666666666$value');
242
-          // bankBrand(picker);
243
-          int index = value.first;
244
-          bankBrand({'id':index,'name':picker.getSelectedValues().first});
245
-          print(bankBrand);
246
-        }
247
-        );
248
-    picker.showModal(context);
249
-  }
250
-
251 273
 }
252
-

+ 30
- 27
lib/pages/bankList/index.dart View File

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
3 3
 import 'package:flutter_screenutil/flutter_screenutil.dart';
4 4
 import 'package:fluttertoast/fluttertoast.dart';
5 5
 import 'package:get/get.dart';
6
+import 'package:worker_client/models/bankCardList.dart';
6 7
 import 'package:worker_client/models/entities/Bank.dart';
7 8
 import 'package:worker_client/models/entities/BankCard.dart';
8 9
 import 'package:worker_client/pages/bankList/widget/BankCard.dart';
@@ -14,8 +15,7 @@ class BankListPages extends BasicPage {
14 15
   BankListPages({Key? key}) : super(key: key) {
15 16
     naviTitle = '我的银行卡';
16 17
   }
17
-  final bankCardList = Rx<List<BankCardModel>>([]);
18
-
18
+  BankCardListController bankCardListStore = BankCardListController.t;
19 19
   @override
20 20
   void beforeShow() {
21 21
     // TODO: implement beforeShow
@@ -28,32 +28,34 @@ class BankListPages extends BasicPage {
28 28
   }
29 29
 
30 30
   void getList() {
31
-    getBankCardList({'pageSize': 500}).then((res) {
32
-      getBankList({'pageSize': 500}).then((res2) {
33
-        var list1 = <BankCardModel>[];
34
-        var bankcardlist = <BankCardModel>[];
35
-        var banklist = <Bank>[];
36
-        var current;
37
-        res['records'].forEach((item) {
38
-          bankcardlist.add(BankCardModel.fromJson(item));
39
-        });
40
-        res2['records'].forEach((item) {
41
-          banklist.add(Bank.fromJson(item));
42
-        });
43
-        for (var item in bankcardlist) {
44
-          for (var v in banklist) {
45
-            if (item.ownerBank == v.name) {
46
-              current = v;
31
+    if (bankCardListStore.bankCardList().isEmpty) {
32
+      getBankCardList({'pageSize': 500}).then((res) {
33
+        getBankList({'pageSize': 500}).then((res2) {
34
+          var list1 = <BankCardModel>[];
35
+          var bankcardlist = <BankCardModel>[];
36
+          var banklist = <Bank>[];
37
+          var current;
38
+          res['records'].forEach((item) {
39
+            bankcardlist.add(BankCardModel.fromJson(item));
40
+          });
41
+          res2['records'].forEach((item) {
42
+            banklist.add(Bank.fromJson(item));
43
+          });
44
+          for (var item in bankcardlist) {
45
+            for (var v in banklist) {
46
+              if (item.ownerBank == v.name) {
47
+                current = v;
48
+              }
47 49
             }
50
+            item.color1 = current.color1;
51
+            item.color2 = current.color2;
52
+            item.bankCode = current.bankCode;
53
+            list1.add(item);
48 54
           }
49
-          item.color1 = current.color1;
50
-          item.color2 = current.color2;
51
-          item.bankCode = current.bankCode;
52
-          list1.add(item);
53
-        }
54
-        bankCardList(list1);
55
+          bankCardListStore.bankCardList(list1);
56
+        });
55 57
       });
56
-    });
58
+    }
57 59
   }
58 60
 
59 61
   void unBind(id) {
@@ -72,9 +74,10 @@ class BankListPages extends BasicPage {
72 74
         children: [
73 75
           Expanded(
74 76
             child: Obx(
75
-              () => bankCardList.value.isNotEmpty
77
+              () => bankCardListStore.bankCardList.value.isNotEmpty
76 78
                   ? ListView(
77
-                      children: bankCardList.value.map((item) {
79
+                      children:
80
+                          bankCardListStore.bankCardList.value.map((item) {
78 81
                       return BankCard(
79 82
                         item: item,
80 83
                         unBind: () {

+ 1
- 1
lib/pages/bankList/widget/BankCard.dart View File

@@ -46,7 +46,7 @@ class BankCard extends StatelessWidget {
46 46
               Expanded(
47 47
                 flex: 1,
48 48
                 child: Text(
49
-                  item.ownerBank.toString(),
49
+                  item.ownerBank.toString()+'储蓄卡',
50 50
                   style: const TextStyle(
51 51
                     color: Colors.white,
52 52
                   ),