Selaa lähdekoodia

添加服务 编辑界面

lailin 4 vuotta sitten
vanhempi
commit
ba0b0d35d8

+ 3 - 3
taskservice/lib/Model/JXMemberModel.dart

@@ -24,7 +24,7 @@ class JXMemberModel {
   String remark = '';
 
   /*服务*/
-  List <JXServiceModel> service = [];
+  List <JXServiceModel> services = [];
 
   Map<String, dynamic> toMap() {
     return {
@@ -41,8 +41,8 @@ class JXMemberModel {
 
   /*获取显示tips*/
   String theFirstTipsDes() {
-    if (this.service.length > 0) {
-      JXServiceModel ser = this.service[0];
+    if (this.services.length > 0) {
+      JXServiceModel ser = this.services[0];
       return '${ser.kind} ${ser.remark}';
     } else {
       return '无任务';

+ 11 - 7
taskservice/lib/Model/JXServiceModel.dart

@@ -2,26 +2,30 @@
 服务信息模型
 * */
 class JXServiceModel {
-  String _id;
-  String kind;
+  /*选中状态*/
+  bool isCheck = false;
+
+  /*数据*/
+  int id;
+  String kind = '';
 
   /*提醒周期*/
-  int cycle;
-  String cycleUnit;
+  int cycle = 0;
+  String cycleUnit = '';
 
   /*提醒时间
   -n 提前n天提醒
   n 延后n天提醒
   0 当天提醒,默认一般当天提醒
   * */
-  int remindDay;
+  int remindDay = 0;
 
   /*备注*/
-  String remark;
+  String remark = '';
 
   Map<String, dynamic> toMap() {
     return {
-      '_id': _id,
+      'id': id,
       'kind': kind,
       'cycle': '$cycle',
       'cycleUnit': cycleUnit,

+ 2 - 2
taskservice/lib/main.dart

@@ -22,9 +22,9 @@ class MyApp extends StatelessWidget {
         }else if(name == '$AccountListPage') {
           return CupertinoPageRoute(builder: (context)=> AccountListPage());
         }else if(name == '$CreateServiceList') {
-          return CupertinoPageRoute(builder: (context)=> CreateServiceList());
+          return CupertinoPageRoute(builder: (context)=> CreateServiceList(), settings: settings);
         }else if(name == '$CreateAddService') {
-          return CupertinoPageRoute(builder: (context)=> CreateAddService());
+          return CupertinoPageRoute(builder: (context)=> CreateAddService(), settings: settings);
         }
         return null;
       },

+ 16 - 36
taskservice/lib/src/crtacc/page_crtacc.dart

@@ -14,7 +14,6 @@ class CreateAccPage extends StatefulWidget {
 }
 
 class _CreateAccPageState extends State<CreateAccPage> {
-  List<JXServiceModel> services;
   JXMemberModel member;
   TextEditingController nameController = TextEditingController();
   TextEditingController phoneController = TextEditingController();
@@ -24,38 +23,6 @@ class _CreateAccPageState extends State<CreateAccPage> {
   @override
   void initState() {
     super.initState();
-    services = [
-      JXServiceModel()
-        ..kind = '清洗'
-        ..cycle = 3
-        ..cycleUnit = '个月'
-        ..remark = '备注1',
-      JXServiceModel()
-        ..kind = '清洗2'
-        ..cycle = 1
-        ..cycleUnit = '个月'
-        ..remark = '备注11',
-      JXServiceModel()
-        ..kind = '清洗3'
-        ..cycle = 2
-        ..cycleUnit = '个月'
-        ..remark = '备注1111',
-      JXServiceModel()
-        ..kind = '清洗4'
-        ..cycle = 30
-        ..cycleUnit = '个月'
-        ..remark = '备注111111',
-      JXServiceModel()
-        ..kind = '清洗5'
-        ..cycle = 12
-        ..cycleUnit = '个月'
-        ..remark = '备注111111',
-      JXServiceModel()
-        ..kind = '清洗6'
-        ..cycle = 2
-        ..cycleUnit = '个月'
-        ..remark = '备注111111',
-    ];
 
     member = JXMemberModel();
     nameController.addListener(onInfoChanged);
@@ -93,7 +60,11 @@ class _CreateAccPageState extends State<CreateAccPage> {
                   child: InkWell(
                     onTap: () {
                       /*跳转到服务*/
-                      Navigator.of(context).pushNamed('$CreateServiceList');
+                      Navigator.of(context).pushNamed('$CreateServiceList',
+                          arguments: {'services': member.services}).then((value) {
+                            print(value.toString());
+                            onClickAddServer(value);
+                      });
                     },
                     child: Container(
                       padding: EdgeInsets.all(8),
@@ -117,8 +88,8 @@ class _CreateAccPageState extends State<CreateAccPage> {
   SliverList buildItemsPart() {
     return SliverList(
       delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
-        if (index <= services.length - 1) {
-          var service = services[index];
+        if (index <= member.services.length - 1) {
+          var service = member.services[index];
           return Container(
             padding: EdgeInsets.symmetric(horizontal: 16),
             child: Column(
@@ -312,8 +283,17 @@ class _CreateAccPageState extends State<CreateAccPage> {
     );
   }
 
+  /*保存*/
   Future<void> onClickSave() async {
     (await MyDataBase.database).saveMember(member);
     Navigator.of(context).pop();
   }
+
+  /*界面返回后添加服务*/
+  void onClickAddServer(List <JXServiceModel> services) {
+    print('添加多个服务');
+    member.services.clear();
+    member.services.addAll(services);
+    setState(() {});
+  }
 }

+ 2 - 2
taskservice/lib/src/custom_widgets.dart

@@ -105,7 +105,7 @@ class _SearchBarState extends State<SearchBar> {
 class EditCell extends StatefulWidget {
   final String mark;
   final String hint;
-  final Function(String value) onEditingComplete;
+  final Function onEditingComplete;
   final TextEditingController controller;
   EditCell({this.mark, this.hint, this.controller, this.onEditingComplete});
   @override
@@ -142,7 +142,7 @@ class _EditCell extends State<EditCell> {
                     fontSize: 16.0,
                   ),
                 ),
-                onEditingComplete: widget.onEditingComplete(widget.controller.text),
+                onEditingComplete: widget.onEditingComplete,
               ),
             )),
       ],

+ 18 - 20
taskservice/lib/src/service/page_addservice.dart

@@ -19,13 +19,13 @@ class _CreateAddService extends State<CreateAddService> {
   /*服务*/
   JXServiceModel _service;
   /*类型*/
-  TextEditingController kindController;
+  TextEditingController _kindController = TextEditingController(text: '');
   /*周期*/
-  TextEditingController cycleController;
+  final TextEditingController _cycleController = TextEditingController(text: '');
   /*提醒*/
-  TextEditingController remandController;
+  final TextEditingController _remandController = TextEditingController(text: '0');
   /*备注*/
-  TextEditingController remarkConotroller;
+  final TextEditingController _remarkConotroller = TextEditingController(text: '');
 
   @override
   void initState() {
@@ -38,10 +38,10 @@ class _CreateAddService extends State<CreateAddService> {
       print('编辑服务');
       _service = widget.service;
       /*设置值*/
-      kindController = TextEditingController(text: _service.kind);
-      cycleController = TextEditingController(text: _service.cycle.toString());
-      remandController = TextEditingController(text: '0');
-      remarkConotroller = TextEditingController(text: _service.remark);
+      /*_kindController = TextEditingController(text: _service.kind);
+      _cycleController = TextEditingController(text: _service.cycle.toString());
+      _remandController = TextEditingController(text: _service.remindDay.toString());
+      _remarkConotroller = TextEditingController(text: _service.remark);*/
     }
   }
 
@@ -62,10 +62,7 @@ class _CreateAddService extends State<CreateAddService> {
                     child: EditCell(
                       mark: '类型',
                       hint: '请输入类型',
-                      controller: kindController,
-                      onEditingComplete: (value){
-                        _service.kind = value;
-                      },
+                      controller: _kindController,
                     ),
                   ),
                   Container(
@@ -77,13 +74,13 @@ class _CreateAddService extends State<CreateAddService> {
                         Expanded(
                           child: SizedBox(width: 0,),
                         ),
-                        theInputDayView('周期', '个月', cycleController),
-                        theInputDayView('提醒', '日', remandController),
+                        theInputDayView('周期', '个月', _cycleController),
+                        theInputDayView('提醒', '日', _remandController),
                       ],
                     ),
                   ),
                   SizedBox(height: 12.0,),
-                  theRemarkView(remarkConotroller),
+                  theRemarkView(_remarkConotroller),
                 ],
               ),
             ),
@@ -199,15 +196,16 @@ class _CreateAddService extends State<CreateAddService> {
     );
   }
 
-
   /**点击事件**/
   /*保存*/
   void saveBtnClickAction() {
-    _service.kind = kindController.text;
-    _service.cycle = int.parse(cycleController.text);
-    _service.remindDay = int.parse(remandController.text);
-    _service.remark = remarkConotroller.text;
+    _service.kind = _kindController.text;
+    _service.cycle = int.parse(_cycleController.text);
+    _service.remindDay = int.parse(_remandController.text);
+    _service.remark = _remarkConotroller.text;
     _service.cycleUnit = '月';
+    _service.id = 12;
     print(_service.toMap());
+    Navigator.of(context).pop(_service);
   }
 }

+ 70 - 26
taskservice/lib/src/service/page_servicelist.dart

@@ -25,26 +25,31 @@ class _CreateServiceList extends State<CreateServiceList> {
     super.initState();
     _baseServices = [
       JXServiceModel()
-      ..kind = '清洗'
-      ..cycle = 2
-      ..cycleUnit = '月'
-      ..remark = '带清洁工具',
+        ..id = 1
+        ..kind = '清洗'
+        ..cycle = 2
+        ..cycleUnit = '月'
+        ..remark = '带清洁工具',
       JXServiceModel()
+        ..id = 2
         ..kind = '除胶'
         ..cycle = 1
         ..cycleUnit = '月'
         ..remark = '带清洁工具',
       JXServiceModel()
+        ..id = 3
         ..kind = '换水'
         ..cycle = 1
         ..cycleUnit = '月'
         ..remark = '带清洁工具',
       JXServiceModel()
+        ..id = 4
         ..kind = '换滤芯'
         ..cycle = 4
         ..cycleUnit = '月'
         ..remark = '带清洁工具',
       JXServiceModel()
+        ..id = 5
         ..kind = '换电机'
         ..cycle = 5
         ..cycleUnit = '月'
@@ -55,6 +60,18 @@ class _CreateServiceList extends State<CreateServiceList> {
   @override
   Widget build(BuildContext context) {
     // TODO: implement build
+    /*标记选中服务*/
+    dynamic obj = ModalRoute.of(context).settings.arguments;
+    if (obj != null && obj['services'] != null) {
+      List items = obj['services'];
+      for (JXServiceModel service in items) {
+        for (JXServiceModel base in _baseServices) {
+          if (service.id == base.id) {
+            base.isCheck = true;
+          }
+        }
+      }
+    }
     return MyScaffold(
       title: '服务列表',
       actions: <Widget>[
@@ -123,32 +140,47 @@ class _CreateServiceList extends State<CreateServiceList> {
   Widget theCellBuilder(JXServiceModel service) {
     return GestureDetector(
       onTap: (){
-        print('click cell, name:${service.kind}');
+        service.isCheck = !service.isCheck;
+        setState(() {});
       },
       child: Container(
         padding: EdgeInsets.symmetric(horizontal: 16),
         color: JXColors.kFFFFFF,
         alignment: Alignment.topCenter,
-        child: Column(
+        child: Row(
           children: <Widget>[
-            SizedBox(height: 12,),
-            Row(
-              mainAxisAlignment: MainAxisAlignment.spaceBetween,
-              children: <Widget>[
-                Text('类型: ${service.kind}'),
-                Text('周期: ${service.cycle}${service.cycleUnit}'),
-              ],
-            ),
-            SizedBox(height: 12,),
-            Row(
-              children: <Widget>[
-                Text('备注 ${service.remark}'),
-              ],
+            Container(
+              width: 44.0,
+              alignment: Alignment.center,
+              child: Icon(
+                  service.isCheck?Icons.radio_button_checked:Icons.radio_button_unchecked
+              ),
             ),
-            SizedBox(height: 12,),
-            Divider(
-              height: 2,
-              thickness: 2,
+            SizedBox(width: 12.0,),
+            Expanded(
+              child: Column(
+                children: <Widget>[
+                  SizedBox(height: 12,),
+                  Row(
+                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                    children: <Widget>[
+                      Text('类型: ${service.kind}'),
+                      Text('周期: ${service.cycle}${service.cycleUnit}'),
+                    ],
+                  ),
+                  SizedBox(height: 12,),
+                  Row(
+                    children: <Widget>[
+                      Text('备注 ${service.remark}'),
+                    ],
+                  ),
+                  SizedBox(height: 12,),
+                  Divider(
+                    height: 2,
+                    thickness: 2,
+                  ),
+                ],
+              ),
             ),
           ],
         ),
@@ -179,12 +211,24 @@ class _CreateServiceList extends State<CreateServiceList> {
 
   /*保存*/
   void saveBtnClickAction() {
-    print('保存');
+    /*筛选选中服务*/
+    List <JXServiceModel> tmpItems = [];
+    for (JXServiceModel service in _baseServices) {
+      if (service.isCheck) {
+        tmpItems.add(service);
+      }
+    }
+    Navigator.of(context).pop(tmpItems);
   }
 
   /*添加信息的服务*/
   void addBtnClickAction() {
-    print('添加服务');
-    Navigator.of(this.context).pushNamed('$CreateAddService');
+    Navigator.of(context).pushNamed('$CreateAddService', arguments: '').then((data) {
+      if (data != null) {
+        setState(() {
+          _baseServices.add(data);
+        });
+      }
+    });
   }
 }