2023-10-25 16:18:27 +08:00

686 lines
26 KiB
Dart

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.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/eventBusEventManage.dart';
import '../../../../tools/showIosTipView.dart';
import '../../../../tools/showTFView.dart';
import '../../../../tools/submitBtn.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../tools/toast.dart';
import '../../../../translations/trans_lib.dart';
import 'lockSet_logic.dart';
class LockSetPage extends StatefulWidget {
const LockSetPage({Key? key}) : super(key: key);
@override
State<LockSetPage> createState() => _LockSetPageState();
}
class _LockSetPageState extends State<LockSetPage> with RouteAware {
final logic = Get.put(LockSetLogic());
final state = Get.find<LockSetLogic>().state;
StreamSubscription? _passCurrentLockInformationEvent;
@override
void initState() {
// TODO: implement initState
super.initState();
logic.initLoadDataAction(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.set!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
children: [
Expanded(
child: ListView(
children: [
// 基本信息
CommonItem(
leftTitel:
TranslationLoader.lanKeys!.basicInformation!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.basicInformationPage, arguments: {
'keyInfo': state.getKeyInfosData.value
});
}),
SizedBox(
height: 10.h,
),
// 门磁
Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.doorMagnetic!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.doorMagneticPage);
// Toast.show(msg: "功能暂未开放");
})),
// 无线键盘
Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.wirelessKeyboard!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.wirelessKeyboardPage);
// Toast.show(msg: "功能暂未开放");
})),
Visibility(
visible: true,
child: CommonItem(
leftTitel: '照明',
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
})),
Visibility(
visible: true,
child: CommonItem(
leftTitel: '开门器',
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
})),
SizedBox(height: 10.h),
// 自动闭锁
Obx(() => Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.automaticBlocking!.tr,
rightTitle: state
.getKeyInfosData.value.autoLockTime! >
-1
? "${state.getKeyInfosData.value.autoLockTime!.toString()}s"
: TranslationLoader.lanKeys!.closed!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.automaticBlockingPage,
arguments: state.getKeyInfosData.value);
}))),
// 锁声音
Obx(() {
var titleStr = "";
if (state.getKeyInfosData.value.lockSound == 1) {
switch (state.getKeyInfosData.value.volume) {
case 1:
titleStr = TranslationLoader.lanKeys!.low!.tr;
break;
case 2:
titleStr = TranslationLoader.lanKeys!.lower!.tr;
break;
case 3:
titleStr = TranslationLoader.lanKeys!.medium!.tr;
break;
case 4:
titleStr = TranslationLoader.lanKeys!.high!.tr;
break;
case 5:
titleStr = TranslationLoader.lanKeys!.higher!.tr;
break;
}
} else {
titleStr = TranslationLoader.lanKeys!.closed!.tr;
}
return Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.lockSound!.tr,
rightTitle: titleStr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.lockSoundSetPage,
arguments: state.getKeyInfosData.value);
}));
}),
// 防撬报警
Obx(() => Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.burglarAlarm!.tr,
rightTitle:
state.getKeyInfosData.value.tamperAlert == 1
? TranslationLoader.lanKeys!.opened!.tr
: TranslationLoader.lanKeys!.closed!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.burglarAlarmPage,
arguments: state.getKeyInfosData.value);
}))),
SizedBox(height: 10.h),
// 常开模式
Obx(() => Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.normallyOpenMode!.tr,
rightTitle:
state.getKeyInfosData.value.passageMode == 1
? TranslationLoader.lanKeys!.opened!.tr
: TranslationLoader.lanKeys!.closed!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.normallyOpenModePage,
arguments: state.getKeyInfosData.value);
}))),
// 远程开锁
Obx(() => Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.remoteUnlocking!.tr,
rightTitle:
state.getKeyInfosData.value.remoteEnable == 1
? TranslationLoader.lanKeys!.opened!.tr
: TranslationLoader.lanKeys!.closed!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.remoteUnlockingPage,
arguments: state.getKeyInfosData.value);
}))),
// 重置键
Obx(() => Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.resetButton!.tr,
rightTitle:
state.getKeyInfosData.value.resetButton == 1
? TranslationLoader.lanKeys!.opened!.tr
: TranslationLoader.lanKeys!.closed!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.resetButtonPage,
arguments: state.getKeyInfosData.value);
}))),
SizedBox(height: 10.h),
//---田总新增展示
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '面容开锁',
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '自动亮屏',
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '逗留警告',
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '异常警告',
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '感应距离',
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
})),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '开门方向设置',
rightTitle: "",
isHaveDirection: true,
isHaveLine: true,
action: () {
Toast.show(msg: "功能暂未开放");
})),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: '电机功率设置',
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
})),
// ),
SizedBox(height: 10.h),
//-----新增至此
Obx(() {
var title = "";
if (state.getKeyInfosData.value.roomStatus == 1) {
title = TranslationLoader.lanKeys!.checkedIn!.tr;
} else if (state.getKeyInfosData.value.roomStatus == 2) {
title = TranslationLoader.lanKeys!.leisure!.tr;
}
return Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.markedHouseState!.tr,
rightTitle: title,
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.markedHouseStatePage,
arguments: state.getKeyInfosData.value);
}));
}),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.checkingIn!.tr,
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _openCheckInSwitch()))),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.unlockReminder!.tr,
rightTitle: "",
isHaveLine: false,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, child: _lockRemindSwitch()))),
// ),
SizedBox(height: 10.h),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader
.lanKeys!.wifiDistributionNetwork!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.configuringWifiPage);
})),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.lockTime!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.lockTimePage,
arguments: state.getKeyInfosData.value);
})),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.diagnose!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.diagnosePage,
arguments: state.getKeyInfosData.value);
})),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.uploadData!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.uploadDataPage);
})),
// ),
// Obx(() =>
// Visibility(
// visible: true,
// child: CommonItem(
// leftTitel: TranslationLoader
// .lanKeys!.importOtherLockData!.tr,
// rightTitle: "",
// isHaveLine: true,
// isHaveDirection: true,
// action: () {
// Get.toNamed(Routers.importOtherLockDataPage);
// })),
// ),
// Obx(() =>
Visibility(
visible: true,
child: CommonItem(
leftTitel:
TranslationLoader.lanKeys!.lockEscalation!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.lockEscalationPage);
})),
// ),
SizedBox(height: 30.h),
Container(
padding:
EdgeInsets.only(left: 20.w, right: 20.w, bottom: 30.h),
child: SubmitBtn(
btnName: TranslationLoader.lanKeys!.delete!.tr,
isDelete: true,
onClick: () {
// logic.deletUserAction();
// logic.deletLockInfoData();
showDeletAlertDialog(context);
// showDeletPasswordAlertDialog(context);
}),
),
],
),
),
],
));
}
CupertinoSwitch _openCheckInSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: (state.getKeyInfosData.value.isAttendance == 1) ? true : false,
onChanged: (value) {
setState(() {
int isOnStr;
if (value == true) {
isOnStr = 1;
} else {
isOnStr = 2;
}
logic.openCheckingInData((checkingInInfoDataEntity) {
if (checkingInInfoDataEntity.data!.companyId == 0) {
showCupertinoAlertDialog(context);
} else {
logic.setLockSetGeneralSetting(isOnStr.toString());
}
});
});
},
);
}
CupertinoSwitch _lockRemindSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: state.isLockPickingReminder.value == 1 ? true : false,
onChanged: (value) {
setState(() {
state.isLockPickingReminder.value =
state.isLockPickingReminder.value == 1 ? 2 : 1;
logic.setLockPickingReminder();
});
},
);
}
CupertinoSwitch _otherUnHaveDoneSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: false,
onChanged: (value) {
Toast.show(msg: "功能暂未开放");
},
);
}
//确认弹窗
void showCupertinoAlertDialog(widgetContext) {
showCupertinoDialog(
context: widgetContext,
builder: (context) {
return CupertinoAlertDialog(
title: const Text("提示"),
content: const Text('创建公司号,考勤功能才能使用'),
actions: [
CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.cancel!.tr),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.sure!.tr),
onPressed: () {
Navigator.pop(context);
Get.toNamed(Routers.checkInCreatCompanyPage,
arguments: state.getKeyInfosData.value);
},
),
],
);
},
);
}
void showDeletAlertDialog(
BuildContext context,
) {
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return ShowIosTipView(
// title: "提示",
// tipTitle: "删除锁后,所有信息都会一起删除,确定删除锁吗?",
// sureClick: () {
// Navigator.pop(context);
// showDeletPasswordAlertDialog(context);
// },
// cancelClick: () {
// Navigator.pop(context);
// },
// );
// },
// );
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text("提示"),
content: const Text('删除锁后,所有信息都会一起删除,确定删除锁吗?'),
actions: [
CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.cancel!.tr),
onPressed: () {
Navigator.pop(context);
},
),
CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.sure!.tr),
onPressed: () {
Navigator.pop(context);
showDeletPasswordAlertDialog(context);
},
),
],
);
},
);
}
// void showCupertinoAlertDialog(
// BuildContext context,
// ) {
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return ShowIosTipView(
// title: "提示",
// tipTitle: "创建公司号,考勤功能才能使用",
// sureClick: () {
// //
// Navigator.pop(context);
// Get.toNamed(Routers.checkInCreatCompanyPage,
// arguments: state.getKeyInfosData.value);
// },
// cancelClick: () {
// Navigator.pop(context);
// },
// );
// },
// );
// }
void showDeletPasswordAlertDialog(
BuildContext context,
) {
showDialog(
context: context,
builder: (BuildContext context) {
return ShowTFView(
title: "请输入登录密码",
tipTitle: "",
controller: state.passwordTF,
sureClick: () {
//发送删除锁请求
if (state.passwordTF.text.isEmpty) {
Toast.show(msg: "请输入登录密码");
return;
}
logic.checkLoginPassword((){
Navigator.pop(context);
});
},
cancelClick: () {
Navigator.pop(context);
},
);
},
);
}
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
/// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
// TODO: implement dispose
/// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
}
/// 界面从上一个界面进入 当前界面即将出现
@override
void didPush() {
print("lockSet===didPush");
}
/// 界面返回上一个界面 当前界面即将消失
@override
void didPop() {
print("lockSet===didPop");
}
/// 当前界面从下一级返回 当前界面即将出现
@override
void didPopNext() {
print("lockSet===didPopNext");
}
/// 当前界面进入下一个界面 当前界面即将消失
@override
void didPushNext() {
print("lockSet===didPushNext");
}
}