2024-06-04 14:44:04 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2024-07-02 14:03:25 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2024-06-04 14:44:04 +08:00
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2024-07-10 13:56:10 +08:00
|
|
|
|
final FocusNode focusNode = FocusNode();
|
2024-06-04 14:44:04 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
2024-07-10 13:56:10 +08:00
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
|
|
|
|
appBar: TitleAppBar(
|
|
|
|
|
|
barTitle: state.isUpdate.value == false
|
|
|
|
|
|
? state.channelType.value == 1
|
|
|
|
|
|
? '新建短信模版'.tr
|
|
|
|
|
|
: '新建邮件模版'.tr
|
|
|
|
|
|
: state.channelType.value == 1
|
|
|
|
|
|
? '编辑短信模版'.tr
|
|
|
|
|
|
: '编辑邮件模版'.tr,
|
|
|
|
|
|
haveBack: true,
|
|
|
|
|
|
backgroundColor: AppColors.mainColor,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
),
|
2024-07-10 13:56:10 +08:00
|
|
|
|
body: GestureDetector(
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
FocusScope.of(context).unfocus();
|
|
|
|
|
|
},
|
|
|
|
|
|
child: 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(
|
2024-07-31 17:24:30 +08:00
|
|
|
|
btnName: '保存'.tr,
|
2024-07-10 13:56:10 +08:00
|
|
|
|
onClick: () {
|
|
|
|
|
|
if (state.currentTemplate.value.isUpdate == true) {
|
|
|
|
|
|
logic.updateTemplateInfo();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logic.addSMSTemplate();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
SizedBox(height: 40.h),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
)));
|
2024-06-04 14:44:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _buildEditTopInfo() {
|
|
|
|
|
|
return Column(
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
|
CommonItem(
|
|
|
|
|
|
leftTitel: '名称'.tr,
|
|
|
|
|
|
rightTitle: '',
|
|
|
|
|
|
isHaveLine: true,
|
|
|
|
|
|
isHaveRightWidget: true,
|
|
|
|
|
|
rightWidget: getTFWidget(
|
|
|
|
|
|
state.templateNameTf,
|
2024-07-26 09:21:22 +08:00
|
|
|
|
'请输入'.tr,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-07-02 17:42:26 +08:00
|
|
|
|
Obx(() => state.isUpdate.value == false
|
|
|
|
|
|
? CommonItem(
|
2024-08-02 13:52:37 +08:00
|
|
|
|
leftTitel: '类型'.tr,
|
2024-07-09 16:04:56 +08:00
|
|
|
|
rightTitle: state.currentTemplate.value.templateName ?? '',
|
|
|
|
|
|
isHaveLine: true,
|
2024-07-02 17:42:26 +08:00
|
|
|
|
isHaveDirection: true,
|
|
|
|
|
|
action: _showSelectTemplateType,
|
|
|
|
|
|
)
|
|
|
|
|
|
: Container()),
|
2024-07-09 16:04:56 +08:00
|
|
|
|
Obx(() => state.isUpdate.value == false
|
|
|
|
|
|
? CommonItem(
|
2024-08-21 14:12:15 +08:00
|
|
|
|
leftTitel: '模版类型'.tr,
|
2024-07-09 16:04:56 +08:00
|
|
|
|
rightTitle: state.currentTemplate.value.langName ?? '',
|
|
|
|
|
|
isHaveLine: false,
|
|
|
|
|
|
isHaveDirection: true,
|
|
|
|
|
|
action: _showSelectLangType,
|
|
|
|
|
|
)
|
|
|
|
|
|
: Container()),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _buildEditTemplate() {
|
|
|
|
|
|
return Container(
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: EdgeInsets.all(25.w),
|
|
|
|
|
|
child: Text(
|
2024-08-02 13:52:37 +08:00
|
|
|
|
'模版内容'.tr,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
style:
|
|
|
|
|
|
TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w600),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
Container(
|
|
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
|
|
|
|
|
|
height: 100,
|
2024-07-10 13:56:10 +08:00
|
|
|
|
child: _buildContentTF(state.templateOneTf),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
),
|
2024-06-06 13:58:21 +08:00
|
|
|
|
Obx(() => Container(
|
|
|
|
|
|
width: 1.sw - 50.w,
|
|
|
|
|
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
2024-07-02 17:42:26 +08:00
|
|
|
|
padding: EdgeInsets.only(bottom: 20.h),
|
2024-06-06 13:58:21 +08:00
|
|
|
|
child: _buildTemplateWithType(isPreview: false),
|
|
|
|
|
|
)),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
SizedBox(height: 10.h),
|
2024-07-09 16:04:56 +08:00
|
|
|
|
Container(
|
|
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
|
|
|
|
|
|
height: 100,
|
|
|
|
|
|
child: Stack(
|
|
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
|
|
children: <Widget>[
|
2024-07-10 13:56:10 +08:00
|
|
|
|
_buildContentTF(state.templateTwoTf),
|
2024-07-09 16:04:56 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2024-06-04 14:44:04 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
2024-08-02 13:52:37 +08:00
|
|
|
|
'预览'.tr,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.w600),
|
|
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Obx(() => Container(
|
2024-06-06 13:58:21 +08:00
|
|
|
|
width: 1.sw - 50.w,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
2024-06-06 13:58:21 +08:00
|
|
|
|
padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 10.h),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: const Color(0xFFF5F5F5),
|
|
|
|
|
|
borderRadius: BorderRadius.circular(10.h),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: _buildTemplateWithType(isPreview: true),
|
|
|
|
|
|
)),
|
2024-07-09 16:04:56 +08:00
|
|
|
|
if (state.channelType.value == 1)
|
2024-07-02 17:42:26 +08:00
|
|
|
|
Padding(
|
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
|
left: 25.w,
|
|
|
|
|
|
top: 25.h,
|
|
|
|
|
|
bottom: 25.h,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
),
|
2024-07-02 17:42:26 +08:00
|
|
|
|
child: Text(
|
2024-08-02 13:52:37 +08:00
|
|
|
|
'${'预计产生短信条数'.tr}:${logic.calculateSmsCost()}',
|
2024-07-02 17:42:26 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
|
fontSize: 20.sp,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
else
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
height: 20.h,
|
|
|
|
|
|
)
|
2024-06-04 14:44:04 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _buildTemplateWithType({required bool isPreview}) {
|
|
|
|
|
|
// 检查当前模板是否为空
|
|
|
|
|
|
if (state.currentTemplate.value.template == null ||
|
|
|
|
|
|
state.currentTemplate.value.template!.isEmpty) {
|
|
|
|
|
|
return const SizedBox.shrink(); // 如果为空,返回一个空的 SizedBox
|
|
|
|
|
|
} else {
|
2024-06-06 13:58:21 +08:00
|
|
|
|
return RichText(
|
|
|
|
|
|
text: TextSpan(
|
2024-08-21 14:12:15 +08:00
|
|
|
|
children: state.currentTemplate.value.templateName == '电子钥匙'.tr
|
2024-06-06 13:58:21 +08:00
|
|
|
|
? logic.buildElectronicKeySpan(isPreview: isPreview)
|
|
|
|
|
|
: logic.buildPasswordSpan(isPreview: isPreview),
|
|
|
|
|
|
),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-10 13:56:10 +08:00
|
|
|
|
Widget _buildContentTF(TextEditingController controller) {
|
2024-06-04 14:44:04 +08:00
|
|
|
|
return TextField(
|
|
|
|
|
|
maxLines: 8,
|
|
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
|
|
controller: controller,
|
|
|
|
|
|
style: state.defaultStyle,
|
2024-07-10 13:56:10 +08:00
|
|
|
|
autofocus: false,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
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) {
|
2024-07-09 16:34:45 +08:00
|
|
|
|
setState(logic.calculateSmsCost);
|
2024-06-04 14:44:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget getTFWidget(TextEditingController tfController, String tfStr) {
|
|
|
|
|
|
return SizedBox(
|
2024-07-02 14:03:25 +08:00
|
|
|
|
height: 65.h,
|
|
|
|
|
|
width: 320.w,
|
|
|
|
|
|
child: TextField(
|
|
|
|
|
|
controller: tfController, //输入框一行
|
|
|
|
|
|
maxLines: 3,
|
|
|
|
|
|
inputFormatters: <TextInputFormatter>[
|
|
|
|
|
|
FilteringTextInputFormatter.deny('\n'),
|
|
|
|
|
|
LengthLimitingTextInputFormatter(50),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
],
|
2024-07-02 14:03:25 +08:00
|
|
|
|
autofocus: false,
|
|
|
|
|
|
textAlign: TextAlign.end,
|
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
|
//输入里面输入文字内边距设置
|
|
|
|
|
|
hintText: tfStr,
|
|
|
|
|
|
hintStyle: TextStyle(fontSize: 22.sp),
|
|
|
|
|
|
focusedBorder: const OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(width: 0, color: Colors.transparent)),
|
|
|
|
|
|
disabledBorder: const OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(width: 0, color: Colors.transparent)),
|
|
|
|
|
|
enabledBorder: const OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(width: 0, color: Colors.transparent)),
|
|
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(width: 0, color: Colors.transparent)),
|
|
|
|
|
|
contentPadding: EdgeInsets.only(top: 20.h, bottom: 0)),
|
|
|
|
|
|
style:
|
|
|
|
|
|
TextStyle(fontSize: 22.sp, textBaseline: TextBaseline.alphabetic),
|
2024-06-04 14:44:04 +08:00
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _showSelectTemplateType() {
|
|
|
|
|
|
final List<String> titleList = state.templateList
|
2024-07-09 16:04:56 +08:00
|
|
|
|
.map((TemplateData template) => template.templateName ?? '')
|
2024-06-04 14:44:04 +08:00
|
|
|
|
.toList();
|
|
|
|
|
|
ShowBottomSheetTool().showSingleRowPicker(
|
|
|
|
|
|
context,
|
|
|
|
|
|
normalIndex: 0,
|
2024-08-02 13:52:37 +08:00
|
|
|
|
title: '类型'.tr,
|
2024-07-26 09:57:44 +08:00
|
|
|
|
cancelTitle: '取消'.tr,
|
2024-07-26 09:21:22 +08:00
|
|
|
|
sureTitle: '确定'.tr,
|
2024-06-04 14:44:04 +08:00
|
|
|
|
data: titleList,
|
|
|
|
|
|
clickCallBack: (int index, Object str) {
|
2024-07-09 16:04:56 +08:00
|
|
|
|
state.selectedTemplateIndex.value = index;
|
2024-06-04 14:44:04 +08:00
|
|
|
|
state.currentTemplate.value = state.templateList[index];
|
2024-07-09 16:04:56 +08:00
|
|
|
|
state.currentTemplate.value.templateName = str.toString();
|
|
|
|
|
|
state.selectedTemplateIndex.refresh();
|
|
|
|
|
|
state.currentTemplate.refresh();
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _showSelectLangType() {
|
|
|
|
|
|
// 提取 langName 列表
|
|
|
|
|
|
final List<String> langNames = state.langTemplateList
|
|
|
|
|
|
.map((LangData langData) => langData.langName ?? '')
|
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
|
|
ShowBottomSheetTool().showSingleRowPicker(
|
|
|
|
|
|
context,
|
|
|
|
|
|
normalIndex: 0,
|
2024-08-02 13:52:37 +08:00
|
|
|
|
title: '类型'.tr,
|
2024-07-26 09:57:44 +08:00
|
|
|
|
cancelTitle: '取消'.tr,
|
2024-07-26 09:21:22 +08:00
|
|
|
|
sureTitle: '确定'.tr,
|
2024-07-09 16:04:56 +08:00
|
|
|
|
data: langNames,
|
|
|
|
|
|
clickCallBack: (int index, Object str) {
|
|
|
|
|
|
state.selectedLangIndex.value = index;
|
|
|
|
|
|
state.currentTemplate.value = state
|
|
|
|
|
|
.langTemplateList[state.selectedLangIndex.value]
|
|
|
|
|
|
.templates![state.selectedTemplateIndex.value];
|
|
|
|
|
|
state.currentTemplate.value.langName = str.toString();
|
|
|
|
|
|
state.selectedLangIndex.refresh();
|
2024-06-04 14:44:04 +08:00
|
|
|
|
state.currentTemplate.refresh();
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|