diff --git a/assets/static/house_auth_fail.webp b/assets/static/house_auth_fail.webp new file mode 100644 index 00000000..a283d590 Binary files /dev/null and b/assets/static/house_auth_fail.webp differ diff --git a/assets/static/house_auth_success.webp b/assets/static/house_auth_success.webp new file mode 100644 index 00000000..e682d683 Binary files /dev/null and b/assets/static/house_auth_success.webp differ diff --git a/assets/static/review_fail.webp b/assets/static/review_fail.webp new file mode 100644 index 00000000..bc1f68f7 Binary files /dev/null and b/assets/static/review_fail.webp differ diff --git a/lib/const/resource.dart b/lib/const/resource.dart index 3731703e..5484bd54 100644 --- a/lib/const/resource.dart +++ b/lib/const/resource.dart @@ -474,6 +474,14 @@ class R { /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/json/zbbj.json) static const String ASSETS_JSON_ZBBJ_JSON = 'assets/json/zbbj.json'; + /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/static/house_auth_fail.webp) + static const String ASSETS_STATIC_HOUSE_AUTH_FAIL_WEBP = + 'assets/static/house_auth_fail.webp'; + + /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/static/house_auth_success.webp) + static const String ASSETS_STATIC_HOUSE_AUTH_SUCCESS_WEBP = + 'assets/static/house_auth_success.webp'; + /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/static/reviewing.webp) static const String ASSETS_STATIC_REVIEWING_WEBP = 'assets/static/reviewing.webp'; diff --git a/lib/constants/app_theme.dart b/lib/constants/app_theme.dart index f81e1b13..708d16b1 100644 --- a/lib/constants/app_theme.dart +++ b/lib/constants/app_theme.dart @@ -8,7 +8,16 @@ class AppTheme { primaryColor: Color(0xFFFFD000), accentColor: Color(0xFFFFD000), textTheme: ThemeData.light().textTheme.copyWith( + headline3: TextStyle( + fontSize: 40.sp, + color: Color(0xFF333333), + fontWeight: FontWeight.bold, + ), subtitle1: TextStyle( + fontSize: 32.sp, + color: Color(0xFF333333), + ), + subtitle2: TextStyle( fontSize: 28.sp, color: Color(0xFF333333), ), @@ -76,6 +85,20 @@ class AppTheme { enableFeedback: true, ), ), + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + overlayColor: MaterialStateProperty.resolveWith((states) { + if (states.contains(MaterialState.disabled)) + return Color(0xFFFFF4D7); + return Color(0xFFFFD000).withOpacity(0.2); + }), + foregroundColor: MaterialStateProperty.resolveWith((states) { + if (states.contains(MaterialState.disabled)) + return Color(0xFF666666); + return Color(0xFF333333); + }), + ), + ), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, dividerColor: Color(0xFFE8E8E8), ); diff --git a/lib/model/user/house_model.dart b/lib/model/user/house_model.dart index 2e455549..25b2ee35 100644 --- a/lib/model/user/house_model.dart +++ b/lib/model/user/house_model.dart @@ -1,26 +1,77 @@ import 'package:flustars/flustars.dart'; +import 'package:flutter/material.dart'; class HouseModel { int id; String roomName; int status; + int type; String effectiveTimeStart; String effectiveTimeEnd; DateTime get effectiveStartDate => DateUtil.getDateTime(effectiveTimeStart); DateTime get effectiveEndDate => DateUtil.getDateTime(effectiveTimeEnd); + String get typeValue { + switch (type) { + case 1: + return '业主'; + case 2: + return '租客'; + case 3: + return '情书'; + } + return ''; + } + + ///我的房屋页面背景颜色 + /// + List get backgroundColor { + //TODO 未通过状态 + if (status != 4) + return [ + Color(0xFFF5F5F5), + Color(0xFFEFEEEE), + Color(0xFFE8E8E8), + ]; + if (type == 1) + return [ + Color(0xFFFFDF7D), + Color(0xFFFFD654), + Color(0xFFFFC40C), + ]; + if (type == 2) + return [ + Color(0xFFFFA446), + Color(0xFFFFA547), + Color(0xFFFF8200), + ]; + if (type == 3) + return [ + Color(0xFF9ADE79), + Color(0xFF91DE6B), + Color(0xFF6ECB41), + ]; + return [ + Color(0xFFF5F5F5), + Color(0xFFEFEEEE), + Color(0xFFE8E8E8), + ]; + } - HouseModel( - {this.id, - this.roomName, - this.status, - this.effectiveTimeStart, - this.effectiveTimeEnd}); + HouseModel({ + this.id, + this.roomName, + this.status, + this.type, + this.effectiveTimeStart, + this.effectiveTimeEnd, + }); HouseModel.fromJson(Map json) { id = json['id']; roomName = json['roomName']; status = json['status']; + type = json['type']; effectiveTimeStart = json['effectiveTimeStart']; effectiveTimeEnd = json['effectiveTimeEnd']; } diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 01bc9ece..4126fb40 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -1,3 +1,4 @@ +import 'package:akuCommunity/model/user/house_model.dart'; import 'package:flutter/material.dart'; import 'package:amap_flutter_location/amap_flutter_location.dart'; @@ -174,4 +175,30 @@ class AppProvider extends ChangeNotifier { _messageCenterModel = MessageCenterModel.fromJson(response.data); notifyListeners(); } + + List _houses = []; + + ///我的房屋列表 + List get houses => _houses; + + ///更新房屋列表 + updateHouses(List items) { + _houses = items; + notifyListeners(); + } + + HouseModel _selectedHouse; + + ///选中的房屋 + HouseModel get selectedHouse { + if (_houses?.isEmpty ?? true) return null; + if (_selectedHouse == null) _selectedHouse = _houses.first; + return _selectedHouse; + } + + ///设置当前选中的房屋 + setCurrentHouse(HouseModel model) { + _selectedHouse = model; + notifyListeners(); + } } diff --git a/lib/ui/profile/house/add_house_page.dart b/lib/ui/profile/house/add_house_page.dart index e3b80e0a..42368147 100644 --- a/lib/ui/profile/house/add_house_page.dart +++ b/lib/ui/profile/house/add_house_page.dart @@ -57,7 +57,7 @@ class _AddHousePageState extends State { children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 16.w), - child: Text(title, style: Theme.of(context).textTheme.subtitle1), + child: Text(title, style: Theme.of(context).textTheme.subtitle2), ), item ?? SizedBox(), ], @@ -279,6 +279,6 @@ class _AddHousePageState extends State { showMessage: true, ); cancel(); - if (model.status) Get.back(); + if (model.status) Get.back(result:true); } } diff --git a/lib/ui/profile/house/house_card.dart b/lib/ui/profile/house/house_card.dart new file mode 100644 index 00000000..7b3ff887 --- /dev/null +++ b/lib/ui/profile/house/house_card.dart @@ -0,0 +1,158 @@ +import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/ui/profile/house/pick_my_house_page.dart'; +import 'package:flutter/material.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:get/get.dart'; + +enum CardAuthType { + FAIL, + SUCCESS, +} + +class HouseCard extends StatelessWidget { + final String plotName; + final String houseName; + final int role; + final CardAuthType type; + const HouseCard({ + Key key, + @required this.plotName, + @required this.houseName, + @required this.role, + @required this.type, + }) : super(key: key); + + const HouseCard.fail({ + Key key, + @required this.plotName, + @required this.houseName, + @required this.role, + }) : type = CardAuthType.FAIL, + super(key: key); + const HouseCard.success({ + Key key, + @required this.plotName, + @required this.houseName, + @required this.role, + }) : type = CardAuthType.SUCCESS, + super(key: key); + + String get _assetPath { + switch (type) { + case CardAuthType.FAIL: + return R.ASSETS_STATIC_HOUSE_AUTH_FAIL_WEBP; + case CardAuthType.SUCCESS: + return R.ASSETS_STATIC_HOUSE_AUTH_SUCCESS_WEBP; + } + return ''; + } + + String get _roleName { + switch (role) { + case 1: + return '业主'; + case 2: + return ''; + case 3: + return ''; + default: + return ''; + } + } + + List get _shadows { + switch (type) { + case CardAuthType.FAIL: + return [ + BoxShadow( + offset: Offset(0, 10.w), + blurRadius: 30.w, + color: Color(0xFFF0F0F0), + ), + ]; + case CardAuthType.SUCCESS: + return [ + BoxShadow( + offset: Offset(0, 10.w), + blurRadius: 30.w, + color: Color(0xFFFFF0BF), + ), + ]; + } + return []; + } + + @override + Widget build(BuildContext context) { + return AspectRatio( + aspectRatio: 686 / 386, + child: Container( + clipBehavior: Clip.antiAlias, + height: double.infinity, + width: double.infinity, + padding: EdgeInsets.only(left: 40.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + 28.hb, + Align( + alignment: Alignment.centerRight, + child: MaterialButton( + height: 48.w, + minWidth: 152.w, + color: Colors.white, + padding: EdgeInsets.zero, + elevation: 0, + focusElevation: 0, + hoverElevation: 0, + disabledElevation: 0, + highlightElevation: 0, + child: Text( + '切换房屋', + style: TextStyle( + color: Color(0xFF333333), + fontSize: 24.sp, + ), + ), + onPressed: () { + Get.to(PickMyHousePage()); + }, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.horizontal(left: Radius.circular(24.w)), + ), + ), + ), + 12.hb, + Text( + plotName, + style: Theme.of(context).textTheme.headline3, + ), + 10.hb, + Text( + houseName, + style: Theme.of(context).textTheme.subtitle1, + ), + Spacer(), + Text( + '身份', + style: Theme.of(context).textTheme.subtitle2.copyWith( + color: Color(0xFF666666), + ), + ), + Text( + _roleName, + style: Theme.of(context).textTheme.subtitle1, + ), + 40.hb, + ], + ), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.w), + image: DecorationImage(image: AssetImage(_assetPath)), + boxShadow: _shadows, + ), + ), + ); + } +} diff --git a/lib/ui/profile/house/house_func.dart b/lib/ui/profile/house/house_func.dart new file mode 100644 index 00000000..93da9e2d --- /dev/null +++ b/lib/ui/profile/house/house_func.dart @@ -0,0 +1,12 @@ +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/user/house_model.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; + +class HouseFunc { + static Future> get houses async { + BaseModel model = await NetUtil().get(API.user.houseList); + if (!model.status) return []; + return (model.data as List).map((e) => HouseModel.fromJson(e)).toList(); + } +} diff --git a/lib/ui/profile/house/house_owners_page.dart b/lib/ui/profile/house/house_owners_page.dart index be68fe98..5f15a128 100644 --- a/lib/ui/profile/house/house_owners_page.dart +++ b/lib/ui/profile/house/house_owners_page.dart @@ -1,3 +1,8 @@ +import 'package:akuCommunity/model/user/house_model.dart'; +import 'package:akuCommunity/provider/app_provider.dart'; +import 'package:akuCommunity/ui/profile/house/house_card.dart'; +import 'package:akuCommunity/ui/profile/house/house_func.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -7,9 +12,10 @@ import 'package:get/get.dart'; import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/ui/profile/house/add_house_page.dart'; -import 'package:akuCommunity/utils/network/base_list_model.dart'; import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:provider/provider.dart'; class HouseOwnersPage extends StatefulWidget { HouseOwnersPage({Key key}) : super(key: key); @@ -21,48 +27,61 @@ class HouseOwnersPage extends StatefulWidget { class _HouseOwnersPageState extends State { EasyRefreshController _refreshController = EasyRefreshController(); + bool get _emptyHouse { + final appProvider = Provider.of(context, listen: false); + return appProvider.houses.isEmpty; + } + @override Widget build(BuildContext context) { - final media = MediaQuery.of(context); + final appProvider = Provider.of(context); return BeeScaffold( title: '我的房屋', - actions: [], + actions: [ + TextButton( + onPressed: _addHouse, + child: Text('新增房屋'), + ), + ], body: EasyRefresh( header: MaterialHeader(), controller: _refreshController, firstRefresh: true, onRefresh: () async { - await _getFirstHouse(); + appProvider.updateHouses(await HouseFunc.houses); }, - child: SizedBox( - height: media.size.height - media.padding.top - 56, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 75.w), - child: Image.asset(R.ASSETS_STATIC_REVIEWING_WEBP), - ), - ElevatedButton( + child: ListView( + children: [ + _emptyHouse + ? 280.hb + : Padding( + padding: EdgeInsets.all(32.w), + child: HouseCard.fail( + plotName: '人才公寓智慧小区', + houseName: appProvider.selectedHouse.roomName, + role: 1, + ), + ), + if (!_emptyHouse) 88.hb, + Padding( + padding: EdgeInsets.symmetric(horizontal: 75.w), + child: Image.asset(R.ASSETS_STATIC_REVIEWING_WEBP), + ), + Center( + child: ElevatedButton( onPressed: _addHouse, child: Text('添加房屋'), ), - ], - ), + ), + ], ), ), ); } + ///跳转到添加房屋 _addHouse() async { - await Get.to(() => AddHousePage()); - } - - Future _getFirstHouse() async { - BaseListModel model = await NetUtil().getList( - API.user.houseList, - params: {'pageNum': 1, 'size': 1}, - ); - print(model.tableList); + bool result = await Get.to(() => AddHousePage()); + if (result == true) _refreshController.callRefresh(); } } diff --git a/lib/ui/profile/house/pick_my_house_page.dart b/lib/ui/profile/house/pick_my_house_page.dart new file mode 100644 index 00000000..5f026e6c --- /dev/null +++ b/lib/ui/profile/house/pick_my_house_page.dart @@ -0,0 +1,128 @@ +import 'package:akuCommunity/model/user/house_model.dart'; +import 'package:akuCommunity/provider/app_provider.dart'; +import 'package:akuCommunity/ui/profile/house/house_func.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:provider/provider.dart'; +import 'package:akuCommunity/utils/headers.dart'; + +class PickMyHousePage extends StatefulWidget { + PickMyHousePage({Key key}) : super(key: key); + + @override + _PickMyHousePageState createState() => _PickMyHousePageState(); +} + +class _PickMyHousePageState extends State { + _renderTitle(String title) { + return SliverPadding( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 16.w), + sliver: SliverToBoxAdapter( + child: Text(title, style: Theme.of(context).textTheme.subtitle2), + ), + ); + } + + Widget get _renderSep => SliverToBoxAdapter(child: 24.hb); + + @override + Widget build(BuildContext context) { + final appProvider = Provider.of(context); + return BeeScaffold( + title: '我的房屋', + body: EasyRefresh( + header: MaterialHeader(), + onRefresh: () async { + final appProvider = Provider.of(context, listen: false); + appProvider.updateHouses(await HouseFunc.houses); + }, + firstRefresh: true, + child: CustomScrollView( + slivers: [ + _renderSep, + _renderTitle('当前房屋'), + SliverToBoxAdapter( + child: _HouseCard( + model: appProvider.selectedHouse, + highlight: true, + ), + ), + ], + ), + ).material(color: Colors.white), + bottomNavi: ElevatedButton( + child: Text('新增房屋'), + onPressed: () {}, + style: ButtonStyle( + padding: + MaterialStateProperty.all(EdgeInsets.symmetric(vertical: 26.w)), + ), + ), + ); + } +} + +class _HouseCard extends StatelessWidget { + final HouseModel model; + final bool highlight; + const _HouseCard({Key key, @required this.model, this.highlight = false}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialButton( + padding: EdgeInsets.symmetric(horizontal: 32.w), + height: 136.w, + child: Row( + children: [ + Container( + child: Text( + model.typeValue, + style: Theme.of(context).textTheme.subtitle2.copyWith( + fontWeight: FontWeight.bold, + ), + ), + alignment: Alignment.center, + height: 88.w, + width: 88.w, + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4.w), + gradient: LinearGradient( + colors: model.backgroundColor, + begin: Alignment.topLeft, + end: Alignment.bottomRight, + ), + ), + ), + 24.wb, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + '人才公寓智慧小区', + style: Theme.of(context).textTheme.subtitle1.copyWith( + color: + highlight ? Color(0xFFFF8200) : Color(0xFF333333), + fontWeight: FontWeight.bold, + ), + ), + 8.hb, + Text( + model.roomName, + style: Theme.of(context).textTheme.subtitle2.copyWith( + color: Color(0xFF999999), + ), + ), + ], + ), + ), + ], + ), + onPressed: () {}, + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 76419f28..ca549faf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -281,13 +281,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.0.0-nullsafety.2" - flutter_datetime_picker: - dependency: "direct main" - description: - name: flutter_datetime_picker - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.0" flutter_easyrefresh: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5bd1305f..3e94e09d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,8 +47,6 @@ dependencies: dio: ^4.0.0-prev3 #骨架 shimmer: ^2.0.0-nullsafety.0 - #时间选择 - flutter_datetime_picker: ^1.4.0 #随机二维码 qr_flutter: ^4.0.0