Commit 3f14062887c9b177c51f84d5a4c54ef9f66b8889

Authored by wdn127929
1 parent f764b6ce

菜品向上向下移动

@@ -203,7 +203,28 @@ class MenuSunModel { @@ -203,7 +203,28 @@ class MenuSunModel {
203 } 203 }
204 204
205 //图片移动数组 205 //图片移动数组
206 - List<RadioModel> get moveList { 206 + List<RadioModel> moveList(int length) {
  207 + if (length == 1) {
  208 + return [];
  209 + }
  210 + if (indexNew == 0) {
  211 + //没有向上移动选项
  212 +
  213 + RadioModel radioModel2 = RadioModel();
  214 + radioModel2.title = '菜品向下移动一个';
  215 + radioModel2.code = '2';
  216 + radioModel2.select = false;
  217 +
  218 + return [radioModel2];
  219 + } else if (indexNew == length - 1) {
  220 + //最后一个没有向下移动选项
  221 + RadioModel radioModel1 = RadioModel();
  222 + radioModel1.title = '菜品向上移动一个';
  223 + radioModel1.code = '1';
  224 + radioModel1.select = false;
  225 +
  226 + return [radioModel1];
  227 + }
207 RadioModel radioModel1 = RadioModel(); 228 RadioModel radioModel1 = RadioModel();
208 radioModel1.title = '菜品向上移动一个'; 229 radioModel1.title = '菜品向上移动一个';
209 radioModel1.code = '1'; 230 radioModel1.code = '1';
@@ -608,7 +629,7 @@ class MenuSunModel { @@ -608,7 +629,7 @@ class MenuSunModel {
608 amounttemp += v.amount; 629 amounttemp += v.amount;
609 amountHasOrderList.add(v); 630 amountHasOrderList.add(v);
610 } 631 }
611 - amount = amounttemp * (json['out_all_num']??1); 632 + amount = amounttemp * (json['out_all_num'] ?? 1);
612 }); 633 });
613 // } 634 // }
614 635
@@ -441,4 +441,9 @@ class HttpUrl { @@ -441,4 +441,9 @@ class HttpUrl {
441 static const String get_pay_message_by_id = 441 static const String get_pay_message_by_id =
442 "?service=App.Activity.GetPayMessageByID"; // 充值成功通知消息获取详情 442 "?service=App.Activity.GetPayMessageByID"; // 充值成功通知消息获取详情
443 443
  444 +
  445 + static const String set_cook_book_order =
  446 + "?service=App.Cookbook.SetCookbookOrder"; // App设置菜品移动
  447 +
  448 +
444 } 449 }
@@ -173,6 +173,23 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -173,6 +173,23 @@ class _MenuManagePageState extends State<MenuManagePage> {
173 } 173 }
174 } 174 }
175 175
  176 + /// App设置菜品移动
  177 + _setCookbookOrder(String id, String upid) async {
  178 + Map<String, String> params = {
  179 + // "sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
  180 + "id": id,
  181 + 'upid': upid
  182 + };
  183 + print(params);
  184 + bool sucess = await menuManageProvider.setCookbookOrder(context, params,
  185 + showLoading: true);
  186 + if (sucess) {
  187 + Utils.showToast('修改成功!');
  188 + //刷新列表数据
  189 + _getCookbookByClass(showLoading: true);
  190 + }
  191 + }
  192 +
176 ///处理数据 193 ///处理数据
177 _handleData({isMove = false}) { 194 _handleData({isMove = false}) {
178 if (menuManageProvider.menuModel != null) { 195 if (menuManageProvider.menuModel != null) {
@@ -699,8 +716,13 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -699,8 +716,13 @@ class _MenuManagePageState extends State<MenuManagePage> {
699 } 716 }
700 717
701 _onLongPress(MenuSunModel model, int indexOut) async { 718 _onLongPress(MenuSunModel model, int indexOut) async {
  719 + List<MenuSunModel> cookbooklist =
  720 + menuManageProvider.menuModel[indexOut].cookbooklist;
702 Map object = await DialogUtil.menuMagageAlertDialog( 721 Map object = await DialogUtil.menuMagageAlertDialog(
703 - context, model.nameTypeList, model.imageTypeList, model.moveList); 722 + context,
  723 + model.nameTypeList,
  724 + model.imageTypeList,
  725 + model.moveList(cookbooklist.length));
704 if (object != null) { 726 if (object != null) {
705 print(object); 727 print(object);
706 if (object['name_type'] != null) { 728 if (object['name_type'] != null) {
@@ -720,25 +742,37 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -720,25 +742,37 @@ class _MenuManagePageState extends State<MenuManagePage> {
720 if (object['move'] == '1' && model.indexNew != 0) { 742 if (object['move'] == '1' && model.indexNew != 0) {
721 //向上移动 743 //向上移动
722 744
723 - var child = menuManageProvider.menuModel[indexOut].cookbooklist  
724 - .removeAt(model.indexNew); 745 + // 当前菜品id
  746 + // model.id
  747 + //上一个id
  748 + // cookbooklist[model.indexNew-1].id
  749 + _setCookbookOrder(model.id, cookbooklist[model.indexNew - 1].id);
725 750
726 - menuManageProvider.menuModel[indexOut].cookbooklist  
727 - .insert(model.indexNew - 1, child); 751 + // var child = menuManageProvider.menuModel[indexOut].cookbooklist
  752 + // .removeAt(model.indexNew);
728 753
729 - _handleData(isMove: true); 754 + // menuManageProvider.menuModel[indexOut].cookbooklist
  755 + // .insert(model.indexNew - 1, child);
  756 +
  757 + // _handleData(isMove: true);
730 } else if (object['move'] == '2' && 758 } else if (object['move'] == '2' &&
731 model.indexNew != 759 model.indexNew !=
732 menuManageProvider.menuModel[indexOut].cookbooklist.length - 760 menuManageProvider.menuModel[indexOut].cookbooklist.length -
733 1) { 761 1) {
734 //向下移动 762 //向下移动
735 - var child = menuManageProvider.menuModel[indexOut].cookbooklist  
736 - .removeAt(model.indexNew); 763 + // 当前菜品id
  764 + // model.id
  765 + //下一个id
  766 + // cookbooklist[model.indexNew+1].id
  767 +
  768 + _setCookbookOrder(model.id, cookbooklist[model.indexNew + 1].id);
  769 + // var child = menuManageProvider.menuModel[indexOut].cookbooklist
  770 + // .removeAt(model.indexNew);
737 771
738 - menuManageProvider.menuModel[indexOut].cookbooklist  
739 - .insert(model.indexNew + 1, child); 772 + // menuManageProvider.menuModel[indexOut].cookbooklist
  773 + // .insert(model.indexNew + 1, child);
740 774
741 - _handleData(isMove: true); 775 + // _handleData(isMove: true);
742 } 776 }
743 } else { 777 } else {
744 _handleData(); 778 _handleData();
@@ -361,6 +361,28 @@ class MenuManageProvider extends ChangeNotifier { @@ -361,6 +361,28 @@ class MenuManageProvider extends ChangeNotifier {
361 return false; 361 return false;
362 } 362 }
363 363
  364 + /// App设置菜品移动
  365 + Future<bool> setCookbookOrder(
  366 + BuildContext context, Map<String, String> params,
  367 + {showLoading = false}) async {
  368 + BaseResp<dynamic> baseResp = await DioUtil()
  369 + .request<dynamic>(context, Method.get, HttpUrl.set_cook_book_order,
  370 + data: params, showLoading: showLoading)
  371 + .catchError((error) {
  372 + print(error.toString());
  373 + Utils.showToast('移动失败,请重试!');
  374 + });
  375 +
  376 + if (baseResp != null && baseResp.code == Constant.status_success) {
  377 + if (baseResp.data == true) {
  378 + return true;
  379 + }
  380 + } else {
  381 + Utils.showToast(baseResp.msg ?? "");
  382 + }
  383 + return false;
  384 + }
  385 +
364 ///修改菜品 386 ///修改菜品
365 Future<bool> setCookbookById(BuildContext context, Map<String, String> params, 387 Future<bool> setCookbookById(BuildContext context, Map<String, String> params,
366 {showLoading = false}) async { 388 {showLoading = false}) async {
@@ -374,9 +374,10 @@ class DialogUtil { @@ -374,9 +374,10 @@ class DialogUtil {
374 // fontSize: ScreenUtil().setSp(fontSize), 374 // fontSize: ScreenUtil().setSp(fontSize),
375 // color: MyColours.color_515151)), 375 // color: MyColours.color_515151)),
376 // ), 376 // ),
377 - MyDivider(  
378 - ScreenUtil().setWidth(280 * 2), ScreenUtil().setWidth(2),  
379 - color: MyColours.color_efefef), 377 + if (moveList.length > 0)
  378 + MyDivider(ScreenUtil().setWidth(280 * 2),
  379 + ScreenUtil().setWidth(2),
  380 + color: MyColours.color_efefef),
380 ListView.builder( 381 ListView.builder(
381 itemCount: moveList.length, 382 itemCount: moveList.length,
382 shrinkWrap: true, 383 shrinkWrap: true,