From 9b155715eb53ad21d4a9dd2f2558c236bd74efd6 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 26 Mar 2021 15:13:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=88=BF=E5=B1=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/user/house_model.dart | 3 ++ lib/ui/profile/house/add_house_page.dart | 5 ++- lib/ui/profile/house/house_card.dart | 23 ++++-------- lib/ui/profile/house/house_owners_page.dart | 39 +++++++++++--------- lib/ui/profile/house/pick_my_house_page.dart | 36 +++++++++++++++++- lib/ui/profile/house/pick_role_page.dart | 13 ++++++- 6 files changed, 82 insertions(+), 37 deletions(-) diff --git a/lib/model/user/house_model.dart b/lib/model/user/house_model.dart index 25b2ee35..38cef9d1 100644 --- a/lib/model/user/house_model.dart +++ b/lib/model/user/house_model.dart @@ -11,6 +11,9 @@ class HouseModel { DateTime get effectiveStartDate => DateUtil.getDateTime(effectiveTimeStart); DateTime get effectiveEndDate => DateUtil.getDateTime(effectiveTimeEnd); + + //TODO 未通过状态 + bool get reviewed => status == 4; String get typeValue { switch (type) { case 1: diff --git a/lib/ui/profile/house/add_house_page.dart b/lib/ui/profile/house/add_house_page.dart index 42368147..9447ef0c 100644 --- a/lib/ui/profile/house/add_house_page.dart +++ b/lib/ui/profile/house/add_house_page.dart @@ -197,7 +197,8 @@ class _AddHousePageState extends State { text: PickRolePage.getType(_roleType), hintText: '请选择身份', onTap: () async { - int role = await Get.to(() => PickRolePage()); + int role = + await Get.to(() => PickRolePage(init: _roleType)); if (role != null) { _roleType = role; setState(() {}); @@ -279,6 +280,6 @@ class _AddHousePageState extends State { showMessage: true, ); cancel(); - if (model.status) Get.back(result:true); + 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 index 7b3ff887..dc4cba14 100644 --- a/lib/ui/profile/house/house_card.dart +++ b/lib/ui/profile/house/house_card.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/model/user/house_model.dart'; import 'package:akuCommunity/ui/profile/house/pick_my_house_page.dart'; import 'package:flutter/material.dart'; import 'package:akuCommunity/utils/headers.dart'; @@ -10,30 +11,22 @@ enum CardAuthType { } class HouseCard extends StatelessWidget { - final String plotName; - final String houseName; - final int role; + final HouseModel model; final CardAuthType type; const HouseCard({ Key key, - @required this.plotName, - @required this.houseName, - @required this.role, + @required this.model, @required this.type, }) : super(key: key); const HouseCard.fail({ Key key, - @required this.plotName, - @required this.houseName, - @required this.role, + @required this.model, }) : type = CardAuthType.FAIL, super(key: key); const HouseCard.success({ Key key, - @required this.plotName, - @required this.houseName, - @required this.role, + @required this.model, }) : type = CardAuthType.SUCCESS, super(key: key); @@ -48,7 +41,7 @@ class HouseCard extends StatelessWidget { } String get _roleName { - switch (role) { + switch (model.type) { case 1: return '业主'; case 2: @@ -125,12 +118,12 @@ class HouseCard extends StatelessWidget { ), 12.hb, Text( - plotName, + '人才公寓智慧小区', style: Theme.of(context).textTheme.headline3, ), 10.hb, Text( - houseName, + model.roomName, style: Theme.of(context).textTheme.subtitle1, ), Spacer(), diff --git a/lib/ui/profile/house/house_owners_page.dart b/lib/ui/profile/house/house_owners_page.dart index 5f15a128..5f6e7900 100644 --- a/lib/ui/profile/house/house_owners_page.dart +++ b/lib/ui/profile/house/house_owners_page.dart @@ -1,8 +1,6 @@ -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'; @@ -10,9 +8,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; 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/net_util.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:provider/provider.dart'; @@ -32,6 +28,12 @@ class _HouseOwnersPageState extends State { return appProvider.houses.isEmpty; } + ///存在已认证的房屋 + bool get _haveAuthedHouse { + final appProvider = Provider.of(context, listen: false); + return (appProvider?.selectedHouse?.status ?? 0) == 4; + } + @override Widget build(BuildContext context) { final appProvider = Provider.of(context); @@ -56,23 +58,26 @@ class _HouseOwnersPageState extends State { ? 280.hb : Padding( padding: EdgeInsets.all(32.w), - child: HouseCard.fail( - plotName: '人才公寓智慧小区', - houseName: appProvider.selectedHouse.roomName, - role: 1, + child: HouseCard( + type: appProvider.selectedHouse.reviewed + ? CardAuthType.SUCCESS + : CardAuthType.FAIL, + model: appProvider.selectedHouse, ), ), 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('添加房屋'), + if (!_haveAuthedHouse) + Padding( + padding: EdgeInsets.symmetric(horizontal: 75.w), + child: Image.asset(R.ASSETS_STATIC_REVIEWING_WEBP), + ), + if (!_haveAuthedHouse) + Center( + child: ElevatedButton( + onPressed: _addHouse, + child: Text('添加房屋'), + ), ), - ), ], ), ), diff --git a/lib/ui/profile/house/pick_my_house_page.dart b/lib/ui/profile/house/pick_my_house_page.dart index 5f026e6c..c0c219cd 100644 --- a/lib/ui/profile/house/pick_my_house_page.dart +++ b/lib/ui/profile/house/pick_my_house_page.dart @@ -4,6 +4,7 @@ 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:get/get.dart'; import 'package:provider/provider.dart'; import 'package:akuCommunity/utils/headers.dart'; @@ -26,6 +27,32 @@ class _PickMyHousePageState extends State { Widget get _renderSep => SliverToBoxAdapter(child: 24.hb); + List get housesWithoutSelected { + final appProvider = Provider.of(context, listen: false); + List models = List.from(appProvider.houses); + models.removeWhere( + (element) => element.id == (appProvider?.selectedHouse?.id ?? -1), + ); + if (models == null || models.isEmpty) return []; + return models; + } + + _renderList() { + return SliverList( + delegate: SliverChildListDelegate( + housesWithoutSelected + .map((e) => _HouseCard(model: e)) + .toList() + .sepWidget( + separate: Divider( + height: 1.w, + indent: 32.w, + endIndent: 32.w, + )), + ), + ); + } + @override Widget build(BuildContext context) { final appProvider = Provider.of(context); @@ -48,6 +75,9 @@ class _PickMyHousePageState extends State { highlight: true, ), ), + _renderSep, + if (housesWithoutSelected.isNotEmpty) _renderTitle('其他房屋'), + if (housesWithoutSelected.isNotEmpty) _renderList(), ], ), ).material(color: Colors.white), @@ -122,7 +152,11 @@ class _HouseCard extends StatelessWidget { ), ], ), - onPressed: () {}, + onPressed: () { + final appProvider = Provider.of(context, listen: false); + appProvider.setCurrentHouse(model); + Get.back(); + }, ); } } diff --git a/lib/ui/profile/house/pick_role_page.dart b/lib/ui/profile/house/pick_role_page.dart index fe4bf5e6..a9979f8f 100644 --- a/lib/ui/profile/house/pick_role_page.dart +++ b/lib/ui/profile/house/pick_role_page.dart @@ -10,6 +10,10 @@ import 'package:akuCommunity/widget/bee_scaffold.dart'; /// ///业主 亲属 租客 class PickRolePage extends StatefulWidget { + final int init; + + PickRolePage({Key key, this.init = 0}) : super(key: key); + static String getType(int index) { switch (index) { case 1: @@ -23,8 +27,6 @@ class PickRolePage extends StatefulWidget { } } - PickRolePage({Key key}) : super(key: key); - @override _PickRolePageState createState() => _PickRolePageState(); } @@ -55,6 +57,7 @@ class _PickRolePageState extends State { setState(() { _pickedValue = value; }); + Get.back(result: _pickedValue); }, ), 16.wb, @@ -70,6 +73,12 @@ class _PickRolePageState extends State { ); } + @override + void initState() { + super.initState(); + _pickedValue = widget.init; + } + @override Widget build(BuildContext context) { return BeeScaffold(