import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/user/pick_building_model.dart'; import 'package:akuCommunity/model/user/user_info_model.dart'; import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:dio/dio.dart'; import 'package:get/get.dart' hide Response; import 'package:provider/provider.dart'; class SignFunc { static Future sendMessageCode(String phone) async { BaseModel baseModel = await NetUtil().post( API.login.sendSMSCode, params: {'tel': phone}, showMessage: true, ); return baseModel; } static Future login(String phone, String code) async { Response response = await NetUtil().dio.post( API.login.loginBySMS, data: {'tel': phone, 'code': code}, ); return response; } static Future> getBuildingInfo() async { BaseModel model = await NetUtil().get(API.login.buildingInfo); return (model.data as List) .map((e) => PickBuildingModel.fromJson(e)) .toList(); } static Future> getUnitInfo(int id) async { BaseModel model = await NetUtil().get( API.login.unitInfo, params: {"buildingId": id}, ); return (model.data as List) .map((e) => PickBuildingModel.fromJson(e)) .toList(); } ///注册 static Future signUp() async { final signUpProvider = Provider.of(Get.context, listen: false); final userProvider = Provider.of(Get.context, listen: false); Response response = await NetUtil().dio.post( API.login.signUp, data: signUpProvider.toMap, ); BotToast.showText(text: response.data['message']); if (response.data['status']) { userProvider.setLogin(response.data['token']); return true; } else return false; } static Future getUserInfo() async { BaseModel baseModel = await NetUtil().get(API.user.userProfile); return UserInfoModel.fromJson(baseModel.data); } }