request_success.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. Container(
  167. alignment: Alignment.bottomCenter,
  168. width: U.bodyWidth(context), color: Colors.white,
  169. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
  170. child: buttonTemplate(text: 'btnWait'.tr(), action: ()=>backAction()),
  171. )
  172. ],
  173. ):Container()
  174. ],
  175. ),
  176. );
  177. }
  178. Widget renderRequested(){
  179. if(list['receptionistId'] != null){
  180. if(widget.user['roomAttendant'] && widget.user['userId'] != list['informantUserId'] && widget.user['userId'] == list['receptionistId']){
  181. return Column(
  182. children: [
  183. textHorizontal('requestedFor'.tr(), list['informantName']??'-'),
  184. SizedBox(height: 16),
  185. ],
  186. );
  187. }
  188. if(widget.user['userId'] == list['informantUserId'] && widget.user['userId'] != list['receptionistId']){
  189. return Column(
  190. children: [
  191. textHorizontal('requestedBy'.tr(), list['receptionistName']??'-'),
  192. SizedBox(height: 16),
  193. ],
  194. );
  195. }
  196. }
  197. return Container();
  198. }
  199. getFileName(pdfUrl){
  200. var imgSplit = pdfUrl.toString().split('/');
  201. return imgSplit[imgSplit.length-1];
  202. }
  203. Widget attachment_new(list){
  204. var imageWidth = ((U.bodyWidth(context)-32)/5)-5;
  205. List imageList = [];
  206. if(list['_attachment'] != null){
  207. for(var i = 1; i <= 5; i++){
  208. if(list['_attachment']['_mobileRequestAtt$i'] != null){
  209. imageList.add({'thumb': list['_attachment']['_mobileRequestThumb$i'], 'image': list['_attachment']['_mobileRequestAtt$i']});
  210. }
  211. }
  212. }
  213. return imageList.length > 0 ? Column(
  214. crossAxisAlignment: CrossAxisAlignment.start,
  215. children: [
  216. Text('image'.tr(), style: TextStyle(color: textColor)),
  217. SizedBox(height: 5),
  218. Row(
  219. children: List.generate(imageList.length, (i){
  220. return GestureDetector(
  221. child: Container(
  222. width: imageWidth, height: imageWidth, alignment: Alignment.topRight,
  223. margin: EdgeInsets.only(right: i == 4 ? 0 : 6),
  224. decoration: BoxDecoration(
  225. color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 0.5),
  226. 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)
  227. ),
  228. ),
  229. onTap: ()=>navigateTo(context, PhotoPreviewGallery(title: 'image'.tr(), imageList: imageList, startIndex: i))
  230. );
  231. }),
  232. )
  233. ],
  234. ) : textVertical('image'.tr(), 'noImgAttach'.tr());
  235. }
  236. }
  237. // --------------------------------------------------------------------------------------------------------------------------------------------------------
  238. class MobReqSuccessPendingPage extends StatefulWidget {
  239. Map<String, dynamic> data;
  240. final bool fromSearch;
  241. MobReqSuccessPendingPage({required this.data, this.fromSearch = false, super.key});
  242. @override
  243. State<MobReqSuccessPendingPage> createState() => _MobReqSuccessPendingPageState();
  244. }
  245. class _MobReqSuccessPendingPageState extends State<MobReqSuccessPendingPage> {
  246. bool _timeLimit = false;
  247. @override
  248. Widget build(BuildContext context) {
  249. return Scaffold(
  250. backgroundColor: backgroundColor,
  251. appBar: AppBar(
  252. elevation: 0,
  253. bottomOpacity: 0,
  254. backgroundColor: backgroundColor,
  255. leading: GestureDetector(
  256. child: Icon(Icons.close_rounded, color: textColor),
  257. onTap: ()=>backAction(),
  258. ),
  259. titleSpacing: 0,
  260. title: Text('detail'.tr(), style: TextStyle(color: textColor, fontSize: 17, fontWeight: FontWeight.w500), overflow: TextOverflow.ellipsis),
  261. ),
  262. body: Column(
  263. children: [
  264. divider(),
  265. Expanded(
  266. child: widget.data.isNotEmpty?Container(
  267. alignment: Alignment.topCenter,
  268. width: U.bodyWidth(context),
  269. child: SingleChildScrollView(
  270. padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  271. child: Column(
  272. crossAxisAlignment: CrossAxisAlignment.start,
  273. children: [
  274. Text(widget.data['title'], style: TextStyle(color: textColor, fontWeight: FontWeight.w600)),
  275. requestTiles(
  276. image: widget.data['image'] ?? "null",
  277. title: widget.data[U.langColumn(context, 'sub')],
  278. subtitle: widget.data[U.langColumn(context, 'desc')]??'',
  279. border: true
  280. ),
  281. SizedBox(height: 16),
  282. widget.data['others']?Column(
  283. children: [
  284. textHorizontal('requestedFor'.tr(), widget.data['data']['user_id']),
  285. SizedBox(height: 16),
  286. ],
  287. ):Container(),
  288. textHorizontal('location'.tr(), widget.data['location']),
  289. SizedBox(height: 16),
  290. divider(opacity: 0.05),
  291. SizedBox(height: 16),
  292. attachment_new(widget.data['imageList']),
  293. SizedBox(height: 16),
  294. textVertical('note'.tr(), widget.data['note'] != '' ? widget.data['note'] : '-'),
  295. SizedBox(height: 24),
  296. Container(
  297. width: double.infinity,
  298. padding: EdgeInsets.all(12),
  299. child: Column(
  300. crossAxisAlignment: CrossAxisAlignment.center,
  301. children: [
  302. Icon(Icons.warning_amber_rounded, color: Colors.red),
  303. SizedBox(height: 5),
  304. Text('pending_info_success'.tr(), style: TextStyle(color: textColor), textAlign: TextAlign.center)
  305. ],
  306. ),
  307. decoration: BoxDecoration(
  308. color: Colors.red.withValues(alpha: 0.1),
  309. border: Border.all(color: Colors.red),
  310. borderRadius: BorderRadius.all(Radius.circular(12))
  311. ),
  312. )
  313. ],
  314. ),
  315. ),
  316. ):_timeLimit ? showButton(context) : loadingTemplate(() {if(mounted) setState(()=>_timeLimit=true);},),
  317. ),
  318. Column(
  319. children: [
  320. divider(),
  321. Container(
  322. alignment: Alignment.bottomCenter,
  323. width: U.bodyWidth(context), color: Colors.white,
  324. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
  325. child: buttonTemplate(text: 'btnWait'.tr(), action: ()=>backAction()),
  326. )
  327. ],
  328. )
  329. ],
  330. ),
  331. );
  332. }
  333. Widget attachment_new(List images){
  334. var imageWidth = ((U.bodyWidth(context)-32)/5)-5;
  335. List imageList = [];
  336. images.forEach((element) {
  337. imageList.add(base64Decode(element));
  338. });
  339. return imageList.length > 0 ? Column(
  340. crossAxisAlignment: CrossAxisAlignment.start,
  341. children: [
  342. Text('image'.tr(), style: TextStyle(color: textColor)),
  343. SizedBox(height: 5),
  344. Row(
  345. children: List.generate(imageList.length, (i){
  346. return GestureDetector(
  347. child: Container(
  348. width: imageWidth, height: imageWidth, alignment: Alignment.topRight,
  349. margin: EdgeInsets.only(right: i == 4 ? 0 : 6),
  350. decoration: BoxDecoration(
  351. color: Colors.black12, borderRadius: BorderRadius.all(Radius.circular(5)), border: Border.all(color: Colors.black26, width: 0.5),
  352. image: DecorationImage(image: MemoryImage(imageList[i]), fit: BoxFit.cover)
  353. ),
  354. ),
  355. onTap: ()=>navigateTo(context, PhotoPreviewGallery(title: 'image'.tr(), imageList: imageList, startIndex: i, isUrl: false))
  356. );
  357. }),
  358. )
  359. ],
  360. ) : textVertical('image'.tr(), 'noImgAttach'.tr());
  361. }
  362. backAction(){
  363. int count = 0;
  364. int page = widget.fromSearch ? 3 : 2;
  365. Navigator.of(context).popUntil((_) => count++ >= page);
  366. }
  367. }