Commit 68fd6edf6b2fb7964c517e4c6894f3b920b61023

Authored by “gaiyaguang”
2 parents 09fd5b57 f9362c88

Merge branch 'v1.5+' of http://123.56.79.57/xt/Flutter-ReserveApp into v1.5+

1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
  2 +import 'package:flutter/services.dart';
2 import 'package:flutter_screenutil/screenutil.dart'; 3 import 'package:flutter_screenutil/screenutil.dart';
3 import 'package:one_key/constant/state.dart'; 4 import 'package:one_key/constant/state.dart';
4 import 'package:one_key/models/remark.dart'; 5 import 'package:one_key/models/remark.dart';
5 import 'package:one_key/provider/remark_manager_model.dart'; 6 import 'package:one_key/provider/remark_manager_model.dart';
6 import 'package:one_key/provider/user_model.dart'; 7 import 'package:one_key/provider/user_model.dart';
7 import 'package:one_key/res/colors.dart'; 8 import 'package:one_key/res/colors.dart';
  9 +import 'package:one_key/utils/utils.dart';
8 import 'package:one_key/widgets/MyDivider.dart'; 10 import 'package:one_key/widgets/MyDivider.dart';
9 import 'package:one_key/widgets/h_empty_view.dart'; 11 import 'package:one_key/widgets/h_empty_view.dart';
10 import 'package:one_key/widgets/page_exception.dart'; 12 import 'package:one_key/widgets/page_exception.dart';
@@ -30,41 +32,56 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -30,41 +32,56 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
30 TextEditingController _controller = TextEditingController(); 32 TextEditingController _controller = TextEditingController();
31 FocusNode focusNode = FocusNode(); 33 FocusNode focusNode = FocusNode();
32 34
  35 + int alwaysCount = 0; //常用备注数
  36 +
33 @override 37 @override
34 void initState() { 38 void initState() {
35 // TODO: implement initState 39 // TODO: implement initState
36 super.initState(); 40 super.initState();
37 41
38 WidgetsBinding.instance.addPostFrameCallback((timeStamp) { 42 WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
39 - _getRemarks(); 43 + _getRemarks(showPageLoading: true);
40 }); 44 });
41 } 45 }
42 46
43 //获取备注 47 //获取备注
44 - _getRemarks() { 48 + _getRemarks({bool showPageLoading = false}) {
45 Map<String, String> params = { 49 Map<String, String> params = {
46 "uid": Provider.of<UserModel>(context, listen: false).user.openid 50 "uid": Provider.of<UserModel>(context, listen: false).user.openid
47 }; 51 };
48 - remarkManagerModel.getRemarks(context, params); 52 + remarkManagerModel.getRemarks(context, params,
  53 + showPageLoading: showPageLoading);
49 } 54 }
50 55
51 //添加备注 56 //添加备注
52 - _addRemark() { 57 + _addRemark() async {
53 Map<String, String> params = { 58 Map<String, String> params = {
54 "uid": Provider.of<UserModel>(context, listen: false).user.openid, 59 "uid": Provider.of<UserModel>(context, listen: false).user.openid,
55 "custom": _controller.text 60 "custom": _controller.text
56 }; 61 };
57 - remarkManagerModel.addRemark(context, params); 62 + await remarkManagerModel.addRemark(context, params);
  63 + _getRemarks(showPageLoading: false); //添加完重新获取备注信息
58 } 64 }
59 65
60 - //删除备注  
61 - _delRemark(Remark remark) { 66 + //添加常用备注
  67 + _addCustomRemark(Remark remark) {
  68 + Map<String, String> params = {
  69 + "uid": Provider.of<UserModel>(context, listen: false).user.openid,
  70 + "kid": remark.id,
  71 + "flag": "custom"
  72 + };
  73 + remarkManagerModel.getRemarks(context, params);
  74 + }
  75 +
  76 + //取消常用备注
  77 + _delCustomRemark(Remark remark) {
62 if (remark.id == "-1") return; 78 if (remark.id == "-1") return;
63 Map<String, String> params = { 79 Map<String, String> params = {
64 "uid": Provider.of<UserModel>(context, listen: false).user.openid, 80 "uid": Provider.of<UserModel>(context, listen: false).user.openid,
65 "kid": remark.id, 81 "kid": remark.id,
  82 + "flag": "often"
66 }; 83 };
67 - remarkManagerModel.delRemark(context, params); 84 + remarkManagerModel.getRemarks(context, params);
68 } 85 }
69 86
70 //构建常用备注 87 //构建常用备注
@@ -98,24 +115,24 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -98,24 +115,24 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
98 color: MyColours.color_6AB6B9, 115 color: MyColours.color_6AB6B9,
99 ), 116 ),
100 GestureDetector( 117 GestureDetector(
101 - onTap: () {  
102 - setState(() {  
103 - remark.oftenUse = "";  
104 - });  
105 - _delRemark(remark);  
106 - },  
107 - child: Padding( 118 + onTap: () {
  119 + setState(() {
  120 + remark.oftenUse = "";
  121 + });
  122 + _delCustomRemark(remark);
  123 + },
  124 + child: Padding(
108 padding: EdgeInsets.all(ScreenUtil().setWidth(10)), 125 padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
109 - child: Text(  
110 - "X",  
111 - style: TextStyle(  
112 - color: MyColours.color_ffffff,  
113 - fontSize: ScreenUtil().setSp(30)),  
114 - )),  
115 - ) 126 + child: Image.asset(
  127 + "assets/icon_remark_del.png",
  128 + width: ScreenUtil().setWidth(18),
  129 + height: ScreenUtil().setWidth(18),
  130 + ),
  131 + ))
116 ]), 132 ]),
117 )); 133 ));
118 } 134 }
  135 + alwaysCount = always.length;
119 return always; 136 return always;
120 } 137 }
121 138
@@ -126,8 +143,13 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -126,8 +143,13 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
126 alls.add( 143 alls.add(
127 GestureDetector( 144 GestureDetector(
128 onTap: () { 145 onTap: () {
  146 + if (alwaysCount >= 10) {
  147 + Utils.showToast("最多添加10个常用备注");
  148 + return;
  149 + }
129 setState(() { 150 setState(() {
130 remark.oftenUse = remark.custom; 151 remark.oftenUse = remark.custom;
  152 + _addCustomRemark(remark);
131 }); 153 });
132 }, 154 },
133 child: Container( 155 child: Container(
@@ -170,6 +192,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -170,6 +192,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
170 ? Container( 192 ? Container(
171 width: ScreenUtil().setWidth(200), 193 width: ScreenUtil().setWidth(200),
172 height: ScreenUtil().setWidth(50), 194 height: ScreenUtil().setWidth(50),
  195 + alignment: Alignment.center,
173 padding: 196 padding:
174 EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)), 197 EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
175 decoration: BoxDecoration( 198 decoration: BoxDecoration(
@@ -178,46 +201,43 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -178,46 +201,43 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
178 width: ScreenUtil().setWidth(2)), 201 width: ScreenUtil().setWidth(2)),
179 borderRadius: 202 borderRadius:
180 BorderRadius.circular(ScreenUtil().setWidth(10))), 203 BorderRadius.circular(ScreenUtil().setWidth(10))),
181 - child: Expanded(  
182 - child: TextField(  
183 - controller: _controller,  
184 - focusNode: focusNode,  
185 - autofocus: true,  
186 - textInputAction: TextInputAction.done,  
187 - textAlignVertical: TextAlignVertical.center,  
188 - keyboardType: TextInputType.text,  
189 - maxLength: 10,  
190 - decoration: InputDecoration(  
191 - border: InputBorder.none,  
192 - ),  
193 - style: TextStyle(  
194 - color: MyColours.color_353535,  
195 - fontSize: ScreenUtil().setSp(30),  
196 - textBaseline:  
197 - TextBaseline.alphabetic),  
198 - onEditingComplete: () {  
199 - if(_controller.text.isEmpty){  
200 - setState(() {  
201 - isAdding=false;  
202 - return;  
203 - });  
204 - } 204 + child: TextField(
  205 + controller: _controller,
  206 + focusNode: focusNode,
  207 + autofocus: true,
  208 + textInputAction: TextInputAction.done,
  209 + textAlignVertical: TextAlignVertical.center,
  210 + keyboardType: TextInputType.text,
  211 + decoration: InputDecoration.collapsed(hintText: ""),
  212 + inputFormatters: [LengthLimitingTextInputFormatter(10)],
  213 + style: TextStyle(
  214 + color: MyColours.color_353535,
  215 + fontSize: ScreenUtil().setSp(30),
  216 + textBaseline: TextBaseline.alphabetic),
  217 + onEditingComplete: () {
  218 + if (_controller.text.isEmpty) {
205 setState(() { 219 setState(() {
206 isAdding = false; 220 isAdding = false;
207 - remarkManagerModel.remarks.add(Remark()  
208 - ..id = "-1"  
209 - ..custom = _controller.text  
210 - ..oftenUse = _controller.text); 221 + return;
211 }); 222 });
212 - _addRemark();  
213 - _controller.clear();  
214 - },  
215 - ),  
216 - ),  
217 - ) 223 + }
  224 + setState(() {
  225 + isAdding = false;
  226 + });
  227 + _addRemark();
  228 + _controller.clear();
  229 + },
  230 + ))
218 : GestureDetector( 231 : GestureDetector(
219 onTap: () { 232 onTap: () {
220 - if(remarkManagerModel.remarks.length>=20)return; 233 + if (remarkManagerModel.remarks.length >= 20) {
  234 + Utils.showToast("最多添加20个备注");
  235 + return;
  236 + }
  237 + if (alwaysCount >= 10) {
  238 + Utils.showToast("最多添加10个常用备注");
  239 + return;
  240 + }
221 setState(() { 241 setState(() {
222 isAdding = true; 242 isAdding = true;
223 }); 243 });
@@ -235,10 +255,10 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -235,10 +255,10 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
235 child: Row( 255 child: Row(
236 mainAxisSize: MainAxisSize.min, 256 mainAxisSize: MainAxisSize.min,
237 children: [ 257 children: [
238 - Icon(  
239 - Icons.add,  
240 - size: ScreenUtil().setWidth(30),  
241 - color: MyColours.color_999999, 258 + Image.asset(
  259 + "assets/icon_remark_add.png",
  260 + width: ScreenUtil().setWidth(30),
  261 + height: ScreenUtil().setWidth(30),
242 ), 262 ),
243 HEmptyView(10), 263 HEmptyView(10),
244 Text( 264 Text(
@@ -276,7 +296,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -276,7 +296,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
276 return ExceptionPage( 296 return ExceptionPage(
277 pageState: model.pageState, 297 pageState: model.pageState,
278 callback: () { 298 callback: () {
279 - _getRemarks(); 299 + _getRemarks(showPageLoading: true);
280 }, 300 },
281 emptyMsg: "暂时没有备注哦", 301 emptyMsg: "暂时没有备注哦",
282 emptyImg: "empty_search", 302 emptyImg: "empty_search",
@@ -310,13 +330,12 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -310,13 +330,12 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
310 ), 330 ),
311 Padding( 331 Padding(
312 padding: EdgeInsets.symmetric( 332 padding: EdgeInsets.symmetric(
313 - vertical: ScreenUtil().setWidth(20)), 333 + vertical: ScreenUtil().setWidth(40)),
314 child: Wrap( 334 child: Wrap(
315 spacing: ScreenUtil().setWidth(20), 335 spacing: ScreenUtil().setWidth(20),
316 runSpacing: ScreenUtil().setWidth(20), 336 runSpacing: ScreenUtil().setWidth(20),
317 children: _buildAlwayItems()), 337 children: _buildAlwayItems()),
318 ), 338 ),
319 - VEmptyView(20),  
320 MyDivider( 339 MyDivider(
321 double.infinity, 340 double.infinity,
322 ScreenUtil().setWidth(2), 341 ScreenUtil().setWidth(2),
@@ -343,7 +362,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { @@ -343,7 +362,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> {
343 ), 362 ),
344 Padding( 363 Padding(
345 padding: EdgeInsets.symmetric( 364 padding: EdgeInsets.symmetric(
346 - vertical: ScreenUtil().setWidth(20)), 365 + vertical: ScreenUtil().setWidth(40)),
347 child: Wrap( 366 child: Wrap(
348 spacing: ScreenUtil().setWidth(20), 367 spacing: ScreenUtil().setWidth(20),
349 runSpacing: ScreenUtil().setWidth(20), 368 runSpacing: ScreenUtil().setWidth(20),
@@ -18,12 +18,14 @@ class RemarkManagerModel extends ChangeNotifier{ @@ -18,12 +18,14 @@ class RemarkManagerModel extends ChangeNotifier{
18 18
19 19
20 //获取备注 20 //获取备注
21 - getRemarks(BuildContext context, Map<String, String> params) async {  
22 - pageState = PageState.Loading;  
23 - notifyListeners(); 21 + getRemarks(BuildContext context, Map<String, String> params,{bool showPageLoading=false}) async {
  22 + if(showPageLoading){
  23 + pageState = PageState.Loading;
  24 + notifyListeners();
  25 + }
24 BaseResp<List> baseResp = await DioUtil() 26 BaseResp<List> baseResp = await DioUtil()
25 .request<List>(context, Method.get, HttpUrl.get_custom_remark, 27 .request<List>(context, Method.get, HttpUrl.get_custom_remark,
26 - data: params, showLoading: false) 28 + data: params, showLoading: showPageLoading?false:true)
27 .catchError((error) { 29 .catchError((error) {
28 print(error.toString()); 30 print(error.toString());
29 if (error is MyError) { 31 if (error is MyError) {
@@ -55,15 +57,14 @@ class RemarkManagerModel extends ChangeNotifier{ @@ -55,15 +57,14 @@ class RemarkManagerModel extends ChangeNotifier{
55 } 57 }
56 58
57 //添加备注 59 //添加备注
58 - addRemark(BuildContext context, Map<String, String> params) async { 60 + Future addRemark(BuildContext context, Map<String, String> params) async {
59 BaseResp<dynamic> baseResp = await DioUtil() 61 BaseResp<dynamic> baseResp = await DioUtil()
60 .request<dynamic>(context, Method.get, HttpUrl.add_custom_remark, 62 .request<dynamic>(context, Method.get, HttpUrl.add_custom_remark,
61 data: params, showLoading: false) 63 data: params, showLoading: false)
62 .catchError((error) { 64 .catchError((error) {
63 print(error.toString()); 65 print(error.toString());
64 }); 66 });
65 - if (baseResp != null && baseResp.code == Constant.status_success) {  
66 - } 67 + return ;
67 } 68 }
68 69
69 //删除备注 70 //删除备注