import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/constants/sars_api.dart'; import 'package:aku_new_community/model/user/pick_building_model.dart'; import 'package:aku_new_community/models/user/my_house_model.dart'; import 'package:aku_new_community/models/user/user_info_model.dart'; import 'package:aku_new_community/pages/sign/login/set_nick_name_page.dart'; import 'package:aku_new_community/pages/sign/login/set_psd_page.dart'; import 'package:aku_new_community/provider/sign_up_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/widget/others/user_tool.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'; import '../tab_navigator.dart'; class SignFunc { //发送手机号验证码 static Future sendMessageCode( String phone, int communityId) async { BaseModel baseModel = await NetUtil().post( SARSAPI.login.sendSMSCode, params: {'tel': phone, 'communityId': communityId}, showMessage: true, ); return baseModel; } //发送手机号验证码 static Future sendForgotMessageCode( String phone, int communityId) async { BaseModel baseModel = await NetUtil().post( SARSAPI.user.sendForgotTelCode, params: {'tel': phone, 'communityId': communityId}, showMessage: true, ); return baseModel; } static Future sendNewMessageCode(String newTel) async { BaseModel baseModel = await NetUtil().post( API.login.sendNewMSCode, params: {'newTel': newTel}, showMessage: true, ); return baseModel; } //登录 static Future login( String phone, String code, int communityId) async { Response response = await NetUtil().dio!.post( API.login.login, data: { 'tel': phone, 'password': code, 'communityId': communityId, }, ); return response; } //验证码登录 static Future loginBySms( String phone, String code, int communityId) async { Response response = await NetUtil().dio!.post( SARSAPI.login.loginTelCode, data: { 'tel': phone, 'code': code, 'communityId': communityId, }, ); 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> getRoom(int? id) async { BaseModel model = await NetUtil().get( API.login.room, params: {"unitId": 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(SARSAPI.user.userProfile); if (baseModel.data == null || !baseModel.success) return null; return UserInfoModel.fromJson(baseModel.data); } ///设置密码(密码不存在时调用 static Future settingPsd(String psd) async { BaseModel baseModel = await NetUtil().get(SARSAPI.user.settingPsd, params: {'password': psd}, showMessage: true); if (baseModel.data == null || !baseModel.success) return false; return true; } ///提交修改的新密码(忘记密码) static Future settingForgotPsd( String psd, String tel, String telcode) async { BaseModel baseModel = await NetUtil().get(SARSAPI.user.settingForgotPsd, params: { 'newPassword': psd, 'tel': tel, 'telCode': telcode, 'communityId': UserTool.appProveider.pickedCityAndCommunity!.communityModel!.id }, showMessage: true); if (baseModel.data == null || !baseModel.success) return false; return true; } static Future> getMyHouseInfo() async { BaseModel baseModel = await NetUtil().get( SARSAPI.profile.house.userHouse, ); if ((baseModel.data as List).isEmpty) return []; return (baseModel.data as List) .map((e) => MyHouseModel.fromJson(e)) .toList(); } static Future checkNameAndAccount() async { if (!UserTool.userProvider.userInfoModel!.isExistPassword) { await Get.to(() => SetPsdPage()); } else if (UserTool.userProvider.userInfoModel!.nickName == null) { await Get.to(() => SetNickNamePage()); } else { Get.offAll(() => TabNavigator()); } } ///检测昵称是否重复 static Future checkNickRepeat(String nick) async { BaseModel baseModel = await NetUtil().get(SARSAPI.user.checkNickRepeat, params: { 'nickName': nick, }, showMessage: true); return baseModel.success; } ///设置昵称 static Future setNickName(String nick) async { BaseModel baseModel = await NetUtil().get(SARSAPI.user.setNickName, params: { 'nickName': nick, }, showMessage: true); return baseModel.success; } }