QinGang_interested/lib/pages/notif/notif_detail_page.dart

190 lines
6.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart';
import 'package:qhd_prevention/customWidget/custom_button.dart';
import 'package:qhd_prevention/customWidget/toast_util.dart';
import 'package:qhd_prevention/http/modules/notif_api.dart';
import 'package:qhd_prevention/pages/mine/webViewPage.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/h_colors.dart';
import 'package:qhd_prevention/tools/tools.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../http/ApiService.dart';
class NotifDetailPage extends StatefulWidget {
const NotifDetailPage(this.item, this.selectedTab, {super.key,required this.onClose});
final Function(String) onClose; // 回调函数
final dynamic item;
final int selectedTab;
@override
State<NotifDetailPage> createState() => _NotifDetailPageState(item,selectedTab,onClose);
}
class _NotifDetailPageState extends State<NotifDetailPage> {
_NotifDetailPageState(this.item, this.selectedTab,this.onClose);
final Function(String) onClose; // 回调函数
final dynamic item;
final int selectedTab;
String title="";
String time="";
String text="";
bool isShowReply=false;
String replyText="";
String noticeReadId='';
@override
void initState() {
super.initState();
if(0==selectedTab){
_getNotifDetail();
}else{
_getNotifEnterpriseDetail();
}
}
Future<void> _getNotifDetail() async {
// LoadingDialogHelper.show();
try {
final result = await NotifApi.getNoticeDetail(item['noticeId']);
if (result['success']) {
final dynamic newList = result['data'] ;
setState(() {
title= newList['title']??'';
time= newList['publishTime']??'';
text= newList['content']??'';
isShowReply=newList['requireReply']==1?true:false;
noticeReadId=newList['noticeReadId']??'';
replyText=newList['replyContent']??'';
});
if(newList['readStatus']!='1'){
final resultTwo = await NotifApi.saveReadNoticeDetail(item['noticeId']);
if (result['success']) {
noticeReadId = resultTwo['data'] ?? '';
}
}
}
} catch (e) {
print('加载出错: $e');
}
}
Future<void> _getNotifEnterpriseDetail() async {
// LoadingDialogHelper.show();
try {
// final result = await HiddenDangerApi.getNotifEnterpriseDetail(item['NOTICECORPUSERID_ID']);
// if (result['result'] == 'success') {
// final dynamic newList = result['pd'] ;
// setState(() {
// title= newList['SYNOPSIS'];
// time= newList['CREATTIME'];
// text= newList['CONTENT'];
// });
// }
} catch (e) {
print('加载出错: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppbar(title: "通知详情"),
body: SafeArea(
child: Container(
// color: Colors.white,
child: Padding(
padding: EdgeInsets.all(10),
child: Card(
child: Container(
width: double.infinity, // 铺满父容器
color: Colors.white,
padding: const EdgeInsets.all(15),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, // 左对齐
children: [
Padding(
padding: EdgeInsets.only(left: 10,right: 10),
child: Text(title,style: TextStyle(color: Colors.black,fontSize: 16,fontWeight: FontWeight.bold),),
),
SizedBox(height: 8),
Padding(
padding: EdgeInsets.only(left: 10,right: 10),
child: Text(time,),
),
SizedBox(height: 8),
Html(
data: text,
),
SizedBox(height: 8),
if(isShowReply&&replyText.isEmpty)
CustomButton(
height: 35,
margin: EdgeInsets.only(right: 10),
onPressed: () async {
final confirmed = await CustomAlertDialog.showInput(
context,
title: "回复",
hintText: '输入内容',
cancelText: '关闭',
confirmText: '确定',
);
if (confirmed != null&&confirmed.isNotEmpty) {
//确定回复
// ToastUtil.showNormal(context, confirmed);
_replyContent(confirmed);
}
},
backgroundColor: h_AppBarColor(),
textStyle: const TextStyle(color: Colors.white),
buttonStyle: ButtonStyleType.primary,
text: '回复',
),
],
),
),
),
),
),
),
),
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
onClose('关闭详情'); // 触发回调
}
Future<void> _replyContent(String content) async {
try {
LoadingDialogHelper.show();
final result = await NotifApi.replyContent(noticeReadId,content);
LoadingDialogHelper.hide();
if (result['success']) {
ToastUtil.showNormal(context, '回复成功');
Navigator.pop(context);
// onClose('关闭详情'); // 触发回调
}
} catch (e) {
print('加载出错: $e');
}
}
}