255 lines
10 KiB
Dart
Executable File
255 lines
10 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart';
|
||
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart';
|
||
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart';
|
||
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart';
|
||
import 'package:star_lock/tools/EasyRefreshTool.dart';
|
||
import 'package:star_lock/tools/noData.dart';
|
||
import 'package:star_lock/tools/showTipView.dart';
|
||
|
||
import '../../../../appRouters.dart';
|
||
import '../../../../app_settings/app_colors.dart';
|
||
import '../../../../tools/submitBtn.dart';
|
||
import '../../../../tools/titleAppBar.dart';
|
||
|
||
class CustomSMSTemplateListPage extends StatefulWidget {
|
||
const CustomSMSTemplateListPage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<CustomSMSTemplateListPage> createState() =>
|
||
_CustomSMSTemplateListPageState();
|
||
}
|
||
|
||
class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
|
||
final CustomSMSTemplateListLogic logic =
|
||
Get.put(CustomSMSTemplateListLogic());
|
||
final CustomSMSTemplateListState state =
|
||
Get.find<CustomSMSTemplateListLogic>().state;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
logic.getSMSTemplateListRequest(isRefresh: true);
|
||
logic.getVipStatus();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
backgroundColor: AppColors.mainBackgroundColor,
|
||
appBar: TitleAppBar(
|
||
barTitle: state.channelType.value == 1 ? '自定义短信模版'.tr : '自定义邮件模版'.tr,
|
||
haveBack: true,
|
||
backgroundColor: AppColors.mainColor),
|
||
body: EasyRefreshTool(
|
||
onRefresh: () {
|
||
logic.getSMSTemplateListRequest(isRefresh: true);
|
||
},
|
||
onLoad: () {
|
||
logic.getSMSTemplateListRequest(isRefresh: false);
|
||
},
|
||
child: Column(
|
||
children: <Widget>[
|
||
Obx(() => Visibility(
|
||
child: _topTipWidget(),
|
||
visible: !state.isVip.value,
|
||
)),
|
||
Expanded(child: Obx(buildMainUI)),
|
||
SubmitBtn(
|
||
btnName: '新建模板'.tr,
|
||
borderRadius: 20.w,
|
||
margin: EdgeInsets.only(
|
||
left: 30.w, right: 30.w, top: 30.w, bottom: 30.w),
|
||
padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
|
||
onClick: () async {
|
||
final TemplateData templateData = TemplateData();
|
||
templateData.channelType = state.channelType.value;
|
||
templateData.isUpdate = false;
|
||
templateData.templateName =
|
||
templateData.templateType == 1 ? '电子钥匙'.tr : '密码'.tr;
|
||
final result = await Get.toNamed(Routers.newSMSTemplatePage,
|
||
arguments: {
|
||
'currentTemplate': templateData,
|
||
'isUpdate': false
|
||
});
|
||
if (result != null) {
|
||
logic.getSMSTemplateListRequest(isRefresh: true);
|
||
}
|
||
}),
|
||
SizedBox(
|
||
height: 40.h,
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _topTipWidget() {
|
||
return Container(
|
||
margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
|
||
padding:
|
||
EdgeInsets.only(top: 20.h, left: 20.w, right: 20.w, bottom: 20.h),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white, borderRadius: BorderRadius.circular(5)),
|
||
child: Column(
|
||
children: <Widget>[
|
||
Text(
|
||
'你可以自己定义模版的内容,用于发送密码或电子钥匙信息给他人'.tr,
|
||
style: TextStyle(
|
||
fontSize: 22.sp,
|
||
color: AppColors.blackColor,
|
||
fontWeight: FontWeight.w600),
|
||
),
|
||
SizedBox(
|
||
height: 15.h,
|
||
),
|
||
Container(
|
||
padding: EdgeInsets.only(
|
||
top: 15.h, left: 15.w, right: 15.w, bottom: 15.h),
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFFFbF9EC),
|
||
borderRadius: BorderRadius.circular(10.h)),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: <Widget>[
|
||
SizedBox(
|
||
width: 1.sw - 15.w * 2 - 40.w * 2 - 140.w,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text(
|
||
'${'当前状态'.tr}:${'试用中'.tr}',
|
||
style: TextStyle(
|
||
fontSize: 20.sp, fontWeight: FontWeight.w600),
|
||
),
|
||
Text('高级功能仅能用于你自己的锁'.tr,
|
||
style: TextStyle(
|
||
fontSize: 20.sp, fontWeight: FontWeight.w600))
|
||
],
|
||
),
|
||
),
|
||
GestureDetector(
|
||
onTap: () {
|
||
Navigator.pushNamed(
|
||
context, Routers.valueAddedServicesHighFunctionPage);
|
||
},
|
||
child: Container(
|
||
width: 100.w,
|
||
height: 50.h,
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFFCAB68D),
|
||
borderRadius: BorderRadius.circular(35.h)),
|
||
child: Center(
|
||
child: Text(
|
||
'去开通'.tr,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
color: Colors.white, fontSize: 20.sp)))),
|
||
),
|
||
],
|
||
),
|
||
)
|
||
],
|
||
));
|
||
}
|
||
|
||
Widget buildMainUI() {
|
||
return state.smsTemplateList.isNotEmpty
|
||
? SlidableAutoCloseBehavior(
|
||
child: ListView.builder(
|
||
itemCount: state.smsTemplateList.length,
|
||
itemBuilder: (BuildContext c, int index) {
|
||
final CustomSMSTemplateItem itemData =
|
||
state.smsTemplateList[index];
|
||
return Slidable(
|
||
key: ValueKey(itemData.id),
|
||
endActionPane: ActionPane(
|
||
extentRatio: 0.2,
|
||
motion: const ScrollMotion(),
|
||
children: <Widget>[
|
||
SlidableAction(
|
||
onPressed: (BuildContext context) {
|
||
ShowTipView()
|
||
.showIosTipWithContentDialog('是否删除?'.tr, () {
|
||
logic.deleteSMSTemplateRequest(
|
||
id: itemData.id ?? 0);
|
||
});
|
||
},
|
||
backgroundColor: Colors.red,
|
||
foregroundColor: Colors.white,
|
||
label: '删除'.tr,
|
||
padding: EdgeInsets.only(left: 5.w, right: 5.w),
|
||
),
|
||
],
|
||
),
|
||
child: _valueAddedServicesListSMSTemplateItem(itemData));
|
||
}),
|
||
)
|
||
: NoData();
|
||
}
|
||
|
||
Widget _valueAddedServicesListSMSTemplateItem(
|
||
CustomSMSTemplateItem itemData) {
|
||
return GestureDetector(
|
||
onTap: () async {
|
||
final TemplateData templateData = TemplateData();
|
||
templateData.name = itemData.name;
|
||
templateData.regards = itemData.regards;
|
||
templateData.tips = itemData.tips;
|
||
templateData.id = itemData.id;
|
||
templateData.template = itemData.template;
|
||
templateData.templateType = itemData.templateType;
|
||
templateData.templateName = templateData.templateName == 1 ? '电子钥匙'.tr : '密码'.tr;
|
||
templateData.channelType = itemData.channelType;
|
||
templateData.isUpdate = true;
|
||
final result = await Get.toNamed(Routers.newSMSTemplatePage,
|
||
arguments: {'currentTemplate': templateData, 'isUpdate': true});
|
||
if (result != null) {
|
||
logic.getSMSTemplateListRequest(isRefresh: true);
|
||
}
|
||
},
|
||
child: Container(
|
||
margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(10.w),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Padding(
|
||
padding: EdgeInsets.only(left: 30.h, top: 30.h, bottom: 20.h),
|
||
child: Text(
|
||
itemData.name ?? '',
|
||
style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600),
|
||
),
|
||
),
|
||
Container(
|
||
width: 1.sw - 20.w * 2 - 30.w * 2,
|
||
margin: EdgeInsets.only(left: 25.w, right: 25.w, bottom: 25.h),
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFFF5F5F5),
|
||
borderRadius: BorderRadius.circular(10.h),
|
||
),
|
||
child: Padding(
|
||
padding: EdgeInsets.only(left: 20.w, top: 20.h, bottom: 20.h),
|
||
child: RichText(
|
||
text: TextSpan(
|
||
children: itemData.templateType == 1
|
||
? logic.buildElectronicKeySpan(templateData: itemData)
|
||
: logic.buildPasswordSpan(templateData: itemData),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|