plan_dish_provider.dart 2.17 KB
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/utils/utils.dart';

import '../constant/constant.dart';
import '../constant/error.dart';
import '../models/cookbook_model.dart';
import '../net/http_url.dart';

/**
 * 预排菜
 */
class PlanDishProvider extends ChangeNotifier {
  PageState pageState = PageState.Success;
  PageState pageStateStore = PageState.Success;
  PageState pageStateMine = PageState.Success;
  PageState pageStateMy = PageState.Success;

  List<MenuModel> menuModel; //菜品数据
  // List<CookbookCategorySunModel> categorySunModel; //菜品分类数据
  // List<CookbookSpecSunModel> specSunModel; //计价单位

  // CookbookOneSunModel cookbookOneSunModel;

  ///分类下所有菜品列表(1.传orderid顾客端获取带订单信息的 否则不传

  getCookbookByClass(BuildContext context, Map<String, String> params,
      {showLoading = false}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(context, Method.get, HttpUrl.get_cookbook_by_class,
            data: params, showLoading: showLoading)
        .catchError((error) {
      print(error.toString());
      if (error is MyError) {
        switch (error.type) {
          case 1:
            pageState = PageState.ConnectivityError;
            break;
          case 2:
            pageState = PageState.ConnectivityTimeOut;
            break;
          default:
            pageState = PageState.ConnectivityError;
            break;
        }
      }
      notifyListeners();
    });
    menuModel = [];

    if (baseResp != null && baseResp.code == Constant.status_success) {
      if (baseResp.data[0]['list'] == '') {
        pageState = PageState.Empty;
      } else {
        List menu = baseResp.data[0]['list'];
        for (int i = 0; i < menu.length; i++) {
          menuModel.add(MenuModel.fromJson(menu[i]));
        }
        print(menuModel);
        pageState = PageState.Success;
      }
    } else {
      Utils.showToast(baseResp.msg ?? "");
      pageState = PageState.ConnectivityError;
    }
    notifyListeners();
  }
}