feat:修改电子钥匙循环页面 bug

This commit is contained in:
anfe 2024-05-04 18:17:22 +08:00
parent c2cb7218ee
commit 987fbe2ffa
3 changed files with 236 additions and 216 deletions

View File

@ -40,21 +40,21 @@ class SendElectronicKeyViewLogic extends BaseGetXController {
switch (type) { switch (type) {
case '0': case '0':
// //
if (state.timeLimitBeginTime.value.isEmpty) { if (state.timeLimitBeginTime.isEmpty) {
showToast("请选择开始时间".tr); showToast("请选择开始时间".tr);
return; return;
} }
if (state.timeLimitEndTime.value.isEmpty) { if (state.timeLimitEndTime.isEmpty) {
showToast("请选择结束时间".tr); showToast("请选择结束时间".tr);
return; return;
} }
typeValue = XSConstantMacro.keyTypeTime; typeValue = XSConstantMacro.keyTypeTime;
startDate = DateTool() startDate = DateTool()
.dateToTimestamp(state.timeLimitBeginTime.value, 1) .dateToTimestamp(state.timeLimitBeginTime, 1)
.toString(); .toString();
endDate = DateTool() endDate = DateTool()
.dateToTimestamp(state.timeLimitEndTime.value, 1) .dateToTimestamp(state.timeLimitEndTime, 1)
.toString(); .toString();
startTime = "0"; startTime = "0";
endTime = "0"; endTime = "0";
@ -73,20 +73,20 @@ class SendElectronicKeyViewLogic extends BaseGetXController {
break; break;
case '3': case '3':
typeValue = XSConstantMacro.keyTypeLoop; typeValue = XSConstantMacro.keyTypeLoop;
if (state.cycleBeginTime.value.isEmpty) { if (state.cycleBeginTime.isEmpty) {
showToast("请选择有效期".tr); showToast("请选择有效期".tr);
return; return;
} }
startDate = DateTool() startDate = DateTool()
.dateToTimestamp(state.cycleBeginTime.value, 1) .dateToTimestamp(state.cycleBeginTime, 1)
.toString(); .toString();
endDate = endDate =
DateTool().dateToTimestamp(state.cycleEndTime.value, 1).toString(); DateTool().dateToTimestamp(state.cycleEndTime, 1).toString();
startTime = DateTool() startTime = DateTool()
.dateToTimestamp(state.effectiveDateTime.value, 0) .dateToTimestamp(state.effectiveDateTime, 0)
.toString(); .toString();
endTime = DateTool() endTime = DateTool()
.dateToTimestamp(state.failureDateTime.value, 0) .dateToTimestamp(state.failureDateTime, 0)
.toString(); .toString();
break; break;
default: default:
@ -96,15 +96,15 @@ class SendElectronicKeyViewLogic extends BaseGetXController {
String getKeyType = typeValue.toString(); String getKeyType = typeValue.toString();
var entity = await ApiRepository.to.sendElectronicKey( var entity = await ApiRepository.to.sendElectronicKey(
createUser: state.isCreateUser.value == true ? "1" : "0", createUser: state.isCreateUser == true ? "1" : "0",
countryCode: state.countryCode.value, countryCode: state.countryCode,
usernameType: isPhoneNumber(state.emailOrPhoneController.text) == true usernameType: isPhoneNumber(state.emailOrPhoneController.text) == true
? '1' ? '1'
: '2', : '2',
endDate: int.parse(endDate), endDate: int.parse(endDate),
faceAuthentication: state.isAuthentication.value == true ? '1' : '2', faceAuthentication: state.isAuthentication == true ? '1' : '2',
isCameraEnable: '2', isCameraEnable: '2',
isRemoteUnlock: state.isRemoteUnlock.value == true ? '1' : '2', isRemoteUnlock: state.isRemoteUnlock == true ? '1' : '2',
keyNameForAdmin: state.keyNameController.text, keyNameForAdmin: state.keyNameController.text,
keyRight: '0', keyRight: '0',
keyType: getKeyType, keyType: getKeyType,
@ -118,13 +118,15 @@ class SendElectronicKeyViewLogic extends BaseGetXController {
endTime: int.parse(endTime), endTime: int.parse(endTime),
isOnlyManageSelf: 0); isOnlyManageSelf: 0);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.isSendSuccess.value = true; state.isSendSuccess = true;
resetData(); resetData();
update();
eventBus.fire(ElectronicKeyListRefreshUI()); eventBus.fire(ElectronicKeyListRefreshUI());
} else { } else {
if (entity.errorCode == 425) { if (entity.errorCode == 425) {
// //
state.isCreateUser.value = true; state.isCreateUser = true;
update();
ShowTipView().showIosTipWithContentDialog( ShowTipView().showIosTipWithContentDialog(
'${"是否发送电子钥匙给未注册账号".tr}\n${state.emailOrPhoneController.text}', () { '${"是否发送电子钥匙给未注册账号".tr}\n${state.emailOrPhoneController.text}', () {
sendElectronicKeyRequest(); sendElectronicKeyRequest();
@ -151,14 +153,15 @@ class SendElectronicKeyViewLogic extends BaseGetXController {
state.keyNameController.text = ""; state.keyNameController.text = "";
state.timeLimitBeginTime = DateTool() state.timeLimitBeginTime = DateTool()
.dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString())
.obs; // ; //
state.timeLimitEndTime = DateTool() state.timeLimitEndTime = DateTool()
.dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString())
.obs; // ; //
state.cycleBeginTime = "".obs; // state.cycleBeginTime = ""; //
state.cycleEndTime = "".obs; // state.cycleEndTime = ""; //
state.effectiveDateTime = "".obs; // state.effectiveDateTime = ""; //
state.failureDateTime = "".obs; // state.failureDateTime = ""; //
state.weekdaysList = [].obs; state.weekdaysList = [];
update();
} }
} }

View File

@ -38,8 +38,7 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
tag: widget.type, tag: widget.type,
init: SendElectronicKeyViewLogic(widget.type), init: SendElectronicKeyViewLogic(widget.type),
builder: (SendElectronicKeyViewLogic logic) { builder: (SendElectronicKeyViewLogic logic) {
return Obx(() { if (logic.state.isSendSuccess == true) {
if (logic.state.isSendSuccess.value == true) {
return sendElectronicKeySucceed(logic); return sendElectronicKeySucceed(logic);
} else { } else {
switch (widget.type) { switch (widget.type) {
@ -98,7 +97,6 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
} }
} }
}); });
});
} }
// widget // widget
@ -123,7 +121,7 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
isHaveRightWidget: true, isHaveRightWidget: true,
isHaveDirection: true, isHaveDirection: true,
rightWidget: Text( rightWidget: Text(
'${logic.state.countryName.value} +${logic.state.countryCode.value}', '${logic.state.countryName} +${logic.state.countryCode}',
textAlign: TextAlign.end, textAlign: TextAlign.end,
style: style:
TextStyle(fontSize: 22.sp, color: AppColors.darkGrayTextColor), TextStyle(fontSize: 22.sp, color: AppColors.darkGrayTextColor),
@ -133,8 +131,9 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
context, Routers.selectCountryRegionPage); context, Routers.selectCountryRegionPage);
if (result != null) { if (result != null) {
result as Map<String, dynamic>; result as Map<String, dynamic>;
logic.state.countryCode.value = result['code']; logic.state.countryCode = result['code'];
logic.state.countryName.value = result['countryName']; logic.state.countryName = result['countryName'];
logic.update();
} }
}, },
), ),
@ -153,33 +152,39 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
Widget keyTimeWidget(SendElectronicKeyViewLogic logic) { Widget keyTimeWidget(SendElectronicKeyViewLogic logic) {
return Column( return Column(
children: [ children: [
Obx(() => CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
rightTitle: logic.state.timeLimitBeginTime.value, rightTitle: logic.state.timeLimitBeginTime,
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
PDuration selectDate = PDuration.parse( PDuration selectDate = PDuration.parse(
DateTime.parse(logic.state.timeLimitBeginTime.value)); DateTime.parse(logic.state.timeLimitBeginTime));
Pickers.showDatePicker(context, Pickers.showDatePicker(context,
selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) { selectDate: selectDate,
logic.state.timeLimitBeginTime.value = mode: DateMode.YMDHM,
onConfirm: (p) {
logic.state.timeLimitBeginTime =
DateTool().getYMDHNDateString(p, 1); DateTool().getYMDHNDateString(p, 1);
logic.update();
}); });
})), }),
Obx(() => CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
rightTitle: logic.state.timeLimitEndTime.value, rightTitle: logic.state.timeLimitEndTime,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
PDuration selectDate = PDuration.parse( PDuration selectDate = PDuration.parse(
DateTime.tryParse(logic.state.timeLimitEndTime.value)); DateTime.tryParse(logic.state.timeLimitEndTime));
Pickers.showDatePicker(context, Pickers.showDatePicker(context,
selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) { selectDate: selectDate,
logic.state.timeLimitEndTime.value = mode: DateMode.YMDHM,
onConfirm: (p) {
logic.state.timeLimitEndTime =
DateTool().getYMDHNDateString(p, 1); DateTool().getYMDHNDateString(p, 1);
logic.update();
}); });
})), }),
Container(height: 10.h), Container(height: 10.h),
], ],
); );
@ -195,7 +200,8 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
isTipsImg: true, isTipsImg: true,
tipsImgAction: () { tipsImgAction: () {
ShowTipView().showSureAlertDialog( ShowTipView().showSureAlertDialog(
"人脸实名认证指的是用户在使用手机APP开锁时需要先进行本人人脸验证验证通过才能开锁。".tr); "人脸实名认证指的是用户在使用手机APP开锁时需要先进行本人人脸验证验证通过才能开锁。"
.tr);
}, },
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: SizedBox( rightWidget: SizedBox(
@ -209,30 +215,32 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
Widget keyPeriodValidityWidget(SendElectronicKeyViewLogic logic) { Widget keyPeriodValidityWidget(SendElectronicKeyViewLogic logic) {
return Column( return Column(
children: [ children: [
Obx(() => CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr,
rightTitle: rightTitle:
"${logic.state.cycleBeginTime.value}\n${logic.state.cycleEndTime.value}", "${logic.state.cycleBeginTime}\n${logic.state.cycleEndTime}",
isHaveDirection: true, isHaveDirection: true,
isHaveLine: true, isHaveLine: true,
action: () async { action: () async {
var result = var result =
await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: { await Get.toNamed(
Routers.seletKeyCyclicDatePage, arguments: {
'validityValue': logic.state.weekdaysList, 'validityValue': logic.state.weekdaysList,
'starDate': logic.state.cycleBeginTime.value, 'starDate': logic.state.cycleBeginTime,
'endDate': logic.state.cycleEndTime.value, 'endDate': logic.state.cycleEndTime,
'starTime': logic.state.effectiveDateTime.value, 'starTime': logic.state.effectiveDateTime,
'endTime': logic.state.failureDateTime.value 'endTime': logic.state.failureDateTime
}); });
if (result != null && result.isNotEmpty) { if (result != null && result.isNotEmpty) {
logic.state.weekdaysList.value = result['validityValue']; logic.state.weekdaysList = result['validityValue'];
logic.state.cycleBeginTime.value = result['starDate']; logic.state.cycleBeginTime = result['starDate'];
logic.state.cycleEndTime.value = result['endDate']; logic.state.cycleEndTime = result['endDate'];
logic.state.effectiveDateTime.value = result['starTime']; logic.state.effectiveDateTime = result['starTime'];
logic.state.failureDateTime.value = result['endTime']; logic.state.failureDateTime = result['endTime'];
logic.update();
} }
})), }),
Obx(() => Visibility( Visibility(
visible: logic.state.weekdaysList.isNotEmpty ? true : false, visible: logic.state.weekdaysList.isNotEmpty ? true : false,
child: CommonItem( child: CommonItem(
leftTitel: "有效日".tr, leftTitel: "有效日".tr,
@ -240,58 +248,66 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
isHaveDirection: true, isHaveDirection: true,
isHaveLine: true, isHaveLine: true,
action: () async { action: () async {
var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, var result = await Get.toNamed(
Routers.seletKeyCyclicDatePage,
arguments: { arguments: {
'validityValue': logic.state.weekdaysList, 'validityValue': logic.state.weekdaysList,
'starDate': logic.state.cycleBeginTime.value, 'starDate': logic.state.cycleBeginTime,
'endDate': logic.state.cycleEndTime.value, 'endDate': logic.state.cycleEndTime,
'starTime': logic.state.effectiveDateTime.value, 'starTime': logic.state.effectiveDateTime,
'endTime': logic.state.failureDateTime.value 'endTime': logic.state.failureDateTime
}); });
if (result != null && result.isNotEmpty) { if (result != null && result.isNotEmpty) {
logic.state.weekdaysList.value = result['validityValue']; logic.state.weekdaysList =
logic.state.cycleBeginTime.value = result['starDate']; result['validityValue'];
logic.state.cycleEndTime.value = result['endDate']; logic.state.cycleBeginTime = result['starDate'];
logic.state.effectiveDateTime.value = result['starTime']; logic.state.cycleEndTime = result['endDate'];
logic.state.failureDateTime.value = result['endTime']; logic.state.effectiveDateTime =
result['starTime'];
logic.state.failureDateTime = result['endTime'];
logic.update();
} }
}))), })),
Obx(() => Visibility( Visibility(
visible: logic.state.effectiveDateTime.value.isNotEmpty, visible: logic.state.effectiveDateTime.isNotEmpty,
child: CommonItem( child: CommonItem(
leftTitel: "有效时间".tr, leftTitel: "有效时间".tr,
rightTitle: rightTitle:
"${logic.state.effectiveDateTime.value}-${logic.state.failureDateTime.value}", "${logic.state.effectiveDateTime}-${logic.state
.failureDateTime}",
isHaveDirection: true, isHaveDirection: true,
action: () async { action: () async {
var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, var result = await Get.toNamed(
Routers.seletKeyCyclicDatePage,
arguments: { arguments: {
'validityValue': logic.state.weekdaysList, 'validityValue': logic.state.weekdaysList,
'starDate': logic.state.cycleBeginTime.value, 'starDate': logic.state.cycleBeginTime,
'endDate': logic.state.cycleEndTime.value, 'endDate': logic.state.cycleEndTime,
'starTime': logic.state.effectiveDateTime.value, 'starTime': logic.state.effectiveDateTime,
'endTime': logic.state.failureDateTime.value 'endTime': logic.state.failureDateTime
}); });
if (result != null && result.isNotEmpty) { if (result != null && result.isNotEmpty) {
logic.state.weekdaysList.value = result['validityValue']; logic.state.weekdaysList =
logic.state.cycleBeginTime.value = result['starDate']; result['validityValue'];
logic.state.cycleEndTime.value = result['endDate']; logic.state.cycleBeginTime = result['starDate'];
logic.state.effectiveDateTime.value = result['starTime']; logic.state.cycleEndTime = result['endDate'];
logic.state.failureDateTime.value = result['endTime']; logic.state.effectiveDateTime =
result['starTime'];
logic.state.failureDateTime = result['endTime'];
logic.update();
} }
}))), })),
], ],
); );
} }
Widget keyBottomWidget( Widget keyBottomWidget(String sendElectronicKeyTips,
String sendElectronicKeyTips, SendElectronicKeyViewLogic logic) { SendElectronicKeyViewLogic logic) {
return Column( return Column(
children: [ children: [
Container( Container(
padding: EdgeInsets.all(20.w), padding: EdgeInsets.all(20.w),
child: Row( child: Row(
// crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
@ -316,7 +332,6 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
}), }),
Container( Container(
padding: EdgeInsets.only(right: 30.w), padding: EdgeInsets.only(right: 30.w),
// color: Colors.red,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
@ -384,8 +399,9 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
SubmitBtn( SubmitBtn(
btnName: '完成'.tr, btnName: '完成'.tr,
onClick: () { onClick: () {
logic.state.isSendSuccess.value = false; logic.state.isSendSuccess = false;
logic.resetData(); logic.resetData();
logic.update();
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,
@ -519,22 +535,22 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
} }
//isRemote true: false: //isRemote true: false:
CupertinoSwitch _remoteSwitch( CupertinoSwitch _remoteSwitch(bool isRemote,
bool isRemote, SendElectronicKeyViewLogic logic) { SendElectronicKeyViewLogic logic) {
return CupertinoSwitch( return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue, activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5, trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white, thumbColor: CupertinoColors.white,
value: isRemote value: isRemote
? logic.state.isRemoteUnlock.value ? logic.state.isRemoteUnlock
: logic.state.isAuthentication.value, : logic.state.isAuthentication,
onChanged: (value) { onChanged: (value) {
if (isRemote) { if (isRemote) {
logic.state.isRemoteUnlock.value = !logic.state.isRemoteUnlock.value; logic.state.isRemoteUnlock = !logic.state.isRemoteUnlock;
} else { } else {
logic.state.isAuthentication.value = logic.state.isAuthentication =
!logic.state.isAuthentication.value; !logic.state.isAuthentication;
if (logic.state.isAuthentication.value) { if (logic.state.isAuthentication) {
ShowTipView().showBuyTipWithContentAlert( ShowTipView().showBuyTipWithContentAlert(
titleStr: '实名认证为付费功能,请购买后再使用'.tr, titleStr: '实名认证为付费功能,请购买后再使用'.tr,
sureClick: () { sureClick: () {
@ -594,8 +610,8 @@ class _SendElectronicKeyViewState extends State<SendElectronicKeyView>
return widgetList; return widgetList;
} }
GestureDetector buildCenter3( GestureDetector buildCenter3(String imageName, String titleStr,
String imageName, String titleStr, int itemIndex) { int itemIndex) {
return GestureDetector( return GestureDetector(
child: Container( child: Container(
width: 120.w, width: 120.w,

View File

@ -3,34 +3,35 @@ import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/dateTool.dart';
class SendElectronicKeyViewState { class SendElectronicKeyViewState {
TextEditingController emailOrPhoneController = TextEditingController(); /// TextEditingController emailOrPhoneController =
TextEditingController(); ///
TextEditingController keyNameController = TextEditingController(); // TextEditingController keyNameController = TextEditingController(); //
final FlutterContactPicker contactPicker = FlutterContactPicker(); final FlutterContactPicker contactPicker = FlutterContactPicker();
late Contact contact; late Contact contact;
final isRemoteUnlock = false.obs; // bool isRemoteUnlock = false; //
final isAuthentication = false.obs; // bool isAuthentication = false; //
var timeLimitBeginTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// var timeLimitBeginTime = DateTool().dateToYMDHNString(
var timeLimitEndTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// DateTime.now().millisecondsSinceEpoch.toString()); //
var cycleBeginTime = "".obs;// var timeLimitEndTime = DateTool().dateToYMDHNString(
var cycleEndTime = "".obs;// DateTime.now().millisecondsSinceEpoch.toString()); //
var effectiveDateTime = "".obs;// var cycleBeginTime = ""; //
var failureDateTime = "".obs;// var cycleEndTime = ""; //
var weekdaysList = [].obs; var effectiveDateTime = ""; //
var failureDateTime = ""; //
var weekdaysList = [];
var isSendSuccess = false.obs; var isSendSuccess = false;
var countryName = '中国'.tr.obs; var countryName = '中国'.tr;
var countryCode = '86'.obs; var countryCode = '86';
var isCreateUser = false.obs; //1 0 var isCreateUser = false; //1 0
var isDemoMode = false; var isDemoMode = false;
final timeLimitTips = '接收者在有效期内可以不限次数使用'; // final timeLimitTips = '接收者在有效期内可以不限次数使用'; //
final permanentTips = '接收者可以使用此App开关锁'; // final permanentTips = '接收者可以使用此App开关锁'; //
final onceLimitTips = '单次钥匙有效期为1小时只能使用一次'; // final onceLimitTips = '单次钥匙有效期为1小时只能使用一次'; //
final cycleLimitTips = '接收者可以在有效期内的固定时间段里,不限次数使用'; // final cycleLimitTips = '接收者可以在有效期内的固定时间段里,不限次数使用'; //
} }