diff --git a/lib/business_system/goods/add_goods/add_goods_page.dart b/lib/business_system/goods/add_goods/add_goods_page.dart index 27932ed1..1e10fd94 100644 --- a/lib/business_system/goods/add_goods/add_goods_page.dart +++ b/lib/business_system/goods/add_goods/add_goods_page.dart @@ -52,6 +52,7 @@ class _AddGoodsPage extends State { bool isAttrStyle = false; bool isKeyBoardShow = false; FocusNode _focusNode = FocusNode(); + List mealDetails = []; @override void initState() { @@ -365,7 +366,13 @@ class _AddGoodsPage extends State { behavior: HitTestBehavior.opaque, onTap:(){ Navigator.of(context).pushNamed( - '/router/set_meal',arguments:{"storeId":widget.arguments["storeId"]}); + '/router/set_meal',arguments:{"storeId":widget.arguments["storeId"],"mealDetails":mealDetails}).then((value){ + if (value != null){ + mealDetails.clear(); + mealDetails.addAll(value); + setState((){}); + } + }); }, child: Padding(padding: EdgeInsets.symmetric(horizontal: 16.w,vertical:16.h), child: Column( diff --git a/lib/business_system/goods/add_goods/set_goods_specs.dart b/lib/business_system/goods/add_goods/set_goods_specs.dart index 7c7611d4..02de55c6 100644 --- a/lib/business_system/goods/add_goods/set_goods_specs.dart +++ b/lib/business_system/goods/add_goods/set_goods_specs.dart @@ -254,7 +254,36 @@ class _SetGoodsSpecs extends State { alignment: Alignment.bottomCenter, child: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () {}, + onTap: () { + bool flag = false; + String tipText = ""; + specs.forEach((element) { + if (element.specsNameController.text + .trim() == + "") { + flag = true; + tipText = "规格名称未输入,请先输入规格名称"; + return; + } else if (element + .specsValues.length == + 0) { + flag = true; + tipText = "未添加规格值,请先添加规格值"; + return; + } + }); + if (flag) { + SmartDialog.show( + clickBgDismissTemp: false, + widget: SettlementTips( + () {}, + text: tipText, + color: Color(0xFF30415B), + )); + } else { + // Navigator.of(context).pop(); + } + }, child: Container( color: Colors.white, width: double.infinity, diff --git a/lib/business_system/goods/add_goods/set_meal.dart b/lib/business_system/goods/add_goods/set_meal.dart index 4aa5b01d..afde17c5 100644 --- a/lib/business_system/goods/add_goods/set_meal.dart +++ b/lib/business_system/goods/add_goods/set_meal.dart @@ -1,9 +1,14 @@ import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import '../../../generated/l10n.dart'; import '../../../retrofit/business_api.dart'; import '../../../retrofit/data/set_specs_meal_list.dart'; import '../../../utils/font_weight.dart'; +import '../../../view_widget/border_text.dart'; +import '../../../view_widget/round_button.dart'; +import '../../../view_widget/settlement_tips_dialog.dart'; class SetMeal extends StatefulWidget { final Map arguments; @@ -39,6 +44,15 @@ class _SetMeal extends State { } }); }); + List mealDetails = widget?.arguments["mealDetails"] ??[]; + mealDetails.forEach((element) { + var tempValue = SetSpecsMealList(); + tempValue.groupsNameController.text = element["groupsName"]; + tempValue.groupsTotal = element["groupsTotal"]; + tempValue.optionalNum = element["optionalNum"]; + tempValue.goodsMeal = element["goodsDetail"]; + specsMeal.add(tempValue); + }); } ///离开页面记着销毁和清除 @@ -65,6 +79,56 @@ class _SetMeal extends State { brightness: Brightness.dark, action: GestureDetector( onTap: () { + bool flag = false; + String tipText = ""; + int index = 0; + List mealDetail = []; + if (specsMeal.length != 0) { + specsMeal.forEach((element) { + index += 1; + if (element.groupsNameController.text.trim() == "") { + flag = true; + tipText = "分组$index未填写分组名"; + return; + } else if (element.goodsMeal.length == 0 || + element.goodsMeal.length != element.groupsTotal) { + flag = true; + tipText = + "分组${element.groupsNameController.text}已选商品数量与设定分组总数不符,请修改"; + return; + } else if (element.optionalNum > element.groupsTotal) { + flag = true; + tipText = + "分组${element.groupsNameController.text}可选数量不可大于分组总数"; + return; + } + mealDetail.add({ + "groupsName":element.groupsNameController.text, + "groupsTotal":element.groupsTotal, + "optionalNum":element.optionalNum, + "goodsDetail":element.goodsMeal + }); + }); + if (flag) { + SmartDialog.show( + clickBgDismissTemp: false, + widget: SettlementTips( + () {}, + text: tipText, + color: Color(0xFF30415B), + )); + } else { + Navigator.of(context).pop(mealDetail); + } + } else { + SmartDialog.show( + clickBgDismissTemp: false, + widget: SettlementTips( + () {}, + text: "请添加设置分组后再点击确实按钮", + color: Color(0xFF30415B), + )); + } }, child: Text( "确定", @@ -95,9 +159,9 @@ class _SetMeal extends State { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - setState(() {}); + FocusScope.of(context).unfocus(); }, - child: specsValueText(position)); + child: mealText(position)); }, ), GestureDetector( @@ -141,8 +205,8 @@ class _SetMeal extends State { )); } - ///添加规格样式 - Widget specsValueText(index) { + ///添加套餐分组样式 + Widget mealText(index) { return Column( children: [ Container( @@ -158,7 +222,7 @@ class _SetMeal extends State { children: [ Expanded( child: Text( - "分组1", + "分组${index + 1}", style: TextStyle( color: Color(0xD9000000), fontSize: 14.sp, @@ -364,9 +428,7 @@ class _SetMeal extends State { Spacer(), GestureDetector( onTap: () { - setState(() { - specsMeal.removeAt(index); - }); + deleteGroupsDialog(index); }, child: Row( mainAxisAlignment: MainAxisAlignment.end, @@ -412,7 +474,7 @@ class _SetMeal extends State { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () {}, - child: specsInfoItem(index, position), + child: addGoodsItem(index, position), ); }, ) @@ -420,8 +482,85 @@ class _SetMeal extends State { ); } - ///规格信息样式 - Widget specsInfoItem(specsIndex, index) { + ///删除分组弹窗提示 + deleteGroupsDialog(index) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + content: Container( + width: MediaQuery.of(context).size.width - 84, + height: 139.h, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "此操作将直接删除当前分组, 是否继续?", + style: TextStyle( + color: Color(0xFFF4524D), + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + ), + ), + SizedBox( + height: 35.h, + ), + Row( + children: [ + Expanded( + child: InkWell( + child: BorderText( + text: S.of(context).quxiao, + textColor: Color(0xFF30415B), + fontSize: 16.sp, + fontWeight: FontWeight.bold, + borderColor: Color(0xFF30415B), + radius: 4, + padding: EdgeInsets.all(12), + borderWidth: 1, + ), + onTap: () { + Navigator.of(context).pop(); + }, + ), + flex: 1, + ), + SizedBox( + width: 16.w, + ), + Expanded( + child: InkWell( + child: RoundButton( + text: S.of(context).queren, + textColor: Colors.white, + radius: 4, + padding: EdgeInsets.all(12), + backgroup: Color(0xFF30415B), + fontSize: 16.sp, + fontWeight: FontWeight.bold, + ), + onTap: () { + setState((){ + Navigator.of(context).pop(); + specsMeal.removeAt(index); + }); + }, + ), + flex: 1, + ), + ], + ) + ], + ), + ), + ); + }, + ); + } + + ///增加商品Item + Widget addGoodsItem(specsIndex, index) { return Container( color: Colors.white, margin: EdgeInsets.symmetric(vertical: 12.h), @@ -460,7 +599,7 @@ class _SetMeal extends State { ), Expanded( child: Text( - specsMeal[specsIndex]?.goodsMeal[index]["goodsNum"] ?? "", + specsMeal[specsIndex]?.goodsMeal[index]["goodsNum"] ?? "", textAlign: TextAlign.center, style: TextStyle( color: Color(0xFF000000), diff --git a/lib/retrofit/data/set_specs_meal_list.dart b/lib/retrofit/data/set_specs_meal_list.dart index d025bbe3..d86cabc3 100644 --- a/lib/retrofit/data/set_specs_meal_list.dart +++ b/lib/retrofit/data/set_specs_meal_list.dart @@ -15,7 +15,6 @@ class SetSpecsMealList { _goodsMeal = value; } - num get groupsTotal => _groupsTotal; set groupsTotal(num value) {