service_formCtrl.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. 'use strict';
  2. app.controller('service_formCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "SweetAlert", "Restangular", "api_report", "api_statistic", "moment", 'api_user_data', 'api_event_form', 'api_bpm', function ($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, SweetAlert, Restangular, api_report, api_statistic, moment, api_user_data, api_event_form, api_bpm) {
  3. //默认显示综合统计
  4. $scope.tap = 'ZHTJ';
  5. //默认显示上一周
  6. $scope.searchstate = 'none';
  7. //日期选择
  8. $scope.nowtimes = moment().format('YYYY-MM-DD')//当前日期;
  9. //上周
  10. $scope.week = function () {
  11. $scope.searchstate = "week";
  12. var weeks = new Date().getDay();
  13. $scope.starttimesModel = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYY-MM-DD');
  14. $scope.endtimesModel = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYY-MM-DD');
  15. }
  16. //上月
  17. $scope.month = function () {
  18. $scope.searchstate = "month";
  19. $scope.starttimesModel = moment().startOf('month').add(-1, 'M').format('YYYY-MM-DD');
  20. $scope.endtimesModel = moment().endOf('month').add(-1, 'M').format('YYYY-MM-DD');
  21. }
  22. //去年
  23. $scope.year = function () {
  24. $scope.searchstate = "year";
  25. $scope.starttimesModel = moment().startOf('year').add(-1, 'y').format('YYYY-MM-DD');
  26. $scope.endtimesModel = moment().endOf('year').add(-1, 'y').format('YYYY-MM-DD');
  27. }
  28. // 今天
  29. $scope.today = function () {
  30. $scope.searchstate = "today";
  31. $scope.starttimesModel = moment().format('YYYY-MM-DD');
  32. $scope.endtimesModel = moment().format('YYYY-MM-DD');
  33. }
  34. //近N日
  35. $scope.day = function (num) {
  36. num = num > 1 ? num : 1;
  37. $scope.searchstate = "none";
  38. $scope.starttimesModel = moment().subtract(num, "days").format("YYYY-MM-DD");
  39. $scope.endtimesModel = moment().subtract(1, "days").format("YYYY-MM-DD");
  40. }
  41. //默认显示最近7天
  42. $scope.day(7);
  43. //选择上一周,上个月,去年
  44. $scope.chooseDate = function (date) {
  45. switch (date) {
  46. case 'week':
  47. $scope.week();
  48. break;
  49. case 'month':
  50. $scope.month();
  51. break;
  52. case 'year':
  53. $scope.year();
  54. break;
  55. case 'today':
  56. $scope.today();
  57. break;
  58. }
  59. };
  60. /**
  61. *日历
  62. */
  63. //打开开始日期选择框
  64. $scope.startOpen = function ($event) {
  65. $event.preventDefault();
  66. $event.stopPropagation();
  67. $scope.endOpened = false;
  68. $scope.startOpened = !$scope.startOpened;
  69. };
  70. //打开结束日期选择框
  71. $scope.endOpen = function ($event) {
  72. $event.preventDefault();
  73. $event.stopPropagation();
  74. $scope.startOpened = false;
  75. $scope.endOpened = !$scope.endOpened;
  76. };
  77. //重置
  78. $scope.reload = function (isReload) {
  79. //点击重置时传true,切换tab传false
  80. if (isReload) {
  81. $scope.day(7);
  82. }
  83. $scope.searchstate = 'none';
  84. $scope.sortActive = 'totaltop';
  85. $scope.name = 'total';//表格排序,字段名称
  86. $scope.type = 'desc';//表格排序,排序方式desc,asc
  87. $scope.direction = 'top';//箭头方向 top,bottom
  88. switch ($scope.tap) {
  89. case 'ZHTJ'://综合统计
  90. $scope.mdxquery('total', 'desc');
  91. break;
  92. case 'DHTJ'://电话统计
  93. $scope.mdxquery('total', 'desc');
  94. break;
  95. case 'WEB'://微信/WEB统计
  96. $scope.mdxquery('total', 'desc');
  97. break;
  98. case 'DHLYTJ'://电话留言统计
  99. $scope.mdxquery('total', 'desc');
  100. break;
  101. case 'DHCHTJ'://电话查号统计
  102. $scope.mdxquery('total', 'desc');
  103. break;
  104. }
  105. };
  106. //选择类型,综合统计,电话统计,微信/WEB统计,电话留言统计
  107. $scope.active = function (name) {
  108. $scope.tap = name;
  109. $scope.reload(false);
  110. };
  111. //综合统计,无限滚动加载
  112. $scope.topEndComplete = function () {
  113. console.log('滚动');
  114. };
  115. // 请求人
  116. // api_user_data.fetchDataList('requester', {
  117. // "idx": 0,
  118. // "sum": 10
  119. // }).then(function (response) {
  120. // if (response) {
  121. // if (response.status = 200) {
  122. // $scope.requester = response.list;
  123. // }
  124. // }
  125. // })
  126. //表格排序------------------------------------------------
  127. $scope.sortActive = '';//表格排序,箭头高亮选中状态
  128. $scope.name = '';//表格排序,字段名称
  129. $scope.type = '';//表格排序,排序方式desc,asc
  130. $scope.direction = '';//箭头方向 top,bottom
  131. /**
  132. * 表格排序
  133. *
  134. * @param {string} name 字段名称
  135. * @param {string} type 排序方式desc,asc
  136. * @param {string} direction 箭头方向 top,bottom
  137. */
  138. $scope.tableSort = function (name) {
  139. if ($scope.name == name) {
  140. $scope.type = $scope.type == 'desc' ? 'asc' : 'desc';
  141. $scope.direction = $scope.direction == 'top' ? 'bottom' : 'top';
  142. } else {
  143. $scope.type = 'desc';
  144. $scope.direction = 'top';
  145. }
  146. $scope.name = name;
  147. $scope.sortActive = name + $scope.direction;
  148. $scope.mdxquery(name, $scope.type);
  149. };
  150. $scope.isArrays = function (arr) {
  151. return Array.isArray(arr);
  152. };
  153. //综合统计
  154. $scope.zhtj_list = null;//表格列表
  155. $scope.zhtj_req_total = 0;//请求总数
  156. $scope.zhtj_req_phone = 0;//请求电话总数
  157. $scope.zhtj_req_wxweb = 0;//请求微信/web总数
  158. $scope.zhtj_req_msg = 0;//请求电话留言总数
  159. $scope.zhtj_req_desk = 0;//请求柜台总数
  160. $scope.zhtj_trans_total = 0;//服务台建单数
  161. $scope.zhtj_p_total = 0;//工单转换直接处理数
  162. $scope.zhtj_unp_total = 0;//工单转换处理工单数
  163. //电话统计
  164. $scope.dhtj_list = null;//表格列表
  165. $scope.dhtj_req_total = 0;//来电总数
  166. $scope.dhtj_req_answer = 0;//接听数量
  167. $scope.dhtj_req_miss = 0;//未接数量
  168. $scope.dhtj_p_total = 0;//电话建单总数
  169. $scope.dhtj_p_phone = 0;//直接解决
  170. $scope.dhtj_unp_phone = 0;//派单数量
  171. //微信/WEB统计
  172. $scope.web_list = null;//表格列表
  173. $scope.web_req_total = 0;//微信/WEB报修总数
  174. $scope.web_req_trans = 0;//转换数量
  175. $scope.web_req_reject = 0;//未受理数量
  176. $scope.web_trans_total = 0;//微信/WEB转换总数
  177. $scope.web_p_total = 0;//直接解决
  178. $scope.web_unp_total = 0;//派单
  179. //电话留言统计
  180. $scope.dhlytj_list = null;//表格列表
  181. $scope.dhlytj_req_total = 0;//电话留言总数
  182. $scope.dhlytj_req_trans = 0;//建单总数
  183. $scope.dhlytj_req_reject = 0;//不受理总数
  184. $scope.dhlytj_trans_total = 0;//电话留言转换总数
  185. $scope.dhlytj_p_total = 0;//直接解决总数
  186. $scope.dhlytj_unp_total = 0;//派单总数
  187. //电话查号统计
  188. $scope.dhchtj_list = null;//表格列表
  189. /**
  190. *
  191. *
  192. * @param {string} name 排序字段
  193. * @param {string} type 排序方式 desc,asc
  194. */
  195. $scope.mdxquery = function (name, type) {
  196. if (!name) {
  197. // name = $scope.tap == 'ZHTJ' ? 'accdate' : 'sum';
  198. name = 'total';
  199. }
  200. type = type || 'desc';
  201. switch ($scope.tap) {
  202. case 'ZHTJ'://综合统计
  203. $scope.zhtj_list = null;
  204. // 请求列表
  205. api_event_form.fetchZhtjList({
  206. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  207. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  208. "sortData": name,
  209. "sortType": type
  210. }).then(function (res) {
  211. if (res.stats == 200) {
  212. $scope.zhtj_list = res.dataList || [];//表格列表
  213. $scope.zhtj_req_total = res.title.req_total;//请求总数
  214. $scope.zhtj_req_phone = res.title.req_phone;//请求电话总数
  215. $scope.zhtj_req_wxweb = res.title.req_wxweb;//请求微信/web总数
  216. $scope.zhtj_req_msg = res.title.req_msg;//请求电话留言总数
  217. $scope.zhtj_req_desk = res.title.req_desk;//请求柜台总数
  218. $scope.zhtj_trans_total = res.title.trans_total;//服务台建单数
  219. $scope.zhtj_p_total = res.title.p_total;//工单转换直接处理数
  220. $scope.zhtj_unp_total = res.title.unp_total;//工单转换处理工单数
  221. }
  222. })
  223. break;
  224. case 'DHTJ'://电话统计
  225. $scope.dhtj_list = null;
  226. // 请求列表
  227. api_event_form.fetchDhtjList({
  228. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  229. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  230. "sortData": name,
  231. "sortType": type
  232. }).then(function (res) {
  233. if (res.stats == 200) {
  234. $scope.dhtj_list = res.dataList || [];//表格列表
  235. $scope.dhtj_req_total = res.title.req_total;//来电总数
  236. $scope.dhtj_req_answer = res.title.req_answer;//接听数量
  237. $scope.dhtj_req_miss = res.title.req_miss;//未接数量
  238. $scope.dhtj_p_total = res.title.p_total;//电话建单总数
  239. $scope.dhtj_p_phone = res.title.p_phone;//直接解决
  240. $scope.dhtj_unp_phone = res.title.unp_phone;//派单数量
  241. }
  242. })
  243. break;
  244. case 'WEB'://微信/WEB统计
  245. $scope.web_list = null;
  246. // 请求列表
  247. api_event_form.fetchWebList({
  248. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  249. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  250. "sortData": name,
  251. "sortType": type
  252. }).then(function (res) {
  253. if (res.stats == 200) {
  254. $scope.web_list = res.dataList || [];//表格列表
  255. $scope.web_req_total = res.title.req_total;//微信/WEB报修总数
  256. $scope.web_req_trans = res.title.req_trans;//转换数量
  257. $scope.web_req_reject = res.title.req_reject;//未受理数量
  258. $scope.web_trans_total = res.title.trans_total;//微信/WEB转换总数
  259. $scope.web_p_total = res.title.p_total;//直接解决
  260. $scope.web_unp_total = res.title.unp_total;//派单
  261. }
  262. })
  263. break;
  264. case 'DHLYTJ'://电话留言统计
  265. $scope.dhlytj_list = null;
  266. // 请求列表
  267. api_event_form.fetchDhlytjList({
  268. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  269. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  270. "sortData": name,
  271. "sortType": type
  272. }).then(function (res) {
  273. if (res.stats == 200) {
  274. $scope.dhlytj_list = res.dataList || [];//表格列表
  275. $scope.dhlytj_req_total = res.title.req_total;//电话留言总数
  276. $scope.dhlytj_req_trans = res.title.req_trans;//建单总数
  277. $scope.dhlytj_req_reject = res.title.req_reject;//不受理总数
  278. $scope.dhlytj_trans_total = res.title.trans_total;//电话留言转换总数
  279. $scope.dhlytj_p_total = res.title.p_total;//直接解决总数
  280. $scope.dhlytj_unp_total = res.title.unp_total;//派单总数
  281. }
  282. })
  283. break;
  284. case 'DHCHTJ'://电话查号统计
  285. $scope.dhchtj_list = null;
  286. // 请求列表
  287. api_event_form.fetchDhchtjList({
  288. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  289. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  290. "sortData": name,
  291. "sortType": type
  292. }).then(function (res) {
  293. if (res.stats == 200) {
  294. $scope.dhchtj_list = res.dataList || [];//表格列表
  295. }
  296. })
  297. break;
  298. }
  299. };
  300. // 跳转
  301. $scope.goTo = function(url,data){
  302. $state.go(url,data);
  303. }
  304. $scope.serviceFormTo = function(rowData,type){
  305. var starttimesModel = moment($scope.starttimesModel).format('YYYY-MM-DD');
  306. var endtimesModel = moment($scope.endtimesModel).format('YYYY-MM-DD');
  307. console.log(rowData.userId);
  308. console.log(starttimesModel);
  309. console.log(endtimesModel);
  310. switch(type){
  311. case 'total':
  312. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId});
  313. break;
  314. case 'p_total':
  315. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, isDirectProcess:1});
  316. break;
  317. case 'unp_total':
  318. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, isDirectProcess:0});
  319. break;
  320. case 'handle_phone':
  321. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'phone'});
  322. break;
  323. case 'handle_wxweb':
  324. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'im'});
  325. break;
  326. case 'handle_msg':
  327. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'record'});
  328. break;
  329. case 'handle_desk':
  330. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'desk'});
  331. break;
  332. case 'handle_other':
  333. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'other'});
  334. break;
  335. case 'handle_discover':
  336. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'discover'});
  337. break;
  338. case 'handle_leader':
  339. $scope.goTo('app.incident.list',{tab:'all',date:starttimesModel + 'to' + endtimesModel, acceptorId:rowData.userId, source:'leader'});
  340. break;
  341. }
  342. }
  343. //导出
  344. $scope.export = function () {
  345. var postData = {
  346. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  347. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  348. "sortData": $scope.name,
  349. "sortType": $scope.type,
  350. report: {}
  351. }
  352. switch ($scope.tap) {
  353. case 'ZHTJ'://综合统计
  354. postData.key = 'mdv2_service_repot_all';
  355. postData.titles = ['人员', '建单数量', '直接处理数量', '处理工单数', '电话建单数', '微信/报修建单', '留言建单', '柜台建单', '其他方式建单', '主动发现建单', '领导指派建单'];
  356. break;
  357. case 'DHTJ'://电话统计
  358. postData.key = 'mdv2_service_repot_phone';
  359. postData.titles = ['人员', '接听数量', '建单数量', '直接解决', '派单数量'];
  360. break;
  361. case 'WEB'://微信/WEB统计
  362. postData.key = 'mdv2_service_repot_wechat_web';
  363. postData.titles = ['人员', '受理报修数', '不受理数', '转换数量', '直接解决数量', '派单数量'];
  364. break;
  365. case 'DHLYTJ'://电话留言统计
  366. postData.key = 'mdv2_service_repot_msg';
  367. postData.titles = ['人员', '受理总数', '不受理总数', '建单总数', '直接解决总数', '派单总数']
  368. break;
  369. }
  370. var wt_url = api_bpm.downDataModel('report', 1).getRequestedUrl()
  371. $http({
  372. url: wt_url,
  373. method: 'POST',
  374. data: JSON.stringify(postData),
  375. headers: {
  376. 'Accept': '*/*'
  377. },
  378. responseType: 'arraybuffer'
  379. }).success(function (data, status, headers, config) {
  380. var fileName = '';
  381. switch ($scope.tap) {
  382. case 'ZHTJ'://综合统计
  383. fileName = '综合统计';
  384. break;
  385. case 'DHTJ'://电话统计
  386. fileName = '电话统计';
  387. break;
  388. case 'WEB'://微信/WEB统计
  389. fileName = '微信/WEB统计';
  390. break;
  391. case 'DHLYTJ'://电话留言统计
  392. fileName = '电话留言统计';
  393. break;
  394. }
  395. // var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1];
  396. var file = new Blob([data], {
  397. type: 'application/vnd.ms-excel'
  398. });
  399. var fileURL = URL.createObjectURL(file);
  400. var a = document.createElement('a');
  401. a.href = fileURL;
  402. a.target = '_blank';
  403. a.download = fileName + '.xls';
  404. document.body.appendChild(a);
  405. a.click();
  406. }).error(function (data, status, headers, config) {
  407. });
  408. };
  409. //初始化
  410. $scope.mdxquery('total', 'desc');
  411. $scope.sortActive = 'totaltop';
  412. $scope.name = 'total';//表格排序,字段名称
  413. $scope.type = 'desc';//表格排序,排序方式desc,asc
  414. $scope.direction = 'top';//箭头方向 top,bottom
  415. }])