feast_model.dart 1.89 KB
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:provider/provider.dart';

import '../constant/constant.dart';
import '../constant/error.dart';
import '../models/filter_btn_model.dart';
import '../models/get_seller_user_by_sellerid_model.dart';
import '../net/base_resp.dart';
import '../net/dio_util.dart';
import '../net/http_url.dart';
import '../utils/utils.dart';

class FeastModel extends ChangeNotifier {
  PageState pageState = PageState.Success;

  List<FilterBtnModel> sellerManageList = []; //经理数据 ---- 商家编辑页面

  ///商家详情编辑页面 ------  获取经理数据
  Future<List<FilterBtnModel>> getSellerUserBySellerid(BuildContext context,
      {isShowLoading = true}) async {
    Map<String, String> params = {
      'sellerid': Provider.of<UserModel>(context, listen: false).user.sellerid
    };
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(
            context, Method.get, HttpUrl.get_seller_user_by_sellerid,
            data: params, showLoading: false)
        .catchError((error) {
      print(error.toString());
      if (error is MyError) {}
    });
    if (baseResp.code == Constant.status_success) {
      List<GetSellerUserBySelleridSunModel> sunmodel =
          GetSellerUserBySelleridModel.fromJson(baseResp.responseData).data;
      sellerManageList = [];
      if (sunmodel != null && sunmodel.length > 0) {
        for (GetSellerUserBySelleridSunModel item in sunmodel) {
          if (item.nickName != null) {
            FilterBtnModel model = FilterBtnModel();
            model.id = item.id;
            model.title = item.nickName;
            sellerManageList.add(model);
          }
        }
      }
    } else {
      if (baseResp != null) {
        Utils.showToast(baseResp.msg ?? "");
      }
    }
    return sellerManageList;
  }
}