incidentDetailCtrl.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. app.controller('incidentDetailCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", '$parse', "$injector", "$aside", 'toaster', 'api_simple', 'api_wechatfile', 'api_text', 'up_down_file', function ($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, $parse, $injector, $aside, toaster, api_simple, api_wechatfile, api_text, up_down_file) {
  3. $scope.langs = i18nService.getAllLangs();
  4. $scope.lang = 'zh-cn';
  5. i18nService.setCurrentLang($scope.lang);
  6. // todo
  7. // 事件id
  8. $scope.incidentId = (/^\d+$/.test($stateParams.id)) ? parseInt($stateParams.id, 10): undefined;
  9. // 事件详情对象
  10. $scope.model = {};
  11. // 事件报修图片
  12. $scope.requestImgs = [];
  13. // 事件处理图片
  14. $scope.userImgs = [];
  15. // 事件处理节点
  16. $scope.followData = [];
  17. // 获取事件详情
  18. $scope.getData = function(incidentId){
  19. api_simple.fetchData('incident', incidentId).then(res => {
  20. if(res.status == 200){
  21. $scope.model = res.data || {};
  22. if ($scope.model.id) {
  23. api_wechatfile.listAttachment("wechatRequesterIncident", $scope.model.id).then( (res) => {
  24. $scope.requestImgs = res.data || [];
  25. });
  26. }
  27. if ($scope.model.id) {
  28. api_wechatfile.listAttachment("incident", $scope.model.id).then( (res) => {
  29. $scope.userImgs = res.data || [];
  30. });
  31. }
  32. if ($scope.model.id) {
  33. api_wechatfile.listAttachment("handleAttachment", $scope.model.id).then( (res) => {
  34. $scope.attachments = res.data || [];
  35. });
  36. }
  37. if ($scope.model.id) {
  38. let postData = {
  39. idx: 0,
  40. sum: 9999,
  41. incidentLog: {
  42. incidentId: $scope.model.id,
  43. }
  44. }
  45. api_simple.fetchDataList('incidentLog', postData).then(function (result) {
  46. if (result.status == 200) {
  47. let newData = Restangular.stripRestangular(result);
  48. $scope.followData = newData.list || [];
  49. }
  50. });
  51. }
  52. }
  53. })
  54. }
  55. // 预览图片
  56. $scope.preview = function (type, url, idx) {
  57. let title = $scope[type][idx].title;
  58. $modal.open({
  59. backdrop: false,
  60. templateUrl: "assets/views/customform/tpl/ui-showimage.html",
  61. controller: function ($scope, $rootScope, scope, $modalInstance) {
  62. $scope.title = title;
  63. $scope.imageurl = $rootScope.attachmentAddressSplicing(url);
  64. $scope.cancel = function () {
  65. $modalInstance.dismiss("cancel");
  66. };
  67. },
  68. resolve: {
  69. scope: function () {
  70. return $scope;
  71. },
  72. },
  73. });
  74. };
  75. // 转换协同人
  76. $scope.transferSynergetic = function(synergetic){
  77. return (synergetic && synergetic.length) ? synergetic.map(v => v.name).join(',') : ''
  78. }
  79. // 下载
  80. $scope.download = function (contentId, filename, token) {
  81. //附件下载
  82. var downUrl = up_down_file
  83. .downloadAttachment("common/common/downloadAttachment", token)
  84. .getRequestedUrl();
  85. var a = document.createElement("a");
  86. a.href = downUrl;
  87. a.target = "_blank";
  88. a.download = filename;
  89. document.body.appendChild(a);
  90. a.click();
  91. };
  92. // 转换处理人
  93. $scope.transferUser = function(incidentData){
  94. if(incidentData.state && incidentData.state.value == 'pending' && incidentData.currentLog){
  95. return incidentData.currentLog.workerName;
  96. }else if(incidentData.state && incidentData.state.value != 'pending' && incidentData.handlingPersonnelUser){
  97. return incidentData.handlingPersonnelUser.name;
  98. }else{
  99. return '';
  100. }
  101. }
  102. // 拨打电话
  103. $scope.dialout = function (teleno) {
  104. $rootScope.callout = 2;
  105. if (localStorage.getItem('fenjiNumber')) {
  106. $rootScope.toggle('off-sidebar');
  107. }else if(localStorage.getItem('hk_phone')){
  108. var gid = "@0"
  109. var telephone = '9' + teleno
  110. $rootScope.callout = 2;
  111. if ($rootScope.takes) {
  112. api_text.dialout($rootScope.takes, gid, telephone).then(function (data) {
  113. if (data.errno == 0) {
  114. $rootScope.status = 6;
  115. }
  116. })
  117. } else {
  118. SweetAlert.swal({
  119. title: "呼叫失败",
  120. text: "请先签入呼叫中心!",
  121. type: "error",
  122. confirmButtonColor: "#DD6B55"
  123. });
  124. }
  125. } else {
  126. SweetAlert.swal({
  127. title: "呼叫失败",
  128. text: "请先签入呼叫中心!",
  129. type: "error",
  130. confirmButtonColor: "#DD6B55",
  131. });
  132. }
  133. };
  134. // 关闭
  135. $scope.closeModel = function () {
  136. $state.go('app.incident.list', {});
  137. };
  138. // init
  139. $scope.init = function(){
  140. $scope.getData($scope.incidentId);
  141. }
  142. $scope.incidentId && $scope.init();
  143. }]);