base_info_provider.dart 2.39 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/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/utils/utils.dart';

class BaseIndoProvider with ChangeNotifier {
  BaseInfoSunModel baseInfoSunModel; //客户经理基础信息

  ///客户经理添加/修改基本信息
  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());
      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;

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