diff --git a/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart b/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart index 1303fc90..9cdca4bb 100755 --- a/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart +++ b/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/view/sendElectronicKeyView_page.dart @@ -426,12 +426,12 @@ class _SendElectronicKeyViewState extends State OutLineBtn( btnName: logic.state.userNameType.value == 1 ? '短信通知' : '邮件通知', onClick: () { - if (logic.state.userNameType.value == 2) { - Get.toNamed(Routers.sendEmailNotificationPage, - arguments: {'email': logic.emailOrPhone}); - } else { - logic.sendMsg(isPhone: true); - } + Get.toNamed(Routers.sendEmailNotificationPage, + arguments: { + 'receiver': logic.emailOrPhone, + 'userNameType': logic.state.userNameType.value, + 'keyId': logic.keyId + }); }, ), SizedBox( diff --git a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_logic.dart b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_logic.dart index 475d09bb..207aafdd 100644 --- a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_logic.dart +++ b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_logic.dart @@ -1,4 +1,4 @@ -import 'package:get_storage/get_storage.dart'; +import 'package:get/get.dart'; 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'; @@ -13,13 +13,33 @@ class SendEmailNotificationLogic extends BaseGetXController { final SendEmailNotificationEntity entity = await ApiRepository.to.getKeyNoticeTemplate( lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, - keyId: CommonDataManage().currentKeyInfo.keyId ?? 0, - channelType: 2, + keyId: state.getKeyId.value, + channelType: state.channelType.value, ); if (entity.errorCode!.codeIsSuccessful) { state.emailTemplateList.value = entity.data?.list ?? []; + state.currentNotifyItem.value = state.emailTemplateList.first; + state.emailController.text = state.currentNotifyItem.value.template ?? ''; state.emailTemplateList.refresh(); + state.currentNotifyItem.refresh(); + } + } + + //发送短信、邮件通知 channelType--1短信 2邮件 openDoorType--1电子钥匙 2密码 + Future keyNoticeSubmitRequest() async { + final SendEmailNotificationEntity entity = + await ApiRepository.to.keyNoticeSubmit( + receiverName: state.getReceiver.value, + 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(); } } } diff --git a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_page.dart b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_page.dart index 40b89831..b6923f78 100755 --- a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_page.dart +++ b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/SendEmailNotification_logic.dart'; +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/tools/emailNotifyTypeSelectAlert.dart'; import 'package:star_lock/tools/pickers/pickers.dart'; @@ -39,7 +40,7 @@ class _SendEmailNotificationPageState extends State { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: '邮件通知', + barTitle: state.channelType.value == 1 ? '短信通知' : '邮件通知', haveBack: true, backgroundColor: AppColors.mainColor), body: SingleChildScrollView( @@ -47,25 +48,25 @@ class _SendEmailNotificationPageState extends State { children: [ Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.receiver!.tr, - rightTitle: state.getEmail.value, + rightTitle: state.getReceiver.value, isHaveLine: true, )), Obx(() => CommonItem( leftTitel: '类型', - rightTitle: - state.emailNotifyType.value == 1 ? '系统邮件' : '个人邮件', + rightTitle: state.getNotifyTypeText.value, isHaveDirection: true, action: () { EmailNotifyTypeSelectAlert.showEmailNotifyTypeSelectAlert( - context, (int value) { - state.emailNotifyType.value = value; - }); + isEmail: state.channelType.value == 2, + onSelected: (int value) { + state.notifyTypeSelect.value = value; + }); }, )), Container(height: 10.h), Obx(() => CommonItem( leftTitel: '模板', - rightTitle: state.selectEmailTemplate.value, + rightTitle: state.currentNotifyItem.value.name ?? '', isHaveDirection: true, isHaveLine: true, action: () { @@ -125,7 +126,9 @@ class _SendEmailNotificationPageState extends State { borderRadius: 20.w, margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), + onClick: () { + logic.keyNoticeSubmitRequest(); + }), ], ), ), @@ -134,13 +137,15 @@ class _SendEmailNotificationPageState extends State { // 底部选择pickerView void openBottomItemSheet(BuildContext context) { - final List nameList = - state.emailTemplateList.map((item) => item.name!).toList(); + final List nameList = state.emailTemplateList + .map((EmailNotificationItem item) => item.name!) + .toList(); Pickers.showSinglePicker(context, data: nameList, pickerStyle: DefaultPickerStyle(), onConfirm: (p, int position) { - state.selectEmailTemplate.value = nameList[position]; + state.currentNotifyItem.value = state.emailTemplateList[position]; + state.emailController.text = state.emailTemplateList[position].template!; }); } } diff --git a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart index bbe0e2fe..e3e2eb54 100644 --- a/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart +++ b/lib/main/lockDetail/electronicKey/sendEmailNotification/sendEmailNotification_state.dart @@ -4,14 +4,39 @@ import 'package:star_lock/main/lockDetail/electronicKey/sendEmailNotification/se class SendEmailNotificationState { SendEmailNotificationState() { - if (Get.arguments['email'] != null) { - getEmail.value = Get.arguments['email']; + if (Get.arguments['receiver'] != null) { + getReceiver.value = Get.arguments['receiver']; + } + + if (Get.arguments['keyId'] != null) { + getKeyId.value = Get.arguments['keyId']; + } + + if (Get.arguments['userNameType'] != null) { + channelType.value = Get.arguments['userNameType']; + if (channelType.value == 1) { + if (notifyTypeSelect.value == 1) { + getNotifyTypeText.value = '系统短信'; + } else { + getNotifyTypeText.value = '个人短信'; + } + } else { + if (notifyTypeSelect.value == 1) { + getNotifyTypeText.value = '系统邮件'; + } else { + getNotifyTypeText.value = '个人邮件'; + } + } } } - RxString getEmail = ''.obs; + RxString getReceiver = ''.obs; final TextEditingController emailController = TextEditingController(); - RxInt emailNotifyType = 1.obs; //1 代表系统邮件,2 代表个人邮件 - RxList emailTemplateList = [].obs; - RxString selectEmailTemplate = '默认模版'.obs; + RxInt notifyTypeSelect = 1.obs; //1 代表系统,2 代表个人 + RxInt channelType = 0.obs; //1 代表短信,2 代表邮件 + RxString getNotifyTypeText = ''.obs; + RxList emailTemplateList = + [].obs; + Rx currentNotifyItem = EmailNotificationItem().obs; + RxInt getKeyId = 0.obs; //获取钥匙成功得到的keyId } diff --git a/lib/network/api.dart b/lib/network/api.dart index ea17749e..8bd06dec 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -255,4 +255,5 @@ abstract class Api { final String checkIpURL = '/checkIp/ip'; final String keyNoticeTemplateURL = '/key/getNoticeTemplate'; //获取电子钥匙通知模板 + final String keyNoticeSubmitURL = '/key/noticeSubmit'; //发送短信、邮件通知 } diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 19035f57..18cfa4b7 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -2245,6 +2245,21 @@ class ApiProvider extends BaseProvider { }), isUnShowLoading: true, ); + + Future> keyNoticeSubmit(String receiverName, int lockId, + int keyId, int channelType, int openDoorType, String templateType) => + post( + keyNoticeSubmitURL.toUrl, + jsonEncode({ + 'receiverName': receiverName, + 'lockId': lockId, + 'keyId': keyId, + 'channelType': channelType, + 'openDoorType': openDoorType, + 'templateType': templateType, + }), + isUnShowLoading: true, + ); } extension ExtensionString on String { diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 542b08f6..1e04fe9d 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -2259,4 +2259,18 @@ class ApiRepository { await apiProvider.getKeyNoticeTemplate(lockId, keyId, channelType); return SendEmailNotificationEntity.fromJson(res.body); } + + // 发送短信、邮件通知 + Future keyNoticeSubmit({ + required String receiverName, + required int lockId, + required int keyId, + required int channelType, + required int openDoorType, + required String templateType, + }) async { + final Response res = await apiProvider.keyNoticeSubmit( + receiverName, lockId, keyId, channelType, openDoorType, templateType); + return SendEmailNotificationEntity.fromJson(res.body); + } } diff --git a/lib/tools/emailNotifyTypeSelectAlert.dart b/lib/tools/emailNotifyTypeSelectAlert.dart index 693ab04e..c7c1afec 100644 --- a/lib/tools/emailNotifyTypeSelectAlert.dart +++ b/lib/tools/emailNotifyTypeSelectAlert.dart @@ -14,10 +14,10 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget { } static void showEmailNotifyTypeSelectAlert( - BuildContext context, Function(int) onSelected) { + {required bool isEmail, required Function(int) onSelected}) { bool isSystemEmailSelected = true; // 默认选中系统邮件 showCupertinoDialog( - context: context, + context: Get.context!, builder: (BuildContext context) { return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { @@ -54,7 +54,7 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget { Padding( padding: EdgeInsets.only(left: 10.w), child: Text( - '系统邮件(推荐)', + isEmail ? '系统邮件(推荐)' : '系统短信(推荐)', style: TextStyle( fontSize: 22.sp, fontWeight: FontWeight.bold), ), @@ -67,7 +67,9 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget { child: Align( alignment: Alignment.centerLeft, child: Text( - '邮件将从软件平台直接发给用户,请根据需要在软件那里购买邮件数量', + isEmail + ? '邮件将从软件平台直接发给用户,请根据需要在软件那里购买邮件数量' + : '短信将从软件平台直接发给用户,请根据需要在软件那里购买短信数量', style: TextStyle(fontSize: 18.sp), textAlign: TextAlign.left, ), @@ -93,7 +95,7 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget { Padding( padding: EdgeInsets.only(left: 10.w), child: Text( - '个人邮件', + isEmail ? '个人邮件' : '个人短信', style: TextStyle( fontSize: 22.sp, fontWeight: FontWeight.bold), ), @@ -106,8 +108,11 @@ class EmailNotifyTypeSelectAlert extends StatelessWidget { child: Align( alignment: Alignment.centerLeft, child: Text( - '邮件将从你的个人邮箱发给用户', + isEmail + ? '邮件将从你的个人邮箱发给用户' + : '短信将从你的个人手机号发给用户,费用由运营商从你的手机号扣除', style: TextStyle(fontSize: 18.sp), + textAlign: TextAlign.left, ), ), ),