detail.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'dart:io';
  2. import 'package:easy_localization/easy_localization.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:open_file/open_file.dart';
  5. import 'package:telnow_mobile_new/src/api/api_auth_provider.dart';
  6. import 'package:telnow_mobile_new/src/api/jwt_token.dart';
  7. import 'package:telnow_mobile_new/src/layouts/components/template.dart';
  8. import 'package:telnow_mobile_new/src/utils/U.dart';
  9. import 'package:translator/translator.dart';
  10. class DetailFunction{
  11. final ApiAuthProvider apiAuthProvider = ApiAuthProvider();
  12. final JwtToken token = JwtToken();
  13. final translator = GoogleTranslator();
  14. Future getMission(BuildContext context, list) async{
  15. var userData = await token.getUserData(context);
  16. var data = list;
  17. if (data['datetimeScheduled'] != null && data['datetimeScheduled'] != '' && data['noteFormat'] == 'DATE') {
  18. var date = data['datetimeScheduled'];
  19. data['datetimeScheduled'] = DateFormat('dd MMM yyyy HH:mm', 'id').format(DateTime.parse(date));
  20. }
  21. data['noteStartTranslate'] = '';
  22. data['noteFinishTranslate'] = '';
  23. data['noteCompleteTranslate'] = '';
  24. data['noteCancelTranslate'] = '';
  25. var locale = context.locale.toString() == 'zh' ? 'zh-cn' : context.locale.toString();
  26. if (data['noteStart'] == 'transferNoteBySystem'){
  27. data['noteStart'] = 'transferNoteBySystem'.tr();
  28. } else if (data['noteStart'] == 'escalationNoteBySystem'){
  29. data['noteStart'] = 'escalationNoteBySystem'.tr();
  30. } else{
  31. if(U.autoTranslate() && data['noteStart'] != null && data['noteStart'] != ''){
  32. var translate = await translator.translate(data['noteStart'], to: locale);
  33. data['noteStartTranslate'] = translate.text;
  34. }
  35. }
  36. if(U.autoTranslate() && data['noteFinish'] != null && data['noteFinish'] != ''){
  37. var translate = await translator.translate(data['noteFinish'], to: locale);
  38. data['noteFinishTranslate'] = translate.text;
  39. }
  40. if(U.autoTranslate() && data['noteComplete'] != null && data['noteComplete'] != ''){
  41. var translate = await translator.translate(data['noteComplete'], to: locale);
  42. data['noteCompleteTranslate'] = translate.text;
  43. }
  44. if(U.autoTranslate() && data['noteCancel'] != null && data['noteCancel'] != ''){
  45. var translate = await translator.translate(data['noteCancel'], to: locale);
  46. data['noteCancelTranslate'] = translate.text;
  47. }
  48. data['_collaboratorDataFilter'] = data['_collaboratorData'].where((el) => el['status'] == 'ACCEPTED').toList();
  49. return {
  50. 'user': userData,
  51. 'list': data
  52. };
  53. }
  54. openAttachment(list) async{
  55. var filePath = await token.getPath()+'/TelNow/Files/';
  56. if(!File(filePath+getFileName(list['responseAttachment'])).existsSync()){
  57. // print("file isnot ready yet");
  58. await apiAuthProvider.downloadImage(list['responseAttachment'], filePath+getFileName(list['responseAttachment']));
  59. }
  60. await OpenFile.open(filePath+getFileName(list['responseAttachment']));
  61. }
  62. getFileName(pdfUrl){
  63. var imgSplit = pdfUrl.toString().split('/');
  64. return imgSplit[imgSplit.length-1];
  65. }
  66. cancelRequest(BuildContext context, list, controllerNote){
  67. var note = controllerNote.text.trim();
  68. if (note.length > 128) {
  69. showError(context, 'noteLongAlert'.tr());
  70. }
  71. else{
  72. dialogConfirm(context: context, title: 'buttonCancel'.tr(), text: 'confirmCancel'.tr(), actionYes: ()async{
  73. showLoading(context);
  74. var data = {
  75. 'note': controllerNote.text.trim(),
  76. };
  77. var res = await apiAuthProvider.postData('/api/requestHistories/search/request/cancel/'+list['ticketNo'], null, data, context);
  78. if(res != null){
  79. closeLoading(context);
  80. navigateBack(context, exc: true);
  81. }
  82. else{
  83. closeLoading(context);
  84. }
  85. });
  86. }
  87. }
  88. }