377 lines
12 KiB
Dart
Executable File
377 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:get/get.dart';
|
|
import 'package:star_lock/app_settings/app_colors.dart';
|
|
import 'package:star_lock/tools/pickers/pickers.dart';
|
|
import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart';
|
|
import 'package:star_lock/tools/pickers/time_picker/model/pduration.dart';
|
|
|
|
import '../../../../../../tools/commonItem.dart';
|
|
import '../../../../../../tools/submitBtn.dart';
|
|
import '../../../../../appRouters.dart';
|
|
import '../../../../../tools/dateTool.dart';
|
|
import '../../../../../tools/storage.dart';
|
|
import '../../../../../translations/trans_lib.dart';
|
|
import 'massSendElectronicKey_logic.dart';
|
|
|
|
class MassSendElectronicKeyPage extends StatefulWidget {
|
|
final String type;
|
|
|
|
const MassSendElectronicKeyPage({Key? key, required this.type})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<MassSendElectronicKeyPage> createState() =>
|
|
_MassSendElectronicKeyPageState();
|
|
}
|
|
|
|
class _MassSendElectronicKeyPageState extends State<MassSendElectronicKeyPage> {
|
|
final logic = Get.put(MassSendElectronicKeyLogic());
|
|
final state = Get.find<MassSendElectronicKeyLogic>().state;
|
|
|
|
@override
|
|
initState() {
|
|
super.initState();
|
|
getDemoMode();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
logic.resetData();
|
|
});
|
|
}
|
|
|
|
Future<void> getDemoMode() async {
|
|
state.isDemoMode = (await Storage.getBool(ifIsDemoModeOrNot))!;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
state.type.value = widget.type;
|
|
|
|
return SingleChildScrollView(
|
|
child: state.isDemoMode
|
|
? indexChangeWidget()
|
|
: Obx(() => indexChangeWidget()),
|
|
);
|
|
}
|
|
|
|
Widget indexChangeWidget() {
|
|
if (state.isSendSuccess.value) {
|
|
return sendElectronicKeySucceed();
|
|
} else {
|
|
switch (int.parse(widget.type)) {
|
|
case 0:
|
|
{
|
|
// 限时
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
keyTimeWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
case 1:
|
|
{
|
|
// 永久
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
case 2:
|
|
{
|
|
// 循环
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
keyPeriodValidityWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
default:
|
|
return Container();
|
|
}
|
|
}
|
|
}
|
|
|
|
// 发送电子钥匙成功
|
|
Widget sendElectronicKeySucceed() {
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
height: 250.h,
|
|
width: 1.sw,
|
|
color: Colors.white,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 30.h,
|
|
),
|
|
Image.asset(
|
|
'images/icon_send_success.png',
|
|
width: 100.w,
|
|
height: 100.w,
|
|
),
|
|
SizedBox(
|
|
height: 20.h,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
"发送成功".tr,
|
|
style: TextStyle(
|
|
fontSize: 26.sp,
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 20.h,
|
|
),
|
|
SubmitBtn(
|
|
btnName: '完成'.tr,
|
|
onClick: () {
|
|
state.isSendSuccess.value = false;
|
|
Get.back();
|
|
}),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 顶部钥匙信息widget
|
|
Widget keyInfoWidget() {
|
|
return Column(
|
|
children: [
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.receiver!.tr,
|
|
rightTitle: state.receiverList.isEmpty
|
|
? TranslationLoader.lanKeys!.pleaseAdd!.tr
|
|
: state.receiverList.length.toString(),
|
|
isHaveLine: true,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Navigator.pushNamed(context, Routers.massSendReceiverPage)
|
|
.then((value) {
|
|
if (value != null) {
|
|
value as Map<String, dynamic>;
|
|
state.receiverList = value['lockUserList'];
|
|
|
|
setState(() {});
|
|
}
|
|
});
|
|
}),
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr,
|
|
rightTitle: "",
|
|
isHaveLine: true,
|
|
isHaveRightWidget: true,
|
|
isHaveDirection: true,
|
|
rightWidget: Text(
|
|
'${state.countryName.value} +${state.countryCode.value}',
|
|
textAlign: TextAlign.end,
|
|
style:
|
|
TextStyle(fontSize: 22.sp, color: AppColors.darkGrayTextColor),
|
|
),
|
|
action: () async {
|
|
var result = await Navigator.pushNamed(
|
|
context, Routers.selectCountryRegionPage);
|
|
if (result != null) {
|
|
result as Map<String, dynamic>;
|
|
state.countryCode = result['code'];
|
|
state.countryName = result['countryName'];
|
|
setState(() {});
|
|
}
|
|
},
|
|
),
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.lock!.tr,
|
|
rightTitle: state.lockIdList.isEmpty
|
|
? TranslationLoader.lanKeys!.pleaseSelect!.tr
|
|
: state.lockIdList.length.toString(),
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Navigator.pushNamed(context, Routers.massSendLockGroupListPage, arguments:{
|
|
"keyLimits":"2",
|
|
}).then((value) {
|
|
//得到选中的锁ID列表
|
|
if (value != null) {
|
|
value as Map<String, dynamic>;
|
|
state.lockIdList = value['selectLockIdList'];
|
|
setState(() {});
|
|
}
|
|
});
|
|
}),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 生效失效时间
|
|
Widget keyTimeWidget() {
|
|
return Column(
|
|
children: [
|
|
Obx(() => CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
|
|
rightTitle: state.beginTime.value,
|
|
isHaveLine: true,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
PDuration selectDate =
|
|
PDuration.parse(DateTime.tryParse(state.beginTime.value));
|
|
Pickers.showDatePicker(context,
|
|
selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) {
|
|
state.beginTime.value = DateTool().getYMDHNDateString(p, 1);
|
|
});
|
|
})),
|
|
Obx(() => CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
|
|
rightTitle: state.endTime.value,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
PDuration selectDate =
|
|
PDuration.parse(DateTime.tryParse(state.endTime.value));
|
|
Pickers.showDatePicker(context,
|
|
selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) {
|
|
state.endTime.value = DateTool().getYMDHNDateString(p, 1);
|
|
});
|
|
})),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 远程开锁
|
|
Widget remoteUnlockingWidget() {
|
|
return Column(
|
|
children: [
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.remoteUnlockingAllowed!.tr,
|
|
rightTitle: "",
|
|
isHaveRightWidget: true,
|
|
rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()),
|
|
action: () {}),
|
|
Container(height: 40.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 有效期
|
|
Widget keyPeriodValidityWidget() {
|
|
return Column(
|
|
children: [
|
|
Obx(() => CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr,
|
|
rightTitle: "${state.beginTime.value}\n${state.endTime.value}",
|
|
isHaveDirection: true,
|
|
isHaveLine: true,
|
|
action: () async {
|
|
var result =
|
|
await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: {
|
|
'validityValue': state.weekdaysList.value,
|
|
'starDate': state.beginTime.value,
|
|
'endDate': state.endTime.value,
|
|
'starTime': state.effectiveDateTime.value,
|
|
'endTime': state.failureDateTime.value
|
|
});
|
|
if (result != null && result.isNotEmpty) {
|
|
state.weekdaysList.value = result['validityValue'];
|
|
state.beginTime.value = result['starDate'];
|
|
state.endTime.value = result['endDate'];
|
|
state.effectiveDateTime.value = result['starTime'];
|
|
state.failureDateTime.value = result['endTime'];
|
|
}
|
|
})),
|
|
Obx(() => Visibility(
|
|
visible: state.weekdaysList.isNotEmpty ? true : false,
|
|
child: CommonItem(
|
|
leftTitel: "有效日".tr,
|
|
rightTitle: state.weekdaysList.value.join(",").toString(),
|
|
isHaveDirection: true,
|
|
isHaveLine: true,
|
|
action: () async {
|
|
var result = await Get.toNamed(Routers.seletKeyCyclicDatePage,
|
|
arguments: {
|
|
'validityValue': state.weekdaysList.value,
|
|
'starDate': state.beginTime.value,
|
|
'endDate': state.endTime.value,
|
|
'starTime': state.effectiveDateTime.value,
|
|
'endTime': state.failureDateTime.value
|
|
});
|
|
if (result != null && result.isNotEmpty) {
|
|
state.weekdaysList.value = result['validityValue'];
|
|
state.beginTime.value = result['starDate'];
|
|
state.endTime.value = result['endDate'];
|
|
state.effectiveDateTime.value = result['starTime'];
|
|
state.failureDateTime.value = result['endTime'];
|
|
}
|
|
}))),
|
|
Obx(() => Visibility(
|
|
visible: state.effectiveDateTime.value.isNotEmpty,
|
|
child: CommonItem(
|
|
leftTitel: "有效时间".tr,
|
|
rightTitle:
|
|
"${state.effectiveDateTime.value}-${state.failureDateTime.value}",
|
|
isHaveDirection: true,
|
|
action: () async {
|
|
var result = await Get.toNamed(
|
|
Routers.seletKeyCyclicDatePage,
|
|
arguments: {
|
|
'validityValue': state.weekdaysList.value,
|
|
'starDate': state.beginTime.value,
|
|
'endDate': state.endTime.value,
|
|
'starTime': state.effectiveDateTime.value,
|
|
'endTime': state.failureDateTime.value
|
|
});
|
|
if (result != null && result.isNotEmpty) {
|
|
state.weekdaysList.value = result['validityValue'];
|
|
state.beginTime.value = result['starDate'];
|
|
state.endTime.value = result['endDate'];
|
|
state.effectiveDateTime.value = result['starTime'];
|
|
state.failureDateTime.value = result['endTime'];
|
|
Get.back(result: result);
|
|
}
|
|
}),
|
|
)),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget keyBottomWidget() {
|
|
return Column(
|
|
children: [
|
|
SubmitBtn(
|
|
btnName: TranslationLoader.lanKeys!.send!.tr,
|
|
onClick: () {
|
|
logic.massKeyChecksRequest();
|
|
}),
|
|
],
|
|
);
|
|
}
|
|
|
|
CupertinoSwitch _switch() {
|
|
return CupertinoSwitch(
|
|
activeColor: CupertinoColors.activeBlue,
|
|
trackColor: CupertinoColors.systemGrey5,
|
|
thumbColor: CupertinoColors.white,
|
|
value: state.isRemoteUnlock.value,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
state.isRemoteUnlock.value = !state.isRemoteUnlock.value;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
}
|