349 lines
13 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../appRouters.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/appRouteObserver.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/dateTool.dart';
import '../../../../tools/showTipView.dart';
import '../../../../tools/submitBtn.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../lockMian/lockMain/lockMain_logic.dart';
import 'remoteControlDetail_logic.dart';
import 'remoteControlDetail_state.dart';
class RemoteControlDetailPage extends StatefulWidget {
const RemoteControlDetailPage({Key? key}) : super(key: key);
@override
State<RemoteControlDetailPage> createState() => _RemoteControlDetailPageState();
}
class _RemoteControlDetailPageState extends State<RemoteControlDetailPage> with RouteAware {
final RemoteControlDetailLogic logic = Get.put(RemoteControlDetailLogic());
final RemoteControlDetailState state = Get.find<RemoteControlDetailLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '遥控详情'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
),
body: ListView(
children: <Widget>[
Obx(() => CommonItem(
leftTitel: '遥控号'.tr,
rightTitle: state.typeNumber.value,
isHaveDirection: false,
isHaveLine: true)),
Obx(() => lockDataListItem('姓名'.tr, state.typeName.value, () {
ShowTipView().showTFViewAlertDialog(state.changeNameController, '修改姓名'.tr, '修改姓名'.tr, () {
if (state.changeNameController.text.isEmpty) {
logic.showToast('请输入姓名'.tr);
return;
}
Get.back();
state.typeName.value = state.changeNameController.text;
logic.editRemoteControlData();
}, inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.deny('\n'),
LengthLimitingTextInputFormatter(50),
]);
})),
Obx(() => Visibility(
visible: state.keyType.value == 4 ||
state.keyType.value == 2 ||
state.keyType.value == 1,
child: CommonItem(
leftTitel:'有效期'.tr,
allHeight: 70.h,
rightTitle: logic.getKeyTypeShowDateTime(),
isHaveDirection: true,
isHaveLine: true,
action: () async {
if (state.keyType.value == 2 || state.keyType.value == 1) {
// 限时
final data = await Get.toNamed(
Routers.otherTypeKeyChangeDatePage,
arguments: <String, Object>{
'pushType': 2,
'fingerprintItemData':
state.fingerprintItemData.value,
});
if (data != null) {
setState(() {
state.startDate.value = data['beginTimeTimestamp'];
state.endDate.value = data['endTimeTimestamp'];
state.keyType.value = 2;
});
}
} else if (state.keyType.value == 4) {
// 循环
var data = await Get.toNamed(
Routers.otherTypeKeyChangeValidityDatePage,
arguments: <String, Object>{
'pushType': 2,
'fingerprintItemData':
state.fingerprintItemData.value,
});
if (data != null) {
setState(() {
state.startDate.value = data['starDate'];
state.endDate.value = data['endDate'];
state.starTime.value = data['starTime'];
state.endTime.value = data['endTime'];
state.weekDay.value = data['validityValue'];
});
}
}
}))),
Obx(() => Visibility(
visible: state.keyType.value == 4,
child: Obx(() => CommonItem(
leftTitel: '有效日'.tr,
rightTitle: logic.weekDayStr.join(','),
isHaveDirection: true,
isHaveLine: true,
action: () async {
var data = await Get.toNamed(
Routers.otherTypeKeyChangeValidityDatePage,
arguments: <String, Object>{
'pushType': 2,
'fingerprintItemData':
state.fingerprintItemData.value,
});
if (data != null) {
setState(() {
state.startDate.value = data['starDate'];
state.endDate.value = data['endDate'];
state.starTime.value = data['starTime'];
state.endTime.value = data['endTime'];
state.weekDay.value = data['validityValue'];
});
}
})))),
Obx(() => Visibility(
visible: state.keyType.value == 4,
child: Obx(() => CommonItem(
leftTitel: '有效时间'.tr,
rightTitle:
'${DateTool().dateToHNString(state.starTime.value)}-${DateTool().dateToHNString(state.endTime.value)}',
isHaveDirection: true,
action: () async {
var data = await Get.toNamed(
Routers.otherTypeKeyChangeValidityDatePage,
arguments: <String, Object>{
'pushType': 2,
'fingerprintItemData':
state.fingerprintItemData.value,
});
if (data != null) {
setState(() {
state.startDate.value = data['starDate'];
state.endDate.value = data['endDate'];
state.starTime.value = data['starTime'];
state.endTime.value = data['endTime'];
state.weekDay.value = data['validityValue'];
});
}
})))),
Container(height: 10.h),
Obx(() => CommonItem(
leftTitel: '添加者'.tr,
isHaveLine: true,
rightTitle: state.adder.value,
)),
Obx(() => CommonItem(
leftTitel: '添加时间'.tr,
rightTitle: DateTool()
.dateToYMDHNString(state.addTime.value.toString()),
)),
SizedBox(height: 10.h),
// Obx(() => CommonItem(
// leftTitel: TranslationLoader.lanKeys!.stressCard!.tr,
// rightTitle: '',
// isTipsImg: false,
// isHaveLine: true,
// isHaveRightWidget: true,
// rightWidget: SizedBox(
// width: 60.w, height: 50.h, child: _isStressFingerprint()))),
// Obx(() => CommonItem(
// leftTitel: '是否为管理员'.tr,
// rightTitle: '',
// isTipsImg: false,
// isHaveRightWidget: true,
// rightWidget:
// SizedBox(width: 60.w, height: 50.h, child: _isAdmin()))),
// Container(height: 10.h),
CommonItem(
leftTitel: '操作记录'.tr,
rightTitle: '',
isHaveDirection: true,
action: () {
Get.toNamed(Routers.lockOperatingRecordPage,
arguments: <String, Object?>{
'type': 6,
'id': state.fingerprintItemData.value.remoteId.toString(),
'recordName': state.fingerprintItemData.value.remoteName
});
}),
// SizedBox(height: 40.h),
// addControlsBtn(type),
SizedBox(height: 30.h),
SubmitBtn(
btnName: '删除'.tr,
isDelete: true,
borderRadius: 20.w,
margin: EdgeInsets.only(
left: 30.w, right: 30.w, top: 30.w, bottom: 30.w),
padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
onClick: () async {
final bool isNetWork =
await logic.isConnected() ?? false;
if (!isNetWork) {
return;
}
ShowTipView().showIosTipWithContentDialog('确定要删除吗?'.tr,
() async {
state.isDeletRemoteControl.value = true;
logic.senderAddICCard();
});
}),
],
),
);
}
Widget lockDataListItem(
String leftTitle, String conentStr, Function()? action) {
return GestureDetector(
onTap: action,
child: Container(
// height: 70.h,
padding:
EdgeInsets.only(left: 20.w, right: 10.w, top: 15.h, bottom: 15.h),
decoration: BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(
color: AppColors.greyLineColor, // 设置边框颜色
width: 2.0.h, // 设置边框宽度
),
)),
child: Row(
children: <Widget>[
Text(leftTitle, style: TextStyle(fontSize: 22.sp)),
SizedBox(width: 10.w),
Expanded(
child: Text(conentStr,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 22.sp,
))),
SizedBox(width: 10.w),
Image.asset(
'images/icon_right_grey.png',
width: 12.w,
height: 21.w,
)
],
),
),
);
}
//isStressFingerprint false:不是胁迫指纹 ture:胁迫指纹
// CupertinoSwitch _isStressFingerprint() {
// return CupertinoSwitch(
// activeColor: CupertinoColors.activeBlue,
// trackColor: CupertinoColors.systemGrey5,
// thumbColor: CupertinoColors.white,
// value: state.isStressCard.value,
// onChanged: (bool value) {
// setState(() {
// state.isStressCard.value = value;
// state.isDeletCard.value = false;
// logic.senderAddICCard();
// });
// },
// );
// }
// 是否为管理员
// CupertinoSwitch _isAdmin() {
// return CupertinoSwitch(
// activeColor: CupertinoColors.activeBlue,
// trackColor: CupertinoColors.systemGrey5,
// thumbColor: CupertinoColors.white,
// value: state.isAdministrator.value,
// onChanged: (bool value) {
// // state.isAdministrator.value = value;
// // state.isDeletCard.value = false;
// // logic.senderAddICCard();
// },
// );
// }
@override
void didChangeDependencies() {
super.didChangeDependencies();
/// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
/// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
}
/// 从上级界面进入 当前界面即将出现
@override
void didPush() {
super.didPush();
state.ifCurrentScreen.value = true;
}
/// 返回上一个界面 当前界面即将消失
@override
void didPop() {
super.didPop();
logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0;
}
/// 从下级返回 当前界面即将出现
@override
void didPopNext() {
super.didPopNext();
state.ifCurrentScreen.value = true;
}
/// 进入下级界面 当前界面即将消失
@override
void didPushNext() {
super.didPushNext();
logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0;
}
}