Daisy 9158ce71e7 1,新增获取邮件模版列表API对接及逻辑处理
2,新增获取默认邮件模版(电子钥匙、密码类型)API对接
2024-06-05 18:24:59 +08:00

266 lines
8.5 KiB
Dart
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/showBottomSheetTool.dart';
import '../../../../tools/submitBtn.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../translations/trans_lib.dart';
class NewSMSTemplatePage extends StatefulWidget {
const NewSMSTemplatePage({Key? key}) : super(key: key);
@override
State<NewSMSTemplatePage> createState() => _NewSMSTemplatePageState();
}
class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
final NewSMSTemplateLogic logic = Get.put(NewSMSTemplateLogic());
final NewSMSTemplateState state = Get.find<NewSMSTemplateLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: state.templateType.value == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
_buildEditTopInfo(),
SizedBox(height: 10.h),
_buildEditTemplate(),
SizedBox(height: 10.h),
_buildPreView(),
SizedBox(height: 42.h),
Container(
margin: EdgeInsets.symmetric(horizontal: 20.w),
child: SubmitBtn(
btnName: TranslationLoader.lanKeys!.save!.tr,
onClick: () {
if (state.currentTemplate.value.isUpdate == true) {
logic.updateTemplateInfo();
} else {
logic.addSMSTemplate();
}
},
),
),
SizedBox(height: 40.h),
],
),
),
);
}
Widget _buildEditTopInfo() {
return Column(
children: <Widget>[
CommonItem(
leftTitel: '名称'.tr,
rightTitle: '',
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: getTFWidget(
state.templateNameTf,
TranslationLoader.lanKeys!.pleaseEnter!.tr,
),
),
Obx(
() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.type!.tr,
rightTitle: state.currentTemplate.value.typeName ?? '',
isHaveLine: false,
isHaveDirection: true,
action: _showSelectTemplateType,
),
),
],
);
}
Widget _buildEditTemplate() {
return Container(
color: Colors.white,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.all(25.w),
child: Text(
TranslationLoader.lanKeys!.templateContent!.tr,
style:
TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w600),
),
),
],
),
Container(
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
height: 100,
child: _buildTextField(state.templateOneTf),
),
Obx(() => _buildTemplateWithType(isPreview: false)),
SizedBox(height: 10.h),
Container(
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
height: 100,
child: Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
_buildTextField(state.templateTwoTf),
],
),
),
],
),
);
}
Widget _buildPreView() {
return Container(
color: Colors.white,
margin: EdgeInsets.only(bottom: 20.h),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 25.h, bottom: 25.h, left: 25.w),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
TranslationLoader.lanKeys!.preview!.tr,
style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w600),
textAlign: TextAlign.left,
),
),
),
Obx(() => Container(
margin: EdgeInsets.only(left: 25.w, right: 25.w),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(10.h),
),
child: _buildTemplateWithType(isPreview: true),
)),
Padding(
padding: EdgeInsets.only(
left: 25.w,
top: 25.h,
bottom: 25.h,
),
child: Text(
'预计产生短信条数2',
style: TextStyle(
color: Colors.grey,
fontSize: 20.sp,
),
),
),
],
),
);
}
Widget _buildTemplateWithType({required bool isPreview}) {
// 检查当前模板是否为空
if (state.currentTemplate.value.template == null ||
state.currentTemplate.value.template!.isEmpty) {
return const SizedBox.shrink(); // 如果为空,返回一个空的 SizedBox
} else {
return Row(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 10.h),
child: Obx(() => RichText(
text: TextSpan(
children: state.currentTemplate.value.typeName == '电子钥匙'
? logic.buildElectronicKeySpan(isPreview: isPreview)
: logic.buildPasswordSpan(isPreview: isPreview),
),
)),
),
],
);
}
}
Widget _buildTextField(TextEditingController controller) {
return TextField(
maxLines: 8,
textAlign: TextAlign.start,
controller: controller,
style: state.defaultStyle,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(20.w),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.h),
borderSide: const BorderSide(color: Color(0xffB2B2B2), width: 0.5),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.h),
borderSide: const BorderSide(color: Color(0xffB2B2B2), width: 1),
),
),
onChanged: (String value) {
setState(() {
controller.text = value;
});
},
);
}
Widget getTFWidget(TextEditingController tfController, String tfStr) {
return SizedBox(
height: 50.h,
width: 300.w,
child: Row(
children: <Widget>[
Expanded(
child: TextField(
maxLines: 1,
controller: tfController,
autofocus: false,
textAlign: TextAlign.end,
style: TextStyle(fontSize: 22.sp),
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0),
hintText: tfStr,
hintStyle: TextStyle(fontSize: 22.sp),
border: InputBorder.none,
),
),
),
],
),
);
}
void _showSelectTemplateType() {
final List<String> titleList = state.templateList
.map((SMSTemplateData template) => template.typeName ?? '')
.toList();
ShowBottomSheetTool().showSingleRowPicker(
context,
normalIndex: 0,
title: TranslationLoader.lanKeys!.type!.tr,
cancelTitle: TranslationLoader.lanKeys!.cancel!.tr,
sureTitle: TranslationLoader.lanKeys!.sure!.tr,
data: titleList,
clickCallBack: (int index, Object str) {
state.currentTemplate.value = state.templateList[index];
state.currentTemplate.value.typeName = str.toString();
state.currentTemplate.refresh();
},
);
}
}