base_info_provider.dart 3.95 KB
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/models/base_info_model.dart';
import 'package:one_key/models/seller_phone_model.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';

class BaseIndoProvider with ChangeNotifier {
  BaseInfoSunModel baseInfoSunModel; //客户经理基础信息
  List<SellerPhoneSunModel> photoList = []; //商家图片信息

  ///客户经理添加/修改基本信息
  Future<dynamic> setCustomerActivityBaseinfo(
      BuildContext context, Map<String, String> params,
      {isShowLoading = true}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(
            context, Method.get, HttpUrl.set_customer_activity_baseinfo,
            data: params, showLoading: isShowLoading)
        .catchError((error) {
      print(error.toString());
      if (error is MyError) {}
      return false;
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data != null) {
        // coupons = baseResp.data['aid'].split('');
        return true;
      } else {
        // Utils.showToast(baseResp.msg ?? "修改失败");
        return false;
      }
    } else {
      if (baseResp != null) {
        // Utils.showToast(baseResp.msg ?? "");
      }
      return false;
    }
  }

  ///客户经理获取基本信息
  Future<bool> getCustomerActivityBaseinfo(
      BuildContext context, Map<String, String> params,
      {isShowLoading = true}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(
            context, Method.get, HttpUrl.get_customer_activity_baseinfo,
            data: params, showLoading: isShowLoading)
        .catchError((error) {
      print(error.toString());
      Map<String, String> params = {
        'sellerid':
            Provider.of<UserModel>(context, listen: false).user.sellerid,
        "uid": Provider.of<UserModel>(context, listen: false).user.openid,
      };
      getCustomerActivityBaseinfo(context, params, isShowLoading: false);
      if (error is MyError) {}
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data == null || baseResp.data == false) {
        return false;
      } else {
        baseInfoSunModel = BaseInfoModel.fromJson(baseResp.responseData).data;
        // for (int i = 0; i < couponListSelect.length; i++) {
        //   coupons.add(couponListSelect[i].id);
        //   // couponsShow.add(couponTemp[i].id);
        // }
        // hasModify = true;
        notifyListeners();

        return true;
      }
    } else {
      if (baseResp != null) {
        Utils.showToast(baseResp.msg ?? "");
      }
      return false;
    }
  }

  ///根据商家ID获取对应类型图片
  Future<bool> getSellerPhotoById(
      BuildContext context, Map<String, String> params,
      {isShowLoading = true}) async {
    BaseResp<dynamic> baseResp = await DioUtil()
        .request<dynamic>(context, Method.get, HttpUrl.get_seller_photo_by_id,
            data: params, showLoading: isShowLoading)
        .catchError((error) {
      print(error.toString());
      if (error is MyError) {}
    });
    if (baseResp.code == Constant.status_success) {
      if (baseResp.data == null || baseResp.data == false) {
        return false;
      } else {
        photoList = SellerPhoneModel.fromJson(baseResp.responseData).data;
        // for (int i = 0; i < couponListSelect.length; i++) {
        //   coupons.add(couponListSelect[i].id);
        //   // couponsShow.add(couponTemp[i].id);
        // }
        // hasModify = true;
        notifyListeners();
        return true;
      }
    } else {
      if (baseResp != null) {
        Utils.showToast(baseResp.msg ?? "");
      }
      return false;
    }
  }
}