part of user_info;

class UserInfoController extends GetxController {
  final UserInfoModel userInfo;
  UserInfoController(this.userInfo);
// 时候展示底部视图
  bool showDetail = false;
  /// 上传头像
  void upload({
    required String path
  }) async {
     // String result  = await CommonAPI.upload(path:path,fileTypes: 'user');
     OssTool tool = OssTool('zxts-user-file');
     final response = await tool.putObjectFile(path);
     _changeInfo(response.realUri.toString());
  }

  void show(){
    showDetail = !showDetail;
    update();
  }

  /// 修改用用户信息
  void _changeInfo(String img) async {
    final result = await MineAPI.changeInfo(headImg: img);
    if(result){
      Toast.show('修改成功');
      userInfo.headImg = img;
      Map<String,dynamic> map = jsonDecode(StorageService.to.getString(kLocalUserInfo));
      if (map.keys.contains('head_img')){
        map['head_img'] = img;
        await StorageService.to.setString(kLocalUserInfo, jsonEncode(map));
      }
      update();
      Get.put(MineController()).getInfo();
    }
  }


}