2024-06-12 13:53:59 +08:00
|
|
|
|
import 'package:get/get.dart';
|
2024-06-11 17:55:00 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_entity.dart';
|
|
|
|
|
|
import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart';
|
|
|
|
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/commonDataManage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SendEmailNotificationLogic extends BaseGetXController {
|
|
|
|
|
|
final SendEmailNotificationState state = SendEmailNotificationState();
|
|
|
|
|
|
|
|
|
|
|
|
//获取电子钥匙通知模板 渠道:1短信 2邮箱
|
|
|
|
|
|
Future<void> getKeyNoticeTemplate() async {
|
|
|
|
|
|
final SendEmailNotificationEntity entity =
|
|
|
|
|
|
await ApiRepository.to.getKeyNoticeTemplate(
|
|
|
|
|
|
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
|
2024-06-12 13:53:59 +08:00
|
|
|
|
keyId: state.getKeyId.value,
|
|
|
|
|
|
channelType: state.channelType.value,
|
2024-06-11 17:55:00 +08:00
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
state.emailTemplateList.value =
|
|
|
|
|
|
entity.data?.list ?? <EmailNotificationItem>[];
|
2024-06-12 13:53:59 +08:00
|
|
|
|
state.currentNotifyItem.value = state.emailTemplateList.first;
|
2024-06-12 16:49:39 +08:00
|
|
|
|
state.templateContentController.text =
|
|
|
|
|
|
state.currentNotifyItem.value.template ?? '';
|
2024-06-11 17:55:00 +08:00
|
|
|
|
state.emailTemplateList.refresh();
|
2024-06-12 13:53:59 +08:00
|
|
|
|
state.currentNotifyItem.refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 16:49:39 +08:00
|
|
|
|
//发送短信、邮件通知 channelType--1短信 2邮件 opisAPKFileName
|
2024-06-12 13:53:59 +08:00
|
|
|
|
Future<void> keyNoticeSubmitRequest() async {
|
2024-06-12 16:49:39 +08:00
|
|
|
|
if (state.receiverController.text.isEmpty &&
|
|
|
|
|
|
state.getReceiver.value.isEmpty) {
|
|
|
|
|
|
showToast('请输入接收者');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-06-12 13:53:59 +08:00
|
|
|
|
final SendEmailNotificationEntity entity =
|
|
|
|
|
|
await ApiRepository.to.keyNoticeSubmit(
|
2024-06-12 16:49:39 +08:00
|
|
|
|
receiverName: state.getReceiver.value.isEmpty
|
|
|
|
|
|
? state.receiverController.text
|
|
|
|
|
|
: state.getReceiver.value,
|
2024-06-12 13:53:59 +08:00
|
|
|
|
lockId: CommonDataManage().currentKeyInfo.lockId ?? 0,
|
|
|
|
|
|
keyId: state.getKeyId.value,
|
|
|
|
|
|
channelType: state.channelType.value,
|
|
|
|
|
|
openDoorType: 1,
|
|
|
|
|
|
templateType: state.currentNotifyItem.value.type ?? '',
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
showToast('发送成功');
|
|
|
|
|
|
Get.back();
|
2024-06-11 17:55:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|