diff --git a/lib/constants/api.dart b/lib/constants/api.dart index ab3385e7..c73b8384 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -4,6 +4,7 @@ class API { static const int networkTimeOut = 10000; static _Login login = _Login(); static _User user = _User(); + static _Manager manager = _Manager(); } class _Login { @@ -36,3 +37,7 @@ class _User { ///用户退出登陆 String get logout => '/user/signOut'; } + +class _Manager { + String get commiteeStaff => '/ownersCommittee/findAll'; +} diff --git a/lib/model/user/committee_item_model.dart b/lib/model/user/committee_item_model.dart new file mode 100644 index 00000000..ff48fba8 --- /dev/null +++ b/lib/model/user/committee_item_model.dart @@ -0,0 +1,63 @@ +class CommitteeItemModel { + int id; + int positionId; + String name; + int sexId; + int age; + int educationId; + String roomName; + String profession; + String roomNumber; + int unitNo; + int estateNo; + + String get sexValue { + if (sexId == 0 || sexId == null) return '未设置'; + if (sexId == 1) return '男'; + if (sexId == 2) return '女'; + return '未设置'; + } + + CommitteeItemModel( + {this.id, + this.positionId, + this.name, + this.sexId, + this.age, + this.educationId, + this.roomName, + this.profession, + this.roomNumber, + this.unitNo, + this.estateNo}); + + CommitteeItemModel.fromJson(Map json) { + id = json['id']; + positionId = json['positionId']; + name = json['name']; + sexId = json['sexId']; + age = json['age']; + educationId = json['educationId']; + roomName = json['roomName']; + profession = json['profession']; + roomNumber = json['roomNumber']; + unitNo = json['unitNo']; + estateNo = json['estateNo']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['positionId'] = this.positionId; + data['name'] = this.name; + data['sexId'] = this.sexId; + data['age'] = this.age; + data['educationId'] = this.educationId; + data['roomName'] = this.roomName; + data['profession'] = this.profession; + data['roomNumber'] = this.roomNumber; + data['unitNo'] = this.unitNo; + data['estateNo'] = this.estateNo; + return data; + } +} diff --git a/lib/pages/industry_committee/industry_committee_page.dart b/lib/pages/industry_committee/industry_committee_page.dart index d63a44d4..ce8c262f 100644 --- a/lib/pages/industry_committee/industry_committee_page.dart +++ b/lib/pages/industry_committee/industry_committee_page.dart @@ -1,8 +1,13 @@ import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/user/committee_item_model.dart'; import 'package:akuCommunity/pages/industry_committee/committee_mailbox/committee_mailbox_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:flutter/material.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:get/get.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:akuCommunity/utils/headers.dart'; @@ -16,6 +21,38 @@ class IndustryCommitteePage extends StatefulWidget { } class _IndustryCommitteePageState extends State { + EasyRefreshController _refreshController = EasyRefreshController(); + BaseListModel _listModel = BaseListModel.zero(); + List _committeeModels = []; + int _page = 0; + + Future> _getCommitteeList() async { + _listModel = await NetUtil().getList(API.manager.commiteeStaff, params: { + 'pageNum': _page, + 'size': 10, + }); + return _listModel.tableList + .map((e) => CommitteeItemModel.fromJson(e)) + .toList(); + } + + Future refresh() async { + _page = 0; + _listModel = BaseListModel.zero(); + _committeeModels.clear(); + _committeeModels = await _getCommitteeList(); + setState(() {}); + } + + Future addPage() async { + _page++; + if (_page >= _listModel.pageCount) + _refreshController.finishLoad(noMore: true); + else + _committeeModels.addAll(await _getCommitteeList()); + setState(() {}); + } + Widget _buildBottomNavi() { return [ MaterialButton( @@ -65,11 +102,75 @@ class _IndustryCommitteePageState extends State { ].row(); } + Widget _buildCard(CommitteeItemModel model) { + return VxBox( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(4.w), + child: SizedBox( + height: 150.w, + width: 150.w, + child: Placeholder(), + ), + ), + 24.wb, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + [ + model.name.text.size(28.sp).color(ktextPrimary).make(), + Spacer(), + Container( + height: 44.w, + padding: + EdgeInsets.symmetric(horizontal: 22.w, vertical: 6.w), + child: 'XXX'.text.size(24.sp).color(ktextPrimary).make(), + decoration: BoxDecoration( + color: Color(0xFFFFF3CD), + borderRadius: BorderRadius.circular(22.w), + border: Border.all(color: Color(0xFFFFC40C), width: 1.w), + ), + ), + ].row(), + 6.hb, + ...[ + '住址:${model.roomName}' + .text + .size(24.sp) + .color(ktextSubColor) + .make(), + '任职期限:XXXXX'.text.size(24.sp).color(ktextSubColor).make(), + '从事岗位:${model.profession}' + .text + .size(24.sp) + .color(ktextSubColor) + .make(), + ].sepWidget(separate: 10.hb), + ], + ).expand(), + ], + ), + ).padding(EdgeInsets.all(20.w)).white.withRounded(value: 8.w).make(); + } + Widget build(BuildContext context) { return BeeScaffold( title: '业委会', - body: Stack( - children: [], + body: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + controller: _refreshController, + onRefresh: refresh, + child: ListView.separated( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.w), + itemBuilder: (context, index) { + return _buildCard(_committeeModels[index]); + }, + separatorBuilder: (context, index) => 20.hb, + itemCount: _committeeModels.length, + ), ), bottomNavi: _buildBottomNavi(), ); diff --git a/lib/utils/network/base_list_model.dart b/lib/utils/network/base_list_model.dart new file mode 100644 index 00000000..e576232c --- /dev/null +++ b/lib/utils/network/base_list_model.dart @@ -0,0 +1,27 @@ +class BaseListModel { + int pageCount; + int rowCount; + List tableList; + BaseListModel({ + this.pageCount, + this.rowCount, + this.tableList, + }); + BaseListModel.zero({ + this.pageCount = 0, + this.rowCount = 0, + this.tableList = const [], + }); + + BaseListModel.err({ + this.pageCount = 0, + this.rowCount = 0, + this.tableList = const [], + }); + + BaseListModel.fromJson(Map json) { + pageCount = json['pageCount'] ?? 0; + rowCount = json['rowCount'] ?? 0; + tableList = json['tableList'] ?? []; + } +} diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index 7391bc61..1260c61e 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/utils/logger/logger_data.dart'; +import 'package:akuCommunity/utils/network/base_list_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:dio/dio.dart'; @@ -37,6 +38,9 @@ class NetUtil { _dio.options.headers.putIfAbsent('App-Admin-Token', () => token); } + /// ## alias of Dio().get + /// + /// GET method Future get( String path, { Map params, @@ -60,6 +64,11 @@ class NetUtil { return BaseModel.err(); } + /// ## alias of Dio().post + /// + /// POST method + /// + /// only work with JSON. Future post( String path, { Map params, @@ -84,6 +93,27 @@ class NetUtil { return BaseModel.err(); } + Future getList( + String path, { + Map params, + }) async { + try { + Response res = await _dio.get(path, queryParameters: params); + _logger.v({ + 'path': res.request.path, + 'header': res.request.headers, + 'params': res.request.queryParameters, + 'data': res.data, + }); + LoggerData.addData(res); + BaseListModel baseListModel = BaseListModel.fromJson(res.data); + return baseListModel; + } on DioError catch (e) { + _parseErr(e); + } + return BaseListModel.err(); + } + _parseErr(DioError err) { _logger.v({ 'type': err.type.toString(),