service_formCtrl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. }
  102. };
  103. //选择类型,综合统计,电话统计,微信/WEB统计,电话留言统计
  104. $scope.active = function (name) {
  105. $scope.tap = name;
  106. $scope.reload(false);
  107. };
  108. //综合统计,无限滚动加载
  109. $scope.topEndComplete = function () {
  110. console.log('滚动');
  111. };
  112. // 请求人
  113. // api_user_data.fetchDataList('requester', {
  114. // "idx": 0,
  115. // "sum": 10
  116. // }).then(function (response) {
  117. // if (response) {
  118. // if (response.status = 200) {
  119. // $scope.requester = response.list;
  120. // }
  121. // }
  122. // })
  123. //表格排序------------------------------------------------
  124. $scope.sortActive = '';//表格排序,箭头高亮选中状态
  125. $scope.name = '';//表格排序,字段名称
  126. $scope.type = '';//表格排序,排序方式desc,asc
  127. $scope.direction = '';//箭头方向 top,bottom
  128. /**
  129. * 表格排序
  130. *
  131. * @param {string} name 字段名称
  132. * @param {string} type 排序方式desc,asc
  133. * @param {string} direction 箭头方向 top,bottom
  134. */
  135. $scope.tableSort = function (name) {
  136. if ($scope.name == name) {
  137. $scope.type = $scope.type == 'desc' ? 'asc' : 'desc';
  138. $scope.direction = $scope.direction == 'top' ? 'bottom' : 'top';
  139. } else {
  140. $scope.type = 'desc';
  141. $scope.direction = 'top';
  142. }
  143. $scope.name = name;
  144. $scope.sortActive = name + $scope.direction;
  145. $scope.mdxquery(name, $scope.type);
  146. };
  147. $scope.isArrays = function (arr) {
  148. return Array.isArray(arr);
  149. };
  150. //综合统计
  151. $scope.zhtj_list = null;//表格列表
  152. $scope.zhtj_req_total = 0;//请求总数
  153. $scope.zhtj_req_phone = 0;//请求电话总数
  154. $scope.zhtj_req_wxweb = 0;//请求微信/web总数
  155. $scope.zhtj_req_msg = 0;//请求电话留言总数
  156. $scope.zhtj_req_desk = 0;//请求柜台总数
  157. $scope.zhtj_trans_total = 0;//工单转换总数
  158. $scope.zhtj_p_total = 0;//工单转换直接处理数
  159. $scope.zhtj_unp_total = 0;//工单转换处理工单数
  160. //电话统计
  161. $scope.dhtj_list = null;//表格列表
  162. $scope.dhtj_req_total = 0;//来电总数
  163. $scope.dhtj_req_answer = 0;//接听数量
  164. $scope.dhtj_req_miss = 0;//未接数量
  165. $scope.dhtj_p_total = 0;//电话建单总数
  166. $scope.dhtj_p_phone = 0;//直接解决
  167. $scope.dhtj_unp_phone = 0;//派单数量
  168. //微信/WEB统计
  169. $scope.web_list = null;//表格列表
  170. $scope.web_req_total = 0;//微信/WEB报修总数
  171. $scope.web_req_trans = 0;//转换数量
  172. $scope.web_req_reject = 0;//未受理数量
  173. $scope.web_trans_total = 0;//微信/WEB转换总数
  174. $scope.web_p_total = 0;//直接解决
  175. $scope.web_unp_total = 0;//派单
  176. //电话留言统计
  177. $scope.dhlytj_list = null;//表格列表
  178. $scope.dhlytj_req_total = 0;//电话留言总数
  179. $scope.dhlytj_req_trans = 0;//建单总数
  180. $scope.dhlytj_req_reject = 0;//不受理总数
  181. $scope.dhlytj_trans_total = 0;//电话留言转换总数
  182. $scope.dhlytj_p_total = 0;//直接解决总数
  183. $scope.dhlytj_unp_total = 0;//派单总数
  184. /**
  185. *
  186. *
  187. * @param {string} name 排序字段
  188. * @param {string} type 排序方式 desc,asc
  189. */
  190. $scope.mdxquery = function (name, type) {
  191. if (!name) {
  192. // name = $scope.tap == 'ZHTJ' ? 'accdate' : 'sum';
  193. name = 'total';
  194. }
  195. type = type || 'desc';
  196. switch ($scope.tap) {
  197. case 'ZHTJ'://综合统计
  198. $scope.zhtj_list = null;
  199. // 请求列表
  200. api_event_form.fetchZhtjList({
  201. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  202. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  203. "sortData": name,
  204. "sortType": type
  205. }).then(function (res) {
  206. if (res.stats == 200) {
  207. $scope.zhtj_list = res.dataList || [];//表格列表
  208. $scope.zhtj_req_total = res.title.req_total;//请求总数
  209. $scope.zhtj_req_phone = res.title.req_phone;//请求电话总数
  210. $scope.zhtj_req_wxweb = res.title.req_wxweb;//请求微信/web总数
  211. $scope.zhtj_req_msg = res.title.req_msg;//请求电话留言总数
  212. $scope.zhtj_req_desk = res.title.req_desk;//请求柜台总数
  213. $scope.zhtj_trans_total = res.title.trans_total;//工单转换总数
  214. $scope.zhtj_p_total = res.title.p_total;//工单转换直接处理数
  215. $scope.zhtj_unp_total = res.title.unp_total;//工单转换处理工单数
  216. }
  217. })
  218. break;
  219. case 'DHTJ'://电话统计
  220. $scope.dhtj_list = null;
  221. // 请求列表
  222. api_event_form.fetchDhtjList({
  223. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  224. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  225. "sortData": name,
  226. "sortType": type
  227. }).then(function (res) {
  228. if (res.stats == 200) {
  229. $scope.dhtj_list = res.dataList || [];//表格列表
  230. $scope.dhtj_req_total = res.title.req_total;//来电总数
  231. $scope.dhtj_req_answer = res.title.req_answer;//接听数量
  232. $scope.dhtj_req_miss = res.title.req_miss;//未接数量
  233. $scope.dhtj_p_total = res.title.p_total;//电话建单总数
  234. $scope.dhtj_p_phone = res.title.p_phone;//直接解决
  235. $scope.dhtj_unp_phone = res.title.unp_phone;//派单数量
  236. }
  237. })
  238. break;
  239. case 'WEB'://微信/WEB统计
  240. $scope.web_list = null;
  241. // 请求列表
  242. api_event_form.fetchWebList({
  243. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  244. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  245. "sortData": name,
  246. "sortType": type
  247. }).then(function (res) {
  248. if (res.stats == 200) {
  249. $scope.web_list = res.dataList || [];//表格列表
  250. $scope.web_req_total = res.title.req_total;//微信/WEB报修总数
  251. $scope.web_req_trans = res.title.req_trans;//转换数量
  252. $scope.web_req_reject = res.title.req_reject;//未受理数量
  253. $scope.web_trans_total = res.title.trans_total;//微信/WEB转换总数
  254. $scope.web_p_total = res.title.p_total;//直接解决
  255. $scope.web_unp_total = res.title.unp_total;//派单
  256. }
  257. })
  258. break;
  259. case 'DHLYTJ'://电话留言统计
  260. $scope.dhlytj_list = null;
  261. // 请求列表
  262. api_event_form.fetchDhlytjList({
  263. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  264. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  265. "sortData": name,
  266. "sortType": type
  267. }).then(function (res) {
  268. if (res.stats == 200) {
  269. $scope.dhlytj_list = res.dataList || [];//表格列表
  270. $scope.dhlytj_req_total = res.title.req_total;//电话留言总数
  271. $scope.dhlytj_req_trans = res.title.req_trans;//建单总数
  272. $scope.dhlytj_req_reject = res.title.req_reject;//不受理总数
  273. $scope.dhlytj_trans_total = res.title.trans_total;//电话留言转换总数
  274. $scope.dhlytj_p_total = res.title.p_total;//直接解决总数
  275. $scope.dhlytj_unp_total = res.title.unp_total;//派单总数
  276. }
  277. })
  278. break;
  279. }
  280. };
  281. //导出
  282. $scope.export = function () {
  283. var postData = {
  284. "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'),
  285. "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'),
  286. "sortData": $scope.name,
  287. "sortType": $scope.type,
  288. report: {}
  289. }
  290. switch ($scope.tap) {
  291. case 'ZHTJ'://综合统计
  292. postData.key = 'mdv2_service_repot_all';
  293. postData.titles = ['人员', '建单数量', '直接处理数量', '处理工单数', '电话接听数', '微信/web报修处理数', '留言处理数', '柜台受理数'];
  294. break;
  295. case 'DHTJ'://电话统计
  296. postData.key = 'mdv2_service_repot_phone';
  297. postData.titles = ['人员', '接听数量', '建单数量', '直接解决', '派单数量'];
  298. break;
  299. case 'WEB'://微信/WEB统计
  300. postData.key = 'mdv2_service_repot_wechat_web';
  301. postData.titles = ['人员', '受理报修数', '不受理数', '转换数量', '直接解决数量', '派单数量'];
  302. break;
  303. case 'DHLYTJ'://电话留言统计
  304. postData.key = 'mdv2_service_repot_msg';
  305. postData.titles = ['人员', '受理总数', '不受理总数', '建单总数', '直接解决总数', '派单总数']
  306. break;
  307. }
  308. var wt_url = api_bpm.downDataModel('report', 1).getRequestedUrl()
  309. $http({
  310. url: wt_url,
  311. method: 'POST',
  312. data: JSON.stringify(postData),
  313. headers: {
  314. 'Accept': '*/*'
  315. },
  316. responseType: 'arraybuffer'
  317. }).success(function (data, status, headers, config) {
  318. var fileName = '';
  319. switch ($scope.tap) {
  320. case 'ZHTJ'://综合统计
  321. fileName = '综合统计';
  322. break;
  323. case 'DHTJ'://电话统计
  324. fileName = '电话统计';
  325. break;
  326. case 'WEB'://微信/WEB统计
  327. fileName = '微信/WEB统计';
  328. break;
  329. case 'DHLYTJ'://电话留言统计
  330. fileName = '电话留言统计';
  331. break;
  332. }
  333. // var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1];
  334. var file = new Blob([data], {
  335. type: 'application/vnd.ms-excel'
  336. });
  337. var fileURL = URL.createObjectURL(file);
  338. var a = document.createElement('a');
  339. a.href = fileURL;
  340. a.target = '_blank';
  341. a.download = fileName + '.xls';
  342. document.body.appendChild(a);
  343. a.click();
  344. }).error(function (data, status, headers, config) {
  345. });
  346. };
  347. //初始化
  348. $scope.mdxquery('total', 'desc');
  349. $scope.sortActive = 'totaltop';
  350. $scope.name = 'total';//表格排序,字段名称
  351. $scope.type = 'desc';//表格排序,排序方式desc,asc
  352. $scope.direction = 'top';//箭头方向 top,bottom
  353. }])