338 lines
12 KiB
Dart
Executable File
338 lines
12 KiB
Dart
Executable File
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_logic.dart';
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_state.dart';
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart';
|
|
import 'package:star_lock/main/lockMian/lockMain/lockMain_logic.dart';
|
|
import 'package:star_lock/tools/noData.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
import '../../../../appRouters.dart';
|
|
import '../../../../app_settings/app_colors.dart';
|
|
import '../../../../tools/EasyRefreshTool.dart';
|
|
import '../../../../tools/customNetworkImage.dart';
|
|
import '../../../../tools/keySearchWidget.dart';
|
|
import '../../../../tools/showTipView.dart';
|
|
import '../../../../tools/submitBtn.dart';
|
|
import '../../../../tools/titleAppBar.dart';
|
|
|
|
class ElectronicKeyListPage extends StatefulWidget {
|
|
const ElectronicKeyListPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<ElectronicKeyListPage> createState() => _ElectronicKeyListPageState();
|
|
}
|
|
|
|
class _ElectronicKeyListPageState extends State<ElectronicKeyListPage> {
|
|
final ElectronicKeyListLogic logic = Get.put(ElectronicKeyListLogic());
|
|
final ElectronicKeyListState state = Get.find<ElectronicKeyListLogic>().state;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
mockRequest();
|
|
}
|
|
|
|
Future<void> mockRequest() async {
|
|
// 获取是否是演示模式 演示模式不获取接口
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
logic.mockNetworkDataRequest().then((ElectronicKeyListEntity value) {
|
|
setState(() {});
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: TitleAppBar(
|
|
barTitle: '电子钥匙'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: <Widget>[
|
|
TextButton(
|
|
child: Text(
|
|
'重置'.tr,
|
|
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
|
),
|
|
onPressed: () async {
|
|
// 获取是否是演示模式 演示模式不获取接口
|
|
final bool? isDemoMode =
|
|
await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
final bool isNetWork = await logic.isConnected() ?? false;
|
|
if (!isNetWork) {
|
|
return;
|
|
}
|
|
ShowTipView().showIosTipWithContentDialog(
|
|
'该锁的电子钥匙都将被删除'.tr, logic.resetElectronicKeyListRequest);
|
|
} else {
|
|
logic.showToast('演示模式'.tr);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: EasyRefreshTool(
|
|
onRefresh: () {
|
|
logic.pageNo = 1;
|
|
mockRequest();
|
|
},
|
|
onLoad: () {
|
|
mockRequest();
|
|
},
|
|
child: Column(
|
|
children: <Widget>[
|
|
// _searchWidget(),
|
|
KeySearchWidget(
|
|
editingController: state.searchController,
|
|
onSubmittedAction: () {
|
|
logic.pageNo = 1;
|
|
mockRequest();
|
|
},
|
|
),
|
|
SizedBox(
|
|
height: 20.h,
|
|
),
|
|
Expanded(child: _buildMainUI()),
|
|
SizedBox(
|
|
height: 20.h,
|
|
),
|
|
AddBottomWhiteBtn(
|
|
btnName: '发送钥匙'.tr,
|
|
onClick: () {
|
|
Navigator.pushNamed(context, Routers.sendElectronicKeyPage)
|
|
.then((Object? val) {
|
|
if (val != null) {
|
|
logic.pageNo = 1;
|
|
mockRequest();
|
|
}
|
|
});
|
|
},
|
|
),
|
|
SizedBox(
|
|
height: 44.h,
|
|
)
|
|
],
|
|
),
|
|
));
|
|
}
|
|
|
|
Widget _buildMainUI() {
|
|
return Obx(() => state.itemDataList.value.isEmpty
|
|
? NoData(
|
|
noDataHeight: 1.sh -
|
|
ScreenUtil().statusBarHeight -
|
|
ScreenUtil().bottomBarHeight -
|
|
190.h -
|
|
64.h)
|
|
: SlidableAutoCloseBehavior(
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemCount: state.itemDataList.value.length,
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final ElectronicKeyListItem indexEntity =
|
|
state.itemDataList.value[index];
|
|
String useDateStr = ''; //使用期限
|
|
String keyStatus = ''; //钥匙状态
|
|
|
|
//使用期限
|
|
useDateStr = getUseDateStr(indexEntity);
|
|
|
|
//钥匙状态
|
|
keyStatus =
|
|
XSConstantMacro.getKeyStatusStr(indexEntity.keyStatus!);
|
|
|
|
//是否为管理钥匙
|
|
bool isAdminKey = false;
|
|
if (indexEntity.keyRight == 1) {
|
|
isAdminKey = true;
|
|
} else {
|
|
isAdminKey = false;
|
|
}
|
|
|
|
return Slidable(
|
|
key: ValueKey(indexEntity.keyId),
|
|
endActionPane: ActionPane(
|
|
extentRatio: 0.2,
|
|
motion: const ScrollMotion(),
|
|
children: <Widget>[
|
|
SlidableAction(
|
|
onPressed: (BuildContext context) {
|
|
logic.deletKeyLogic(indexEntity);
|
|
},
|
|
backgroundColor: Colors.red,
|
|
foregroundColor: Colors.white,
|
|
label: '删除'.tr,
|
|
padding: EdgeInsets.only(left: 5.w, right: 5.w),
|
|
),
|
|
],
|
|
),
|
|
child: _electronicKeyItem(
|
|
indexEntity.headUrl!,
|
|
indexEntity.keyName!,
|
|
useDateStr,
|
|
keyStatus,
|
|
isAdminKey,
|
|
indexEntity.remoteEnable == 1, () {
|
|
Navigator.pushNamed(
|
|
context, Routers.electronicKeyDetailPage,
|
|
arguments: <String, ElectronicKeyListItem>{
|
|
'itemData': indexEntity,
|
|
}).then((Object? val) {
|
|
if (val == 'deletScuess') {
|
|
state.itemDataList.removeWhere(
|
|
(ElectronicKeyListItem item) =>
|
|
item.keyId == indexEntity.keyId!);
|
|
setState(() {});
|
|
} else if (val != null) {
|
|
logic
|
|
.refreshIndividualKeys(
|
|
lockId: indexEntity.lockId!,
|
|
keyId: indexEntity.keyId!)
|
|
.then((dynamic value) => setState(() {}));
|
|
}
|
|
});
|
|
}),
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return const Divider(
|
|
height: 1,
|
|
color: AppColors.greyLineColor,
|
|
);
|
|
},
|
|
),
|
|
));
|
|
}
|
|
|
|
//使用期限
|
|
String getUseDateStr(ElectronicKeyListItem indexEntity) {
|
|
String useDateStr = '';
|
|
final DateTime sendDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.sendDate!);
|
|
if (indexEntity.keyType == XSConstantMacro.keyTypeTime) {
|
|
//限期
|
|
final DateTime startDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.startDate!);
|
|
final DateTime endDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.endDate!);
|
|
useDateStr =
|
|
'${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}';
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLong) {
|
|
//永久
|
|
useDateStr =
|
|
'${sendDateStr.toLocal().toString().substring(0, 16)} ${"永久".tr}';
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeOnce) {
|
|
//单次
|
|
useDateStr = '单次'.tr;
|
|
useDateStr =
|
|
'${sendDateStr.toLocal().toString().substring(0, 16)} ${"单次".tr}';
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLoop) {
|
|
//循环
|
|
useDateStr = '循环'.tr;
|
|
}
|
|
|
|
return useDateStr;
|
|
}
|
|
|
|
Widget _electronicKeyItem(
|
|
String avatarURL,
|
|
String receiveUser,
|
|
String useDate,
|
|
String keyStatus,
|
|
bool isAdminKey,
|
|
bool isRemteUnlocking,
|
|
Function() action) {
|
|
return GestureDetector(
|
|
onTap: action,
|
|
child: Container(
|
|
color: Colors.white,
|
|
padding: EdgeInsets.only(top: 15.h, bottom: 15.h),
|
|
child: Row(
|
|
children: <Widget>[
|
|
SizedBox(width: 20.w),
|
|
SizedBox(
|
|
width: 60.w,
|
|
height: 60.w,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(30.w),
|
|
child: CustomNetworkImage(
|
|
url: avatarURL,
|
|
defaultUrl: 'images/controls_user.png',
|
|
width: 60.w,
|
|
height: 60.h,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 20.w),
|
|
SizedBox(
|
|
width: 1.sw - 20.w - 60.w - 20.w - 20.w,
|
|
child: Column(
|
|
children: <Widget>[
|
|
Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Text(receiveUser,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 24.sp, color: AppColors.blackColor)),
|
|
),
|
|
if (isRemteUnlocking) SizedBox(width: 5.w),
|
|
if (isRemteUnlocking)
|
|
Image.asset(
|
|
'images/icon_electronicKey_remteUnlocking.png',
|
|
width: 24.w,
|
|
height: 20.w,
|
|
),
|
|
if (isRemteUnlocking) SizedBox(width: 5.w),
|
|
if (isAdminKey)
|
|
Image.asset(
|
|
'images/icon_electronicKey_admin.png',
|
|
width: 24.w,
|
|
height: 20.w,
|
|
),
|
|
// Expanded(child: SizedBox(width: 20.w,)),
|
|
SizedBox(width: 10.w),
|
|
// const Spacer(),
|
|
Text(
|
|
keyStatus,
|
|
textAlign: TextAlign.end,
|
|
style: TextStyle(fontSize: 18.sp, color: Colors.red),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 10.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
useDate,
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
color: AppColors.placeholderTextColor),
|
|
),
|
|
],
|
|
),
|
|
// SizedBox(width: 20.h),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 20.w),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|