recordCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. 'use strict';
  2. app.controller('recordCtrl', ["$scope", "i18nService", "$rootScope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_data", "api_text", "api_user_data", function($scope, i18nService, $rootScope, $state, $timeout, $interval, $modal, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_data, api_text, api_user_data) {
  3. $scope.langs = i18nService.getAllLangs();
  4. $scope.lang = 'zh-cn';
  5. i18nService.setCurrentLang($scope.lang);
  6. // $(window).resize(function() {
  7. // // console.log("1111")
  8. // });
  9. var loginUser = $rootScope.user;
  10. // var voiceurl=$rootScope.audioiIp;
  11. // delete $rootScope.user.authority;
  12. var pdKey = $state.current.pdKey;
  13. $scope.gridOptions = {};
  14. $scope.gridOptions.data = 'myData';
  15. $scope.gridOptions.enableColumnResizing = true;
  16. $scope.gridOptions.enableFiltering = false;
  17. $scope.gridOptions.enableGridMenu = false;
  18. $scope.gridOptions.enableRowSelection = true;
  19. $scope.gridOptions.showGridFooter = true;
  20. $scope.gridOptions.showColumnFooter = false;
  21. $scope.gridOptions.fastWatch = true;
  22. // $scope.gridOptions.useExternalFiltering=true;
  23. $scope.gridOptions.useExternalPagination = true;
  24. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  25. $scope.gridOptions.paginationPageSize = 10;
  26. $scope.gridOptions.multiSelect = true;
  27. var mun = $scope.gridOptions.paginationPageSize;
  28. // $scope.gridOptions.rowTemplate = "<div ng-click=\"lookFunction(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  29. $scope.gridOptions.rowIdentity = function(row) {
  30. return row.id;
  31. };
  32. $scope.gridOptions.getRowIdentity = function(row) {
  33. return row.id;
  34. };
  35. $scope.transferstate = function(item) {
  36. var handstate = "未处理";
  37. if (item.isExcute) { //未处理
  38. handstate = "已处理";
  39. }
  40. return handstate;
  41. }
  42. $scope.transfersucc = function(item) {
  43. var handstate = "有效";
  44. if (item.isValid) { //未处理
  45. handstate = "无效";
  46. }
  47. return handstate;
  48. }
  49. $scope.transferTime = function(time) {
  50. return moment(time).format('YYYY-MM-DD HH:mm:ss');
  51. }
  52. $scope.gridOptions.columnDefs = [{
  53. name: 'item',
  54. displayName: '序号',
  55. width: 50,
  56. cellTemplate: '<div>' +
  57. '<div class="ui-grid-cell-contents" ng-class="{\'ashy\':row.entity.field1==\'1\'}">{{row.entity.item}}</div>' +
  58. '</div>'
  59. },
  60. {
  61. name: 'recTime',
  62. displayName: '留言时间',
  63. width: '20%',
  64. cellTemplate: '<div>' +
  65. '<div class="ui-grid-cell-contents" ng-class="{\'ashy\':row.entity.field1==\'1\'}">{{grid.appScope.transferTime(row.entity.recTime)}}</div>' +
  66. '</div>'
  67. },
  68. {
  69. name: 'isValid',
  70. displayName: '有效状态',
  71. width: '10%',
  72. cellTemplate: '<div>' +
  73. '<div class="ui-grid-cell-contents" ng-class="{\'ashy\':row.entity.field1==\'1\'}">{{grid.appScope.transfersucc(row.entity)}}</div>' +
  74. '</div>'
  75. }, {
  76. name: 'isExcute',
  77. displayName: '处理状态',
  78. width: '10%',
  79. cellTemplate: '<div>' +
  80. '<div class="ui-grid-cell-contents" ng-class="{\'ashy\':row.entity.field1==\'1\'}">{{grid.appScope.transferstate(row.entity)}}</div>'
  81. },
  82. { name: '操作', cellTemplate: '<recordoperator item="row.entity" colobject="col">' }
  83. ];
  84. $scope.value = 10;
  85. $scope.decrement = function() {
  86. $scope.value = $scope.value - 1;
  87. };
  88. $scope.gridOptions.onRegisterApi = function(gridApi) {
  89. $scope.gridApi = gridApi;
  90. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  91. var filtersData = $scope.memoryfilterData;
  92. filtersData.idx = newPage - 1;
  93. filtersData.sum = pageSize;
  94. $scope.refreshData('expand-right', filtersData);
  95. });
  96. $scope.selected = {
  97. items: []
  98. }
  99. };
  100. $scope.memoryfilterData = defaultFilterData = {
  101. "idx": 0,
  102. "sum": mun
  103. };
  104. /*--------- new incident --------- */
  105. $scope.selectRowFunction = function(recorddata) {
  106. var filterData = { "idx": 0, "sum": 10, "requester": { "mphone": recorddata.ano, "telephone": recorddata.ano, "selectType": 1 } }
  107. api_user_data.fetchDataList('requester', filterData).then(function(data) {
  108. var myData = Restangular.stripRestangular(data);
  109. // $rootScope.phone="";
  110. $rootScope.setbusy();
  111. if (myData.list.length == 0) {
  112. var modalInstance = $modal.open({
  113. templateUrl: 'assets/views/customform/tpl/modal-add-callrequester.html',
  114. controller: function($scope, $modalInstance, api_user_data) {
  115. $scope.title = "新增报修人";
  116. $scope.requester = {};
  117. $scope.onChangeadd = function(searchData) {
  118. $scope.searchKey = searchData.account;
  119. var requesdata = angular.copy(searchData)
  120. if (requesdata.telephone) {
  121. delete requesdata.telephone;
  122. }
  123. angular.extend($scope.requester, requesdata);
  124. }
  125. $scope.refreshUseradd = function(searchKey) { //请求人搜索
  126. $scope.requester.account = searchKey;
  127. $scope.searchData = searchKey;
  128. serchdataadd(searchKey);
  129. }
  130. $scope.getMydata = function(x) {
  131. var reqestdatap = JSON.parse(x[0])
  132. if ($scope.requester.telephone) {
  133. delete reqestdatap.telephone;
  134. }
  135. $scope.searchField = JSON.parse(x[0]).account;
  136. angular.extend($scope.requester, reqestdatap);
  137. }
  138. $scope.getMydataone = function(x) {
  139. $scope.searchField = x;
  140. $scope.requester.account = x;
  141. }
  142. serchdataadd();
  143. function serchdataadd(searchKey) {
  144. if (searchKey) {
  145. var filterData = {
  146. 'requester': {
  147. 'searchKey': searchKey,
  148. },
  149. idx: 0,
  150. sum: 10
  151. };
  152. } else {
  153. var filterData = {
  154. idx: 0,
  155. sum: 10
  156. };
  157. }
  158. api_user_data.fetchDataList('requester', filterData).then(function(response) {
  159. var myData = response;
  160. $scope.myData = myData.list;
  161. });
  162. }
  163. $scope.requester = { 'telephone': recorddata.ano };
  164. $scope.ok = function() {
  165. $modalInstance.close($scope.requester);
  166. };
  167. $scope.cancel = function() {
  168. $modalInstance.dismiss('cancel');
  169. };
  170. },
  171. });
  172. modalInstance.result.then(function(selectedItem) {
  173. if (selectedItem) {
  174. if (selectedItem.telephone && !selectedItem.mphone) {
  175. selectedItem.telephone = angular.copy(selectedItem.mphone);
  176. delete selectedItem.mphone;
  177. }
  178. var data = {
  179. 'requester': selectedItem
  180. };
  181. api_user_data.addData('requester', data).then(function(response) {
  182. if (response.status == 200) {
  183. var data = { 'model': { 'requestershow': response.data, 'recordId': recorddata.id, 'incident': { 'requester': response.data, 'area': response.areaDTO, 'place': response.placeDTO, 'houseNumber': response.houseNumber, 'source': { 'id': 2 } } } }
  184. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  185. }
  186. })
  187. }
  188. });
  189. } else if (myData.list.length == 1) {
  190. var data = { 'model': { 'requestershow': myData.list[0], 'recordId': recorddata.id, 'incident': { 'requester': myData.list[0], 'area': myData.list[0].areaDTO, 'place': myData.list[0].placeDTO, 'houseNumber': myData.list[0].houseNumber, 'source': { 'id': 2 } } } }
  191. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  192. } else {
  193. var modalInstance = $modal.open({
  194. templateUrl: 'assets/views/createincident.html',
  195. controller: function($scope, datas, $modalInstance, api_user_data) {
  196. $scope.title = "请确定报修人";
  197. $scope.requester = myData.list;
  198. $scope.choice = function(requester) {
  199. $modalInstance.dismiss('cancel');
  200. var data = { 'model': { 'requestershow': requester, 'recordId': recorddata.id, 'incident': { 'requester': requester, 'area': requester.areaDTO, 'place': requester.placeDTO, 'houseNumber': requester.houseNumber, 'source': { 'id': 2 } } } }
  201. $state.go('app.incident.title', { 'model': JSON.stringify(data) });
  202. };
  203. $scope.cancel = function() {
  204. $modalInstance.dismiss('cancel');
  205. };
  206. },
  207. resolve: {
  208. datas: function() {
  209. return recorddata;
  210. }
  211. },
  212. size: "lg"
  213. });
  214. }
  215. });
  216. // var formdata = {
  217. // 'model': {
  218. // 'incident': {
  219. // 'source': { 'id': 1 },
  220. // },
  221. // 'recordId': data.id
  222. // }
  223. // }
  224. // $state.go('app.incident.chart', { 'model': JSON.stringify(formdata) });
  225. };
  226. /*--------- Recordings --------- */
  227. // $scope.recordcall = function(data) {
  228. // $scope.oldRecord(data);
  229. // var modalInstance = $modal.open({
  230. // templateUrl: 'assets/views/incident/tpl/audio.html',
  231. // controller: function($rootScope, $scope, $modalInstance, $sce) {
  232. // $scope.data = {
  233. // "name": "视频",
  234. // "url": callIp + "/recording/recording?recordId=" + data.id
  235. // };
  236. // $rootScope.setbusy();
  237. // $scope.data.url = $sce.trustAsResourceUrl($scope.data.url);
  238. // $scope.cancel = function() {
  239. // $modalInstance.dismiss('cancel');
  240. // // $rootScope.setidle();
  241. // };
  242. // $modalInstance.close();
  243. // }
  244. // });
  245. // modalInstance.result.then(function(result) {
  246. // // $rootScope.setidle();
  247. // }, function(reason) {
  248. // $rootScope.setidle();
  249. // });
  250. // };
  251. //录音
  252. $scope.recordcall = function(data) {
  253. var modalInstance = $modal.open({
  254. backdrop: "static",
  255. templateUrl: 'assets/views/incident/tpl/audio.html',
  256. controller: function($rootScope, $scope, $modalInstance, $sce, $http, api_playservice) {
  257. $rootScope.setbusy();
  258. $scope.datasurl = "";
  259. $http({
  260. url: callIp + "/recording/recording?recordId=" + data.id,
  261. method: 'GET',
  262. headers: {},
  263. }).success(function(data, status, headers, config) {
  264. $scope.data = {
  265. "name": "视频",
  266. "url": $sce.trustAsResourceUrl("http://" + data.rrpath)
  267. };
  268. $scope.datasurl = data.rrpath;
  269. }).error(function(data, status, headers, config) {});
  270. $scope.download = function(contentId, filename) {
  271. $http({
  272. url: "http://" + $scope.datasurl,
  273. method: 'GET',
  274. headers: {
  275. 'Content-type': 'application/octet-stream',
  276. },
  277. responseType: 'arraybuffer'
  278. }).success(function(data, status, headers, config) {
  279. var file = new Blob([data], {
  280. type: 'application/octet-stream'
  281. });
  282. //trick to download store a file having its URL
  283. var fileURL = URL.createObjectURL(file);
  284. var a = document.createElement('a');
  285. a.href = fileURL;
  286. a.target = '_blank';
  287. a.download = filename;
  288. document.body.appendChild(a);
  289. a.click();
  290. }).error(function(data, status, headers, config) {
  291. // console.log(data);
  292. });
  293. }
  294. $scope.cancel = function() {
  295. $modalInstance.dismiss('cancel');
  296. };
  297. $modalInstance.close();
  298. }
  299. });
  300. modalInstance.result.then(function(result) {
  301. // $rootScope.setidle();
  302. }, function(reason) {
  303. $rootScope.setidle();
  304. });
  305. };
  306. /*--------- call --------- */
  307. $scope.recordcallid = function(data) {
  308. var telephone = '9' + data.ano;
  309. $rootScope.callout = 2;
  310. if ($rootScope.takes) {
  311. api_text.dialout($rootScope.takes, "@0", telephone).then(function(data) {
  312. if (data.errno == 0) {
  313. $rootScope.status = 6;
  314. $scope.oldRecord(data);
  315. }
  316. })
  317. } else {
  318. SweetAlert.swal({
  319. title: "呼叫失败",
  320. text: "请先签入呼叫中心!",
  321. type: "error",
  322. confirmButtonColor: "#DD6B55"
  323. });
  324. }
  325. };
  326. /*--------- old record --------- */
  327. $scope.oldRecord = function(data) {
  328. api_bpm_data.updData("hjzxRecord", { 'id': data.id, 'field1': '1', 'isValid': data.isValid, 'isExcute': data.isExcute }).then(function(data) {
  329. if (data.status) {
  330. $scope.refreshData('expand-right', defaultFilterData);
  331. }
  332. });
  333. };
  334. /*--------- record status translate --------- */
  335. $scope.record = function(data) {
  336. var keydata = 0;
  337. if (data.isValid == 1) {
  338. keydata = 0;
  339. } else {
  340. keydata = 1;
  341. }
  342. api_bpm_data.updData("hjzxRecord", { 'id': data.id, 'isValid': keydata, 'isExcute': 1, 'field1': '1' }).then(function(data) {
  343. if (data.status) {
  344. SweetAlert.swal({
  345. title: "提交成功!",
  346. text: "有效状态转换成功!",
  347. type: "success"
  348. }, function() {
  349. $scope.refreshData('expand-right', defaultFilterData);
  350. });
  351. } else {
  352. SweetAlert.swal({
  353. title: "提交失败!",
  354. text: "有效状态转换失败,请重试!",
  355. type: "error"
  356. });
  357. }
  358. }, function() {
  359. $scope.ldloading[style.replace('-', '_')] = false;
  360. });
  361. };
  362. /*--------- double click --------- */
  363. // $scope.onDblClick = function(row) {
  364. // var modelfile = { model: { incident: row.entity } };
  365. // if (row.entity.state == "未转换") {
  366. // angular.extend(modelfile.model.incident, { status: 1 })
  367. // } else {
  368. // angular.extend(modelfile.model.incident, { status: 0 })
  369. // }
  370. // $state.go('app.desk.form_editor', { formKey: 'desk_detail', service: 'api_user_data', model: JSON.stringify(modelfile) });
  371. // };
  372. /*--------- get zhe list data--------- */
  373. var defaultFilterData = {
  374. "idx": 0,
  375. "sum": mun
  376. };
  377. $scope.ldloading = {};
  378. $scope.refreshData = function(style, filterData) {
  379. $scope.ldloading[style.replace('-', '_')] = true;
  380. if (angular.isUndefined(filterData)) {
  381. filterData = defaultFilterData;
  382. }
  383. $scope.myData = [];
  384. $scope.gridOptions['sum'] = filterData.sum;
  385. api_bpm_data.fetchDataList("hjzxRecord", filterData).then(function(data) {
  386. var myData = Restangular.stripRestangular(data);
  387. $scope.gridOptions['totalItems'] = myData.totalNum;
  388. $scope.myData = myData.list;
  389. for (var i = 0; i < $scope.myData.length; i++) {
  390. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  391. }
  392. // console.log($scope.myData)
  393. $scope.ldloading[style.replace('-', '_')] = false;
  394. }, function() {
  395. $scope.ldloading[style.replace('-', '_')] = false;
  396. });
  397. };
  398. $scope.refreshData('expand-right', defaultFilterData);
  399. }]);
  400. /*--------- operation --------- */
  401. app.controller('Recordoperator', ['$rootScope', '$http', '$scope', '$modal', function($rootScope, $http, $scope, $modal) {
  402. $scope.handle = false;
  403. $scope.isvalid = false;
  404. $scope.novalid = false;
  405. if (!$scope.item.isExcute && !$scope.item.isValid) {
  406. $scope.handle = true;
  407. } else { $scope.handle = false; }
  408. if (!$scope.item.isExcute) {
  409. if ($scope.item.isValid) {
  410. $scope.isvalid = true;
  411. $scope.novalid = false;
  412. } else {
  413. $scope.isvalid = false;
  414. $scope.novalid = true;
  415. }
  416. } else {
  417. $scope.isvalid = false;
  418. }
  419. $scope.edit = function() {
  420. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  421. // $scope.doEdit($scope.item.id);
  422. }
  423. $scope.record = function() {
  424. $scope.colobject.grid.appScope.record($scope.item);
  425. // $scope.doEdit($scope.item.id);
  426. }
  427. $scope.recordcall = function() {
  428. $scope.colobject.grid.appScope.recordcall($scope.item);
  429. // $scope.doEdit($scope.item.id);
  430. }
  431. $scope.recordcallid = function() {
  432. $scope.colobject.grid.appScope.recordcallid($scope.item);
  433. // $scope.doEdit($scope.item.id);
  434. }
  435. }]);
  436. app.directive('recordoperator', function() {
  437. return {
  438. restrict: 'E',
  439. scope: {
  440. item: '=',
  441. colobject: '='
  442. },
  443. controller: 'Recordoperator',
  444. template: '<div class="links cl-effect-1 ui-grid-cell-contents pull-left" >' +
  445. '<a ng-click="edit()" ng-show="{{handle}}" class="bianjifont">新建事件</a>' +
  446. '<a ng-click="record()" ng-show="{{isvalid}}&&{{handle}}" class="luyinfont">有效</a>' +
  447. '<a ng-click="record()" ng-show="{{novalid}}&&{{handle}}" class="luyinfont">无效</a>' +
  448. '<a ng-click="recordcall()" class="handlefont">回放</a>' +
  449. '<a ng-click="recordcallid()" class="printfont">回拨</a>' +
  450. '</div>'
  451. };
  452. });