request_success.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:easy_localization/easy_localization.dart';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_linkify/flutter_linkify.dart';
  7. import 'package:open_file/open_file.dart';
  8. import 'package:telnow_mobile_new/src/api/api_auth_provider.dart';
  9. import 'package:telnow_mobile_new/src/layouts/components/template.dart';
  10. import 'package:telnow_mobile_new/src/utils/U.dart';
  11. import 'package:url_launcher/url_launcher.dart';
  12. class MobReqSuccessPage extends StatefulWidget {
  13. Map<String, dynamic> user;
  14. final String ticketNo;
  15. final bool fromSearch;
  16. MobReqSuccessPage({required this.user, required this.ticketNo, this.fromSearch = false, super.key});
  17. @override
  18. State<MobReqSuccessPage> createState() => _MobReqSuccessPageState();
  19. }
  20. class _MobReqSuccessPageState extends State<MobReqSuccessPage> {
  21. final ApiAuthProvider apiAuthProvider = ApiAuthProvider();
  22. Map<String, dynamic> list = {};
  23. @override
  24. void initState() {
  25. getMission();
  26. // TODO: implement initState
  27. super.initState();
  28. }
  29. getMission() async{
  30. var data = await apiAuthProvider.getData('/api/requestHistories/'+widget.ticketNo, null, context);
  31. if(data != null) {
  32. if (data['datetimeScheduled'] != null && data['datetimeScheduled'] != '' && data['noteFormat'] == 'DATE') {
  33. var date = data['datetimeScheduled'];
  34. data['datetimeScheduled'] = DateFormat('dd MMM yyyy HH:mm', 'id').format(DateTime.parse(date));
  35. }
  36. if (data['noteStart'] == 'escalationNoteBySystem'){
  37. data['noteStart'] = 'escalationNoteBySystem'.tr();
  38. }
  39. setState((){
  40. list = data;
  41. });
  42. }
  43. }
  44. backAction(){
  45. int count = 0;
  46. int page = widget.fromSearch ? 3 : 2;
  47. Navigator.of(context).popUntil((_) => count++ >= page);
  48. }
  49. bool _timeLimit = false;
  50. @override
  51. Widget build(BuildContext context) {
  52. return Scaffold(
  53. backgroundColor: backgroundColor,
  54. appBar: AppBar(
  55. elevation: 0,
  56. bottomOpacity: 0,
  57. backgroundColor: backgroundColor,
  58. leading: GestureDetector(
  59. child: Icon(Icons.close_rounded, color: textColor),
  60. onTap: ()=>backAction(),
  61. ),
  62. titleSpacing: 0,
  63. title: Text('detail'.tr(), style: TextStyle(color: textColor, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  64. ),
  65. body: Column(
  66. children: [
  67. divider(),
  68. Expanded(
  69. child: list.isNotEmpty?Container(
  70. alignment: Alignment.topCenter,
  71. width: U.bodyWidth(context),
  72. child: SingleChildScrollView(
  73. padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  74. child: Column(
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: [
  77. Text(list[U.langColumn(context, 'requestGroupDescription')], style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
  78. requestTiles(
  79. image: list['_requestImage'] ?? "null",
  80. title: list[U.langColumn(context, 'requestSubject')],
  81. subtitle: list[U.langColumn(context, '_subjectDescription')]??'',
  82. border: true
  83. ),
  84. SizedBox(height: 16),
  85. textHorizontal('ticketNumber'.tr(), list['ticketNo'], copy: true),
  86. SizedBox(height: 16),
  87. renderRequested(),
  88. textHorizontal('location'.tr(), list['ipphoneExtLocation']),
  89. SizedBox(height: 16),
  90. divider(opacity: 0.05),
  91. SizedBox(height: 16),
  92. list['autoResponse'] ? Column(
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. Text('note'.tr(), style: TextStyle(color: textColor)),
  96. SizedBox(height: 5),
  97. list['responseText']!=null&&list['responseText']!=''?Linkify(
  98. text: list['responseText'], style: TextStyle(color: textColor, fontSize: 12, fontWeight: FontWeight.w300),
  99. onOpen: (link) async {
  100. if (await canLaunchUrl(Uri.parse(link.url))) {
  101. await launchUrl(Uri.parse(link.url));
  102. }
  103. },
  104. ):Container(),
  105. list['responseAttachment']!=null&&list['responseAttachment']!=''?list['_isPdf']?GestureDetector(
  106. onTap: kIsWeb ? () async{
  107. Uri _url = Uri.parse(list['_mobileResponseAttachment']);
  108. await canLaunchUrl(_url) ? await launchUrl(_url) : print('Could not launch $_url');
  109. // html.window.open(list['responseAttachment'], '_blank');
  110. } : () async{
  111. var filePath = await token.getPath()+'/TelNow/Files/';
  112. if(!File(filePath+getFileName(list['responseAttachment'])).existsSync()){
  113. // print("file isnot ready yet");
  114. await apiAuthProvider.downloadImage(list['responseAttachment'], filePath+getFileName(list['responseAttachment']));
  115. }
  116. await OpenFile.open(filePath+getFileName(list['responseAttachment']));
  117. },
  118. child: Container(
  119. width: double.infinity,
  120. margin: EdgeInsets.only(top: 8),
  121. decoration: BoxDecoration(
  122. color: Colors.white,
  123. border: Border.all(color: Colors.deepOrange),
  124. borderRadius: BorderRadius.all(Radius.circular(12)),
  125. ),
  126. child: Center(
  127. child: Column(
  128. children: [
  129. Icon(Icons.picture_as_pdf, color: Colors.deepOrange, size: 50),
  130. Text('seeAttachment'.tr(), style: TextStyle(color: Colors.black45, fontSize: 12))
  131. ],
  132. ),
  133. )
  134. )
  135. ):GestureDetector(
  136. child: Image.network(list['_mobileResponseAttachment'], fit: BoxFit.cover, width: double.infinity, height: U.bodyWidth(context)/(kIsWeb?2.1:1.7), loadingBuilder:(BuildContext? context, Widget? child,ImageChunkEvent? loadingProgress) {
  137. if (loadingProgress == null) return child!;
  138. return Container(
  139. height: U.bodyWidth(context)/(kIsWeb?2.1:1.7),
  140. child: Center(
  141. child: CircularProgressIndicator(
  142. value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! : null,
  143. ),
  144. ),
  145. );
  146. },
  147. ),
  148. onTap: ()=>navigateTo(context, PhotoPreview('image'.tr(), list['_mobileResponseAttachment'], true))
  149. ):Container()
  150. ],
  151. ) : attachment_new(list),
  152. list['autoResponse'] ? Container() : SizedBox(height: 16),
  153. list['autoResponse'] ? Container() : textVertical('note'.tr(), list['requestNote'] != '' ? list['requestNote'] : '-'),
  154. list['autoResponse'] ? Container() : SizedBox(height: 16),
  155. list['autoResponse'] || list['datetimeScheduled'] == null || list['datetimeScheduled'] == '' ? Container() : Text("${"scheduleMessage".tr()} ${list['datetimeScheduled']}."),
  156. SizedBox(height: 24),
  157. infoContainer('reqSuccessMsg'.tr())
  158. ],
  159. ),
  160. ),
  161. ):_timeLimit ? showButton(context) : loadingTemplate(() {if(mounted) setState(()=>_timeLimit=true);},),
  162. ),
  163. list.isNotEmpty?Column(
  164. children: [
  165. divider(),
  166. SafeArea(
  167. child: Container(
  168. alignment: Alignment.bottomCenter,
  169. width: U.bodyWidth(context), color: Colors.white,
  170. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
  171. child: buttonTemplate(text: 'btnWait'.tr(), action: ()=>backAction()),
  172. ),
  173. )
  174. ],
  175. ):Container()
  176. ],
  177. ),
  178. );
  179. }
  180. Widget renderRequested(){
  181. if(list['receptionistId'] != null){
  182. if(widget.user['roomAttendant'] && widget.user['userId'] != list['informantUserId'] && widget.user['userId'] == list['receptionistId']){
  183. return Column(
  184. children: [
  185. textHorizontal('requestedFor'.tr(), list['informantName']??'-'),
  186. SizedBox(height: 16),
  187. ],
  188. );
  189. }
  190. if(widget.user['userId'] == list['informantUserId'] && widget.user['userId'] != list['receptionistId']){
  191. return Column(
  192. children: [
  193. textHorizontal('requestedBy'.tr(), list['receptionistName']??'-'),
  194. SizedBox(height: 16),
  195. ],
  196. );
  197. }
  198. }
  199. return Container();
  200. }
  201. getFileName(pdfUrl){
  202. var imgSplit = pdfUrl.toString().split('/');
  203. return imgSplit[imgSplit.length-1];
  204. }
  205. Widget attachment_new(list){
  206. var imageWidth = ((U.bodyWidth(context)-32)/5)-5;
  207. List imageList = [];
  208. if(list['_attachment'] != null){
  209. for(var i = 1; i <= 5; i++){
  210. if(list['_attachment']['_mobileRequestAtt$i'] != null){
  211. imageList.add({'thumb': list['_attachment']['_mobileRequestThumb$i'], 'image': list['_attachment']['_mobileRequestAtt$i']});
  212. }
  213. }
  214. }
  215. return imageList.length > 0 ? Column(
  216. crossAxisAlignment: CrossAxisAlignment.start,
  217. children: [
  218. Text('image'.tr(), style: TextStyle(color: textColor)),
  219. SizedBox(height: 5),
  220. Row(
  221. children: List.generate(imageList.length, (i){
  222. return GestureDetector(
  223. child: Container(
  224. width: imageWidth, height: imageWidth, alignment: Alignment.topRight,
  225. margin: EdgeInsets.only(right: i == 4 ? 0 : 6),
  226. decoration: BoxDecoration(
  227. color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 0.5),
  228. image: imageList[i]['thumb'] != null ? DecorationImage(image: NetworkImage(imageList[i]['thumb']), fit: BoxFit.cover) : DecorationImage(image: AssetImage('assets/image/error/ImageNotFound.png'), fit: BoxFit.cover)
  229. ),
  230. ),
  231. onTap: ()=>navigateTo(context, PhotoPreviewGallery(title: 'image'.tr(), imageList: imageList, startIndex: i))
  232. );
  233. }),
  234. )
  235. ],
  236. ) : textVertical('image'.tr(), 'noImgAttach'.tr());
  237. }
  238. }
  239. // --------------------------------------------------------------------------------------------------------------------------------------------------------
  240. class MobReqSuccessPendingPage extends StatefulWidget {
  241. Map<String, dynamic> data;
  242. final bool fromSearch;
  243. MobReqSuccessPendingPage({required this.data, this.fromSearch = false, super.key});
  244. @override
  245. State<MobReqSuccessPendingPage> createState() => _MobReqSuccessPendingPageState();
  246. }
  247. class _MobReqSuccessPendingPageState extends State<MobReqSuccessPendingPage> {
  248. bool _timeLimit = false;
  249. @override
  250. Widget build(BuildContext context) {
  251. return Scaffold(
  252. backgroundColor: backgroundColor,
  253. appBar: AppBar(
  254. elevation: 0,
  255. bottomOpacity: 0,
  256. backgroundColor: backgroundColor,
  257. leading: GestureDetector(
  258. child: Icon(Icons.close_rounded, color: textColor),
  259. onTap: ()=>backAction(),
  260. ),
  261. titleSpacing: 0,
  262. title: Text('detail'.tr(), style: TextStyle(color: textColor, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  263. ),
  264. body: Column(
  265. children: [
  266. divider(),
  267. Expanded(
  268. child: widget.data.isNotEmpty?Container(
  269. alignment: Alignment.topCenter,
  270. width: U.bodyWidth(context),
  271. child: SingleChildScrollView(
  272. padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  273. child: Column(
  274. crossAxisAlignment: CrossAxisAlignment.start,
  275. children: [
  276. Text(widget.data['title'], style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
  277. requestTiles(
  278. image: widget.data['image'] ?? "null",
  279. title: widget.data[U.langColumn(context, 'sub')],
  280. subtitle: widget.data[U.langColumn(context, 'desc')]??'',
  281. border: true
  282. ),
  283. SizedBox(height: 16),
  284. widget.data['others']?Column(
  285. children: [
  286. textHorizontal('requestedFor'.tr(), widget.data['data']['user_id']),
  287. SizedBox(height: 16),
  288. ],
  289. ):Container(),
  290. textHorizontal('location'.tr(), widget.data['location']),
  291. SizedBox(height: 16),
  292. divider(opacity: 0.05),
  293. SizedBox(height: 16),
  294. attachment_new(widget.data['imageList']),
  295. SizedBox(height: 16),
  296. textVertical('note'.tr(), widget.data['note'] != '' ? widget.data['note'] : '-'),
  297. SizedBox(height: 24),
  298. Container(
  299. width: double.infinity,
  300. padding: EdgeInsets.all(12),
  301. child: Column(
  302. crossAxisAlignment: CrossAxisAlignment.center,
  303. children: [
  304. Icon(Icons.warning_amber_rounded, color: Colors.red),
  305. SizedBox(height: 5),
  306. Text('pending_info_success'.tr(), style: TextStyle(color: textColor), textAlign: TextAlign.center)
  307. ],
  308. ),
  309. decoration: BoxDecoration(
  310. color: Colors.red.withValues(alpha: 0.1),
  311. border: Border.all(color: Colors.red),
  312. borderRadius: BorderRadius.all(Radius.circular(12))
  313. ),
  314. )
  315. ],
  316. ),
  317. ),
  318. ):_timeLimit ? showButton(context) : loadingTemplate(() {if(mounted) setState(()=>_timeLimit=true);},),
  319. ),
  320. Column(
  321. children: [
  322. divider(),
  323. SafeArea(
  324. child: Container(
  325. alignment: Alignment.bottomCenter,
  326. width: U.bodyWidth(context), color: Colors.white,
  327. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
  328. child: buttonTemplate(text: 'btnWait'.tr(), action: ()=>backAction()),
  329. ),
  330. )
  331. ],
  332. )
  333. ],
  334. ),
  335. );
  336. }
  337. Widget attachment_new(List images){
  338. var imageWidth = ((U.bodyWidth(context)-32)/5)-5;
  339. List imageList = [];
  340. images.forEach((element) {
  341. imageList.add(base64Decode(element));
  342. });
  343. return imageList.length > 0 ? Column(
  344. crossAxisAlignment: CrossAxisAlignment.start,
  345. children: [
  346. Text('image'.tr(), style: TextStyle(color: textColor)),
  347. SizedBox(height: 5),
  348. Row(
  349. children: List.generate(imageList.length, (i){
  350. return GestureDetector(
  351. child: Container(
  352. width: imageWidth, height: imageWidth, alignment: Alignment.topRight,
  353. margin: EdgeInsets.only(right: i == 4 ? 0 : 6),
  354. decoration: BoxDecoration(
  355. color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 0.5),
  356. image: DecorationImage(image: MemoryImage(imageList[i]), fit: BoxFit.cover)
  357. ),
  358. ),
  359. onTap: ()=>navigateTo(context, PhotoPreviewGallery(title: 'image'.tr(), imageList: imageList, startIndex: i, isUrl: false))
  360. );
  361. }),
  362. )
  363. ],
  364. ) : textVertical('image'.tr(), 'noImgAttach'.tr());
  365. }
  366. backAction(){
  367. int count = 0;
  368. int page = widget.fromSearch ? 3 : 2;
  369. Navigator.of(context).popUntil((_) => count++ >= page);
  370. }
  371. }