diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart index 4a6d8475..cbfe55b4 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart'; import 'package:star_lock/tools/regularExpression.dart'; @@ -12,9 +13,15 @@ class CustomSMSTemplateListLogic extends BaseGetXController { CustomSMSTemplateListState state = CustomSMSTemplateListState(); //获取短信模板列表 - Future getSMSTemplateListRequest() async { + Future getSMSTemplateListRequest({required bool isRefresh}) async { + // 如果是下拉刷新,清空已有数据 + if (isRefresh) { + state.smsTemplateList.clear(); + pageNo = 1; + } final CustomSMSTemplateListEntity entity = await ApiRepository.to - .getSMSTemplateList(type: 1, pageNo: 1, pageSize: 20); + .getSMSTemplateList( + type: 1, pageNo: pageNo, pageSize: int.parse(pageSize)); if (entity.errorCode!.codeIsSuccessful) { state.smsTemplateList.value = entity.data?.list ?? []; @@ -22,6 +29,15 @@ class CustomSMSTemplateListLogic extends BaseGetXController { } } + //删除短信模版 + Future deleteSMSTemplateRequest({required int id}) async { + final LoginEntity entity = + await ApiRepository.to.deleteTemplateInfo(id: id); + if (entity.errorCode!.codeIsSuccessful) { + getSMSTemplateListRequest(isRefresh: true); + } + } + List buildElectronicKeySpan( {required CustomSMSTemplateItem templateData}) { final List textSpans = []; diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart index 5db7684d..01c34643 100755 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart @@ -1,11 +1,14 @@ 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'; @@ -30,7 +33,7 @@ class _CustomSMSTemplateListPageState extends State { @override void initState() { super.initState(); - logic.getSMSTemplateListRequest(); + logic.getSMSTemplateListRequest(isRefresh: true); } @override @@ -41,29 +44,37 @@ class _CustomSMSTemplateListPageState extends State { barTitle: '自定义短信模版'.tr, haveBack: true, backgroundColor: AppColors.mainColor), - body: Column( - children: [ - Obx(() => Visibility( - child: _topTipWidget(), - visible: !state.isVip.value, - )), - Expanded(child: Obx(buildMainUI)), - SubmitBtn( - btnName: TranslationLoader.lanKeys!.creatingANewTemplate!.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 result = await Get.toNamed(Routers.newSMSTemplatePage); - if (result != null) { - logic.getSMSTemplateListRequest(); - } - }), - SizedBox( - height: 40.h, - ) - ], + body: EasyRefreshTool( + onRefresh: () { + logic.getSMSTemplateListRequest(isRefresh: true); + }, + onLoad: () { + logic.getSMSTemplateListRequest(isRefresh: false); + }, + child: Column( + children: [ + Obx(() => Visibility( + child: _topTipWidget(), + visible: !state.isVip.value, + )), + Expanded(child: Obx(buildMainUI)), + SubmitBtn( + btnName: TranslationLoader.lanKeys!.creatingANewTemplate!.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 result = await Get.toNamed(Routers.newSMSTemplatePage); + if (result != null) { + logic.getSMSTemplateListRequest(isRefresh: true); + } + }), + SizedBox( + height: 40.h, + ) + ], + ), ), ); } @@ -139,13 +150,36 @@ class _CustomSMSTemplateListPageState extends State { Widget buildMainUI() { return state.smsTemplateList.isNotEmpty - ? ListView.builder( - itemCount: state.smsTemplateList.length, - itemBuilder: (BuildContext c, int index) { - final CustomSMSTemplateItem itemData = - state.smsTemplateList[index]; - return _valueAddedServicesListSMSTemplateItem(itemData); - }) + ? 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: [ + 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(); } @@ -166,7 +200,7 @@ class _CustomSMSTemplateListPageState extends State { 'currentTemplate': templateData }); if (result != null) { - logic.getSMSTemplateListRequest(); + logic.getSMSTemplateListRequest(isRefresh: true); } }, child: Container( diff --git a/lib/network/api.dart b/lib/network/api.dart index 9bdb14a0..d3f5b998 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -251,4 +251,5 @@ abstract class Api { final String addSMSTemplateURL = '/v2/service/addSmsTemplate'; //添加短信模板 final String keydetail = ' /key/detail'; //获取钥匙详情 final String updateTemplateInfoURL = '/v2/service/update'; //更新模板信息 + final String deleteTemplateURL = '/v2/service/delete'; //删除模板 } diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 403dd5cd..7b6b7baa 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -2211,6 +2211,12 @@ class ApiProvider extends BaseProvider { }), isUnShowLoading: true, ); + + Future> deleteTemplateInfo(int id) => post( + deleteTemplateURL.toUrl, + jsonEncode({'id': id}), + isUnShowLoading: true, + ); } extension ExtensionString on String { diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index f8ef8da6..19cb6b66 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -2229,4 +2229,10 @@ class ApiRepository { await apiProvider.updateTemplateInfo(id, name, regards, tips); return LoginEntity.fromJson(res.body); } + + // 删除模板 + Future deleteTemplateInfo({required int id}) async { + final Response res = await apiProvider.deleteTemplateInfo(id); + return LoginEntity.fromJson(res.body); + } } diff --git a/lib/tools/showTipView.dart b/lib/tools/showTipView.dart index c72db1b7..1386d50c 100755 --- a/lib/tools/showTipView.dart +++ b/lib/tools/showTipView.dart @@ -79,11 +79,11 @@ class ShowTipView { content: Text(contentStr), actions: [ CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.cancel!.tr), + child: Text('取消', style: TextStyle(color: AppColors.mainColor)), onPressed: Get.back, ), CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.sure!.tr), + child: Text('确定', style: TextStyle(color: AppColors.mainColor)), onPressed: () { Get.back(); sureClick(); @@ -96,7 +96,8 @@ class ShowTipView { } void showTFViewAlertDialog(TextEditingController controller, String title, - String tipTitle, Function sureClick, {List? inputFormatters}) { + String tipTitle, Function sureClick, + {List? inputFormatters}) { // 点击删除 开始扫描 showDialog( context: Get.context!,