diff --git a/lib/constants/saas_api.dart b/lib/constants/saas_api.dart index 1cf4f042..2c384e3e 100644 --- a/lib/constants/saas_api.dart +++ b/lib/constants/saas_api.dart @@ -58,6 +58,12 @@ class _City { class _Bracelet { ///爱牵挂手环数据 String get data => '/app/user/elderlyCareEquipment/getAqgData'; + + ///添加爱牵挂手环 + String get add => '/app/user/elderlyCareEquipment/bind'; + + ///绑定设备列表 + String get list => '/app/user/elderlyCareEquipment/list'; } class _User { diff --git a/lib/main.dart b/lib/main.dart index 774eb5ea..837ec0bb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:aku_new_community/provider/old_age_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -40,6 +41,7 @@ class _MyAppState extends State { ChangeNotifierProvider(create: (context) => SignUpProvider()), ChangeNotifierProvider(create: (context) => DataProvider()), ChangeNotifierProvider(create: (context) => ClockTimerProvider()), + ChangeNotifierProvider(create: (context) => OldAgeProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/models/bracelet/bracelet_list_model.dart b/lib/models/bracelet/bracelet_list_model.dart new file mode 100644 index 00000000..61bf51c1 --- /dev/null +++ b/lib/models/bracelet/bracelet_list_model.dart @@ -0,0 +1,33 @@ +import 'package:aku_new_community/pages/services/old_age/old_enum.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; + +part 'bracelet_list_model.g.dart'; + +@JsonSerializable() +class BraceletListModel extends Equatable { + final int id; + final int type; + final String deviceType; + final String imei; + + factory BraceletListModel.fromJson(Map json) => + _$BraceletListModelFromJson(json); + + BraceletBrand get braceletBrand => BraceletBrand.getValue(type); + + const BraceletListModel({ + required this.id, + required this.type, + required this.deviceType, + required this.imei, + }); + + @override + List get props => [ + id, + type, + deviceType, + imei, + ]; +} diff --git a/lib/models/test.g.dart b/lib/models/bracelet/bracelet_list_model.g.dart similarity index 51% rename from lib/models/test.g.dart rename to lib/models/bracelet/bracelet_list_model.g.dart index 180ef7d1..dba8614b 100644 --- a/lib/models/test.g.dart +++ b/lib/models/bracelet/bracelet_list_model.g.dart @@ -1,11 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'test.dart'; +part of 'bracelet_list_model.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -Test _$TestFromJson(Map json) => Test( +BraceletListModel _$BraceletListModelFromJson(Map json) => + BraceletListModel( id: json['id'] as int, + type: json['type'] as int, + deviceType: json['deviceType'] as String, + imei: json['imei'] as String, ); diff --git a/lib/models/test.dart b/lib/models/test.dart deleted file mode 100644 index 77462aa9..00000000 --- a/lib/models/test.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:equatable/equatable.dart'; - -part 'test.g.dart'; - -@JsonSerializable() -class Test extends Equatable { - final int id; - - factory Test.fromJson(Map json) => _$TestFromJson(json); - - @override - List get props => [ - id, - ]; - - const Test({ - required this.id, - }); -} diff --git a/lib/pages/personal/wallet/balance_record_view.dart b/lib/pages/personal/wallet/balance_record_view.dart index 5fc5fb9b..855a8ab2 100644 --- a/lib/pages/personal/wallet/balance_record_view.dart +++ b/lib/pages/personal/wallet/balance_record_view.dart @@ -1,3 +1,5 @@ +import 'package:aku_new_community/extensions/widget_list_ext.dart'; +import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -31,6 +33,7 @@ class _BalanceRecordViewState extends State { int _pickType = 0; Map _types = { + 0: '全部', 1: '支付', 2: '退还', 3: '充值', @@ -89,7 +92,7 @@ class _BalanceRecordViewState extends State { return BeePickerBox( onPressed: () { Get.back(); - setState(() {}); + _refreshController.callRefresh(); }, child: CupertinoPicker.builder( itemExtent: 60.w, @@ -142,7 +145,7 @@ class _BalanceRecordViewState extends State { .getList(SAASAPI.balance.tradeRecordList, params: { 'pageNum': _pageNum, 'size': _size, - 'modelType': 0, + 'modelType': 1, 'type': _pickType == 0 ? null : _pickType, 'createDate': DateUtil.formatDate(_pickTime, format: DateFormats.full), @@ -176,7 +179,11 @@ class _BalanceRecordViewState extends State { }, child: ListView( padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), - children: _models.map((e) => _buildCard(e)).toList(), + children: _models.map((e) => _buildCard(e)).toList().sepWidget( + separate: Padding( + padding: EdgeInsets.symmetric(vertical: 20.w), + child: BeeDivider(), + )), ), ), ), @@ -189,6 +196,7 @@ class _BalanceRecordViewState extends State { Widget _buildCard(TradeRecordListModel model) { return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ diff --git a/lib/pages/personal/wallet/point_record_view.dart b/lib/pages/personal/wallet/point_record_view.dart index ed67f767..f6d0dd01 100644 --- a/lib/pages/personal/wallet/point_record_view.dart +++ b/lib/pages/personal/wallet/point_record_view.dart @@ -1,3 +1,6 @@ +import 'package:aku_new_community/extensions/widget_list_ext.dart'; +import 'package:aku_new_community/gen/assets.gen.dart'; +import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -31,6 +34,7 @@ class _PointRecordViewState extends State { int _pickType = 0; Map _types = { + 0:'全部', 1: '支付', 2: '退还', 3: '充值', @@ -89,7 +93,7 @@ class _PointRecordViewState extends State { return BeePickerBox( onPressed: () { Get.back(); - setState(() {}); + _refreshController.callRefresh(); }, child: CupertinoPicker.builder( itemExtent: 60.w, @@ -142,7 +146,7 @@ class _PointRecordViewState extends State { .getList(SAASAPI.balance.tradeRecordList, params: { 'pageNum': _pageNum, 'size': _size, - 'modelType': 1, + 'modelType': 2, 'type': _pickType == 0 ? null : _pickType, 'createDate': DateUtil.formatDate(_pickTime, format: DateFormats.full), @@ -175,7 +179,10 @@ class _PointRecordViewState extends State { }, child: ListView( padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), - children: _models.map((e) => _buildCard(e)).toList(), + children: _models.map((e) => _buildCard(e)).toList().sepWidget(separate: Padding( + padding: EdgeInsets.symmetric(vertical: 20.w), + child: BeeDivider(), + )), ), ), ), @@ -188,6 +195,7 @@ class _PointRecordViewState extends State { Widget _buildCard(TradeRecordListModel model) { return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ @@ -197,13 +205,14 @@ class _PointRecordViewState extends State { .color(Colors.black.withOpacity(0.85)) .make(), Spacer(), - '${incom(model.type) ? '+' : '-'}¥${model.payAmount}' + '${incom(model.type) ? '+' : '-'}${model.payAmount.toInt()}' .text .size(28.sp) .color(incom(model.type) ? Colors.red : Colors.black.withOpacity(0.85)) .make(), + Assets.icons.intergral.image(width: 32.w,height: 32.w), ], ), 8.hb, diff --git a/lib/pages/personal/wallet/wallet_recharge_page.dart b/lib/pages/personal/wallet/wallet_recharge_page.dart index 40b6f53c..ecf92709 100644 --- a/lib/pages/personal/wallet/wallet_recharge_page.dart +++ b/lib/pages/personal/wallet/wallet_recharge_page.dart @@ -34,7 +34,7 @@ class _WalletRechargePageState extends State late TabController _tabController; List _tabs = ['余额充值', '积分充值']; - List _balanceValue = [10, 20, 30, 50, 00, 200, 300, 500]; + List _balanceValue = [10, 20, 30, 50, 100, 200, 300, 500]; List _pointValue = [10, 200, 300, 500, 1000, 2000, 5000, 10000]; int _rechargeValue = 0; diff --git a/lib/pages/services/old_age/equipment_list_page.dart b/lib/pages/services/old_age/equipment_list_page.dart index 925dfe83..adaf39c4 100644 --- a/lib/pages/services/old_age/equipment_list_page.dart +++ b/lib/pages/services/old_age/equipment_list_page.dart @@ -1,29 +1,20 @@ +import 'package:aku_new_community/constants/saas_api.dart'; +import 'package:aku_new_community/models/bracelet/bracelet_list_model.dart'; +import 'package:aku_new_community/utils/network/net_util.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:aku_new_community/extensions/widget_list_ext.dart'; -import 'package:aku_new_community/gen/assets.gen.dart'; -import 'package:aku_new_community/pages/services/old_age/add_equipment_page.dart'; import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; -class bracelet { - String title; - String describe; - bool open; - String path; - - bracelet({ - required this.title, - required this.describe, - required this.open, - required this.path, - }); -} +import 'add_equipment_page.dart'; class EquipmentListPage extends StatefulWidget { const EquipmentListPage({Key? key}) : super(key: key); @@ -33,20 +24,8 @@ class EquipmentListPage extends StatefulWidget { } class _EquipmentListPageState extends State { - List _connects = [ - bracelet( - title: 'x5手环', - describe: '爱牵挂', - open: true, - path: Assets.bracelet.x5.path), - ]; - List _bracelets = [ - bracelet( - title: 'x8手环 旗舰型', - describe: '爱牵挂', - open: false, - path: Assets.bracelet.x8.path), - ]; + BraceletListModel? _currentBracelet; + List _bracelets = []; @override Widget build(BuildContext context) { @@ -82,49 +61,8 @@ class _EquipmentListPageState extends State { .bold .make(), 24.w.heightBox, - ..._connects - .map((e) => Container( - width: double.infinity, - padding: EdgeInsets.all(24.w), - decoration: BoxDecoration( - color: Color(0xFF6395D7), - borderRadius: BorderRadius.circular(16.w)), - child: Row( - children: [ - Image.asset( - e.path, - width: 100.w, - height: 100.w, - ), - 12.w.widthBox, - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - '${e.title}'.text.size(24.sp).white.make(), - 16.w.heightBox, - '${e.describe}'.text.size(24.sp).white.make(), - ], - ), - Spacer(), - Container( - width: 15.w, - height: 16.w, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16.w), - ), - ), - 24.w.widthBox, - '${e.open ? '已连接' : '未开启'}' - .text - .size(24.sp) - .white - .make(), - ], - ), - )) - .toList() - .sepWidget(separate: 24.w.heightBox), + if (_currentBracelet != null) + _braceletWidget(e: _currentBracelet!, bgColor: Color(0xFF6395D7)) ], ), ); @@ -141,55 +79,12 @@ class _EquipmentListPageState extends State { .make(), 24.w.heightBox, ..._bracelets - .map((e) => Container( - width: double.infinity, - padding: EdgeInsets.all(24.w), - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.06), - borderRadius: BorderRadius.circular(16.w)), - child: Row( - children: [ - Image.asset( - e.path, - width: 100.w, - height: 100.w, - ), - 12.w.widthBox, - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - '${e.title}' - .text - .size(24.sp) - .color(Colors.black.withOpacity(0.65)) - .make(), - 16.w.heightBox, - '${e.describe}' - .text - .size(24.sp) - .color(Colors.black.withOpacity(0.65)) - .make(), - ], - ), - Spacer(), - Container( - width: 15.w, - height: 16.w, - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.25), - borderRadius: BorderRadius.circular(16.w), - ), - ), - 24.w.widthBox, - '${e.open ? '已连接' : '未开启'}' - .text - .size(24.sp) - .color(Colors.black.withOpacity(0.65)) - .make(), - ], - ), - )) + .map((e) => _braceletWidget( + e: e, + onTap: () { + _currentBracelet = e; + setState(() {}); + })) .toList() .sepWidget( separate: 24.w.heightBox, @@ -201,32 +96,103 @@ class _EquipmentListPageState extends State { title: '设备列表', bodyColor: Colors.white, body: SafeArea( + child: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + var base = await NetUtil().get(SAASAPI.bracelet.list); + if (base.success) { + _bracelets = (base.data as List) + .map((e) => BraceletListModel.fromJson(e)) + .toList(); + setState(() {}); + } + }, child: ListView( - padding: EdgeInsets.all(24.w), - children: [ - // user, - // BeeDivider.horizontal(), - connected, - 24.w.heightBox, - bingding, - BeeDivider.horizontal(), - // 24.w.heightBox, - Row( - mainAxisAlignment: MainAxisAlignment.start, + padding: EdgeInsets.all(24.w), children: [ - TextButton( - onPressed: () { - Get.to(() => AddEquipmentPage()); - }, - child: '添加智能设备' - .text - .size(28.sp) - .color(Color(0xFF6395D7)) - .make()), + // user, + // BeeDivider.horizontal(), + connected, + 24.w.heightBox, + bingding, + BeeDivider.horizontal(), + // 24.w.heightBox, ], - ) - ], - )), + ), + ), + ), + bottomNavi: Padding( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), + child: MaterialButton( + onPressed: () { + Get.to(() => AddEquipmentPage()); + }, + color: Color(0xFF5096F1), + padding: EdgeInsets.symmetric(vertical: 24.w), + minWidth: 686.w, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.w), + ), + child: '添加设备'.text.size(28.sp).white.make(), + ), + ), + ); + } + + Widget _braceletWidget( + {required BraceletListModel e, VoidCallback? onTap, Color? bgColor}) { + return GestureDetector( + onTap: onTap, + child: Container( + width: double.infinity, + padding: EdgeInsets.all(24.w), + decoration: BoxDecoration( + color: bgColor ?? Colors.black.withOpacity(0.06), + borderRadius: BorderRadius.circular(16.w)), + child: Row( + children: [ + Image.asset( + e.braceletBrand.imgPath, + width: 100.w, + height: 100.w, + ), + 12.w.widthBox, + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + '${e.deviceType} ${e.braceletBrand.name}' + .text + .size(24.sp) + .color(Colors.black.withOpacity(0.65)) + .make(), + 16.w.heightBox, + '设备码:${e.imei}' + .text + .size(24.sp) + .color(Colors.black.withOpacity(0.65)) + .make(), + ], + ), + Spacer(), + Container( + width: 15.w, + height: 16.w, + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.25), + borderRadius: BorderRadius.circular(16.w), + ), + ), + 24.w.widthBox, + '${UserTool.oldAgeProvider.imei == e.imei ? '已连接' : '未开启'}' + .text + .size(24.sp) + .color(Colors.black.withOpacity(0.65)) + .make(), + ], + ), + ), ); } } diff --git a/lib/pages/services/old_age/old_age_support_page_simple.dart b/lib/pages/services/old_age/old_age_support_page_simple.dart index 56c9d837..4762e714 100644 --- a/lib/pages/services/old_age/old_age_support_page_simple.dart +++ b/lib/pages/services/old_age/old_age_support_page_simple.dart @@ -1,16 +1,17 @@ +import 'dart:async'; + import 'package:aku_new_community/constants/saas_api.dart'; import 'package:aku_new_community/utils/network/base_model.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; -import 'package:dio/dio.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart' hide Response; import 'package:velocity_x/velocity_x.dart'; -import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/gen/assets.gen.dart'; import 'package:aku_new_community/models/bracelet/bracelet_model.dart'; import 'package:aku_new_community/pages/services/old_age/add_equipment_page.dart'; @@ -31,17 +32,35 @@ class _OldAgeSupportPageSimpleState extends State { BraceletModel? _model; DateTime? _date; + Timer? _timer; + + void _startTimer() { + _timer = Timer.periodic(Duration(seconds: 5), (timer) { + _date = DateTime.now(); + getData(); + }); + } + + void _disposeTimer() { + _timer?.cancel(); + _timer = null; + } + @override void initState() { - var cancel = BotToast.showLoading(); - getData(); - cancel(); + Future.delayed(Duration.zero, () async { + var cancel = BotToast.showLoading(); + await getData(); + cancel(); + _startTimer(); + }); super.initState(); } @override void dispose() { BotToast.closeAllLoading(); + _disposeTimer(); super.dispose(); } @@ -130,17 +149,14 @@ class _OldAgeSupportPageSimpleState extends State { } Future getData() async { - var cancel = BotToast.showLoading(); - BaseModel base = - await NetUtil().get(SAASAPI.bracelet.data, params: { - 'imei': 863204050238280, + BaseModel base = await NetUtil().get(SAASAPI.bracelet.data, params: { + 'imei': UserTool.oldAgeProvider.imei, }); if (base.data != null) { _model = BraceletModel.fromJson(base.data); _date = DateTime.now(); } setState(() {}); - cancel(); } Container bottomCard() { @@ -441,7 +457,7 @@ class _OldAgeSupportPageSimpleState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ '剩余电量'.text.size(28.sp).color(Colors.black.withOpacity(0.65)).make(), - '${_model?.remainingPower??0}' + '${_model?.remainingPower ?? 0}' .richText .withTextSpanChildren([ ' %' @@ -547,6 +563,16 @@ class _OldAgeSupportPageSimpleState extends State { ), ), ), + actions: [ + IconButton( + icon: Icon(CupertinoIcons.repeat), + iconSize: 30.w, + color: Colors.black, + onPressed: () { + Get.to(() => EquipmentListPage()); + }, + ) + ], bottomNavi: Padding( padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), child: MaterialButton( diff --git a/lib/pages/services/old_age/old_enum.dart b/lib/pages/services/old_age/old_enum.dart new file mode 100644 index 00000000..8faeb6c1 --- /dev/null +++ b/lib/pages/services/old_age/old_enum.dart @@ -0,0 +1,13 @@ + +enum BraceletBrand { + aqg(1, '爱牵挂','assets/bracelet/x5.png'); + + final int typeNum; + final String name; + final String imgPath; + + static BraceletBrand getValue(int value) => + BraceletBrand.values.firstWhere((element) => element.typeNum == value); + + const BraceletBrand(this.typeNum, this.name,this.imgPath); +} diff --git a/lib/pages/services/old_age/submit_equipment_code_page.dart b/lib/pages/services/old_age/submit_equipment_code_page.dart index e0a74f23..7347b7ce 100644 --- a/lib/pages/services/old_age/submit_equipment_code_page.dart +++ b/lib/pages/services/old_age/submit_equipment_code_page.dart @@ -1,7 +1,11 @@ +import 'package:aku_new_community/constants/saas_api.dart'; +import 'package:aku_new_community/utils/network/net_util.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:flutter/material.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:aku_new_community/gen/assets.gen.dart'; @@ -67,12 +71,25 @@ class _SubmitEquipmentCodePageState extends State { bottomNavi: Padding( padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 32.w), child: MaterialButton( - onPressed: () { + onPressed: () async { if (_editingController.text.isEmpty) { BotToast.showText(text: '设备码不能为空'); return; } - BotToast.showText(text: '请输入正确的设备码'); + var base = await NetUtil().post(SAASAPI.bracelet.add, params: { + 'type': 1, + 'deviceType': 'x5', + 'imei': _editingController.text + }); + if (base.success) { + Get.back(); + Get.back(); + if (UserTool.oldAgeProvider.imei.isEmpty) { + UserTool.oldAgeProvider.changeImei(_editingController.text); + } + } else { + BotToast.showText(text: base.msg); + } }, elevation: 0, color: Color(0xFF6395D7), diff --git a/lib/provider/old_age_provider.dart b/lib/provider/old_age_provider.dart new file mode 100644 index 00000000..dc7a9213 --- /dev/null +++ b/lib/provider/old_age_provider.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class OldAgeProvider extends ChangeNotifier { + String _imei=''; + + String get imei => _imei; + + void changeImei(String value) { + _imei = value; + notifyListeners(); + } +} diff --git a/lib/ui/manager/advice/advice_detail_page.dart b/lib/ui/manager/advice/advice_detail_page.dart index 4856d358..f81db68b 100644 --- a/lib/ui/manager/advice/advice_detail_page.dart +++ b/lib/ui/manager/advice/advice_detail_page.dart @@ -96,9 +96,6 @@ class _AdviceDetailPageState extends State { type = '您'; break; case 2: - type = '装修公司'; - break; - case 3: type = '物业'; break; } diff --git a/lib/widget/others/user_tool.dart b/lib/widget/others/user_tool.dart index bfc561af..86ee488b 100644 --- a/lib/widget/others/user_tool.dart +++ b/lib/widget/others/user_tool.dart @@ -1,4 +1,5 @@ import 'package:aku_new_community/constants/app_theme.dart'; +import 'package:aku_new_community/provider/old_age_provider.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -20,5 +21,8 @@ class UserTool { static MyAppStyle get myAppStyle => Theme.of(Get.context!).extension()!; + static OldAgeProvider get oldAgeProvider => + Provider.of(Get.context!, listen: false); + UserTool(); }