268 lines
8.7 KiB
Dart
Executable File
268 lines
8.7 KiB
Dart
Executable File
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 == 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(() => Container(
|
|
width: 1.sw - 50.w,
|
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
|
child: _buildTemplateWithType(isPreview: false),
|
|
)),
|
|
SizedBox(height: 10.h),
|
|
Obx(() => Visibility(
|
|
visible: state.templateType.value == 1,
|
|
child: 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(
|
|
width: 1.sw - 50.w,
|
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
|
padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 10.h),
|
|
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(
|
|
'预计产生短信条数:${state.smsCost.value}',
|
|
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 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;
|
|
logic.updateSmsCost(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();
|
|
},
|
|
);
|
|
}
|
|
}
|