import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/electronicKeyDetail/electronicKeyDetail_logic.dart'; import '../../../../../appRouters.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../common/XSConstantMacro/XSConstantMacro.dart'; import '../../../../../tools/commonDataManage.dart'; import '../../../../../tools/commonItem.dart'; import '../../../../../tools/dateTool.dart'; import '../../../../../tools/showTFView.dart'; import '../../../../../tools/submitBtn.dart'; import '../../../../../tools/titleAppBar.dart'; enum ShowAlertEnum { name, realName, idCardNumber } class ElectronicKeyDetailPage extends StatefulWidget { const ElectronicKeyDetailPage({Key? key}) : super(key: key); @override State createState() => _ElectronicKeyDetailPageState(); } class _ElectronicKeyDetailPageState extends State { final logic = Get.put(ElectronicKeyDetailLogic()); final state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: '钥匙详情'.tr, haveBack: true, actionsList: (state.keyType.value != 3) ? [ IconButton( icon: Image.asset( 'images/icon_bar_more.png', height: 30.h, width: 10.w, ), onPressed: () { logic.openModalBottomSheet(context); }, ), ] : null, backgroundColor: AppColors.mainColor), body: ListView( children: [ Obx(() => CommonItem( leftTitel: '姓名'.tr, rightTitle: state.keyName.value, isHaveDirection: true, isHaveLine: true, action: () { showCupertinoAlertDialog( tipsTitle: "修改姓名".tr, alertEnum: ShowAlertEnum.name); })), Obx(() => Visibility( visible: state.isRealNameAuth.value, child: CommonItem( leftTitel: '真实姓名'.tr, rightTitle: state.getRealName.value, isHaveDirection: true, isHaveLine: true, action: () { showCupertinoAlertDialog( tipsTitle: "修改真实姓名".tr, alertEnum: ShowAlertEnum.realName); }))), Obx(() => Visibility( visible: state.isRealNameAuth.value, child: CommonItem( leftTitel: '身份证'.tr, rightTitle: state.getIDCardNumber.value, isHaveDirection: true, isHaveLine: true, action: () { showCupertinoAlertDialog( tipsTitle: "修改身份证号".tr, alertEnum: ShowAlertEnum.idCardNumber); }))), Obx(() => CommonItem( leftTitel: '有效期'.tr, allHeight: 70.h, // rightTitle:"2023.09.19 11:27\n2023.09.25 11:27", rightTitle: logic.getKeyTypeShowDateTime(), isHaveDirection: state.itemData.value.keyStatus! == XSConstantMacro.keyStatusExpired ? false : state.keyType.value == 3 ? false : true, isHaveLine: true, action: state.itemData.value.keyStatus! == XSConstantMacro.keyStatusExpired ? null : () async { if(state.itemData.value.keyStatus == XSConstantMacro.keyStatusFrozen){ logic.showToast("冻结状态下不允许修改钥匙权限".tr); return; } if (state.keyType.value == 2 || state.keyType.value == 1) { // 限时/永久 var data = await Get.toNamed( Routers.electronicKeyDetailChangeDate, arguments: { "pushType": 0, "itemData": state.itemData.value, }); if (data != null) { setState(() { state.starDate.value = data["beginTimeTimestamp"].toString(); state.endDate.value = data["endTimeTimestamp"].toString(); state.keyType.value = 2; }); } } else if (state.keyType.value == 4) { // 循环 var data = await Get.toNamed( Routers.electronicKeyPeriodValidityPage, arguments: { "pushType": 0, "itemData": state.itemData.value, }); if (data != null) { setState(() { state.starDate.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 ? true : false, child: Obx(() => CommonItem( leftTitel: '有效日'.tr, rightTitle: state.weekDay.value.join(','), isHaveDirection: true, isHaveLine: true, action: () async { if(state.itemData.value.keyStatus == XSConstantMacro.keyStatusFrozen){ logic.showToast("冻结状态下不允许修改钥匙权限".tr); return; } var data = await Get.toNamed( Routers.electronicKeyPeriodValidityPage, arguments: { "pushType": 0, "itemData": state.itemData.value, }); if (data != null) { setState(() { state.starDate.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 ? true : false, child: Obx(() => CommonItem( leftTitel: "有效时间".tr, rightTitle: "${DateTool().dateToHNString(state.starTime.value)}-${DateTool().dateToHNString(state.endTime.value)}", isHaveDirection: true, action: () async { if(state.itemData.value.keyStatus == XSConstantMacro.keyStatusFrozen){ logic.showToast("冻结状态下不允许修改钥匙权限".tr); return; } var data = await Get.toNamed( Routers.electronicKeyPeriodValidityPage, arguments: { "pushType": 0, "itemData": state.itemData.value, }); if (data != null) { setState(() { state.starDate.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), CommonItem( leftTitel: "接收者".tr, rightTitle: state.itemData.value.username ?? ""), const SizedBox(height: 1), CommonItem( leftTitel: "发送人".tr, rightTitle: state.itemData.value.senderUsername ?? ""), const SizedBox(height: 1), CommonItem( leftTitel: '发送时间'.tr, rightTitle: DateTool() .dateToYMDHNString(state.itemData.value.sendDate.toString())), Container(height: 10.h), Visibility( visible: state.itemData.value.keyRight == 1 ? true : false, child: CommonItem( leftTitel: "仅管理自己创建的用户".tr, rightTitle: "", isHaveRightWidget: true, isHaveLine: true, rightWidget: SizedBox( width: 60.w, child: _onlyManageYouCreatesUserSwitch())), ), Obx( () => Visibility( // (state.keyInfo.value.lockSetting!.remoteUnlock == 1 ? true : false // visible: CommonDataManage() // .currentKeyInfo // .lockSetting! // .remoteUnlock == // 1 // ? true // : false, visible: (CommonDataManage().currentKeyInfo.lockSetting!.remoteUnlock == 1 && state.itemData.value.keyRight != 1) ? true : false, child: CommonItem( leftTitel: "远程开锁".tr, rightTitle: "", isHaveRightWidget: true, isHaveLine: true, rightWidget: SizedBox( width: 60.w, child: _remoteUnlockingSwitch()))), ), Obx(() => CommonItem( leftTitel: '实名认证'.tr, rightTitle: "", isHaveRightWidget: true, rightWidget: SizedBox(width: 60.w, child: _realNameAuthSwitch()))), Container(height: 10.h), CommonItem( leftTitel: '操作记录'.tr, rightTitle: "", isHaveDirection: true, action: () { Get.toNamed(Routers.lockOperatingRecordPage, arguments: { 'type': 5, 'id': state.itemData.value.keyId.toString(), 'recordName': state.itemData.value.keyName }); }), Container(height: 40.h), Container( margin: EdgeInsets.only(left: 20.w, right: 20.w), child: SubmitBtn( btnName: '删除'.tr, borderRadius: 20.w, isDelete: true, 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: () { logic.deletKeyLogic(); }), ), ], ), ); } CupertinoSwitch _realNameAuthSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isRealNameAuth.value, onChanged: (value) { if (!state.isRealNameAuth.value) { logic.checkRealNameStatus(1); } else { logic.checkRealNameStatus(2); } }, ); } CupertinoSwitch _remoteUnlockingSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isRemoteUnlock.value, onChanged: (value) { state.isRemoteUnlock.value = !state.isRemoteUnlock.value; logic.updateKeyDateRequest(2); }, ); } CupertinoSwitch _onlyManageYouCreatesUserSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.onlyManageYouCreatesUser.value, onChanged: (value) { setState(() { state.onlyManageYouCreatesUser.value = !state.onlyManageYouCreatesUser.value; logic.updateKeyDateRequest(1); }); }, ); } void showCupertinoAlertDialog( {required String tipsTitle, required ShowAlertEnum alertEnum}) { showDialog( context: context, builder: (BuildContext context) { return ShowTFView( title: tipsTitle, tipTitle: "请输入".tr, controller: logic.getCurrentController(alertEnum), inputFormatters: [ FilteringTextInputFormatter.deny('\n'), LengthLimitingTextInputFormatter(50), ], sureClick: () { if (alertEnum == ShowAlertEnum.name) { logic.modifyKeyNameRequest(); } else { Get.back(); logic.updateRealNameInfoRequest(alertEnum); } }, cancelClick: () { Get.back(); }, ); }, ); } }