'use strict'; 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) { //默认显示综合统计 $scope.tap = 'ZHTJ'; //默认显示上一周 $scope.searchstate = 'none'; //日期选择 $scope.nowtimes = moment().format('YYYY-MM-DD')//当前日期; //上周 $scope.week = function () { $scope.searchstate = "week"; var weeks = new Date().getDay(); $scope.starttimesModel = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYY-MM-DD'); $scope.endtimesModel = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYY-MM-DD'); } //上月 $scope.month = function () { $scope.searchstate = "month"; $scope.starttimesModel = moment().startOf('month').add(-1, 'M').format('YYYY-MM-DD'); $scope.endtimesModel = moment().endOf('month').add(-1, 'M').format('YYYY-MM-DD'); } //去年 $scope.year = function () { $scope.searchstate = "year"; $scope.starttimesModel = moment().startOf('year').add(-1, 'y').format('YYYY-MM-DD'); $scope.endtimesModel = moment().endOf('year').add(-1, 'y').format('YYYY-MM-DD'); } // 今天 $scope.today = function () { $scope.searchstate = "today"; $scope.starttimesModel = moment().format('YYYY-MM-DD'); $scope.endtimesModel = moment().format('YYYY-MM-DD'); } //近N日 $scope.day = function (num) { num = num > 1 ? num : 1; $scope.searchstate = "none"; $scope.starttimesModel = moment().subtract(num, "days").format("YYYY-MM-DD"); $scope.endtimesModel = moment().subtract(1, "days").format("YYYY-MM-DD"); } //默认显示最近7天 $scope.day(7); //选择上一周,上个月,去年 $scope.chooseDate = function (date) { switch (date) { case 'week': $scope.week(); break; case 'month': $scope.month(); break; case 'year': $scope.year(); break; case 'today': $scope.today(); break; } }; /** *日历 */ //打开开始日期选择框 $scope.startOpen = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.endOpened = false; $scope.startOpened = !$scope.startOpened; }; //打开结束日期选择框 $scope.endOpen = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.startOpened = false; $scope.endOpened = !$scope.endOpened; }; //重置 $scope.reload = function (isReload) { //点击重置时传true,切换tab传false if (isReload) { $scope.day(7); } $scope.searchstate = 'none'; $scope.sortActive = 'totaltop'; $scope.name = 'total';//表格排序,字段名称 $scope.type = 'desc';//表格排序,排序方式desc,asc $scope.direction = 'top';//箭头方向 top,bottom switch ($scope.tap) { case 'ZHTJ'://综合统计 $scope.mdxquery('total', 'desc'); break; case 'DHTJ'://电话统计 $scope.mdxquery('total', 'desc'); break; case 'WEB'://微信/WEB统计 $scope.mdxquery('total', 'desc'); break; case 'DHLYTJ'://电话留言统计 $scope.mdxquery('total', 'desc'); break; } }; //选择类型,综合统计,电话统计,微信/WEB统计,电话留言统计 $scope.active = function (name) { $scope.tap = name; $scope.reload(false); }; //综合统计,无限滚动加载 $scope.topEndComplete = function () { console.log('滚动'); }; // 请求人 // api_user_data.fetchDataList('requester', { // "idx": 0, // "sum": 10 // }).then(function (response) { // if (response) { // if (response.status = 200) { // $scope.requester = response.list; // } // } // }) //表格排序------------------------------------------------ $scope.sortActive = '';//表格排序,箭头高亮选中状态 $scope.name = '';//表格排序,字段名称 $scope.type = '';//表格排序,排序方式desc,asc $scope.direction = '';//箭头方向 top,bottom /** * 表格排序 * * @param {string} name 字段名称 * @param {string} type 排序方式desc,asc * @param {string} direction 箭头方向 top,bottom */ $scope.tableSort = function (name) { if ($scope.name == name) { $scope.type = $scope.type == 'desc' ? 'asc' : 'desc'; $scope.direction = $scope.direction == 'top' ? 'bottom' : 'top'; } else { $scope.type = 'desc'; $scope.direction = 'top'; } $scope.name = name; $scope.sortActive = name + $scope.direction; $scope.mdxquery(name, $scope.type); }; $scope.isArrays = function (arr) { return Array.isArray(arr); }; //综合统计 $scope.zhtj_list = null;//表格列表 $scope.zhtj_req_total = 0;//请求总数 $scope.zhtj_req_phone = 0;//请求电话总数 $scope.zhtj_req_wxweb = 0;//请求微信/web总数 $scope.zhtj_req_msg = 0;//请求电话留言总数 $scope.zhtj_req_desk = 0;//请求柜台总数 $scope.zhtj_trans_total = 0;//工单转换总数 $scope.zhtj_p_total = 0;//工单转换直接处理数 $scope.zhtj_unp_total = 0;//工单转换处理工单数 //电话统计 $scope.dhtj_list = null;//表格列表 $scope.dhtj_req_total = 0;//来电总数 $scope.dhtj_req_answer = 0;//接听数量 $scope.dhtj_req_miss = 0;//未接数量 $scope.dhtj_p_total = 0;//电话建单总数 $scope.dhtj_p_phone = 0;//直接解决 $scope.dhtj_unp_phone = 0;//派单数量 //微信/WEB统计 $scope.web_list = null;//表格列表 $scope.web_req_total = 0;//微信/WEB报修总数 $scope.web_req_trans = 0;//转换数量 $scope.web_req_reject = 0;//未受理数量 $scope.web_trans_total = 0;//微信/WEB转换总数 $scope.web_p_total = 0;//直接解决 $scope.web_unp_total = 0;//派单 //电话留言统计 $scope.dhlytj_list = null;//表格列表 $scope.dhlytj_req_total = 0;//电话留言总数 $scope.dhlytj_req_trans = 0;//建单总数 $scope.dhlytj_req_reject = 0;//不受理总数 $scope.dhlytj_trans_total = 0;//电话留言转换总数 $scope.dhlytj_p_total = 0;//直接解决总数 $scope.dhlytj_unp_total = 0;//派单总数 /** * * * @param {string} name 排序字段 * @param {string} type 排序方式 desc,asc */ $scope.mdxquery = function (name, type) { if (!name) { // name = $scope.tap == 'ZHTJ' ? 'accdate' : 'sum'; name = 'total'; } type = type || 'desc'; switch ($scope.tap) { case 'ZHTJ'://综合统计 $scope.zhtj_list = null; // 请求列表 api_event_form.fetchZhtjList({ "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "sortData": name, "sortType": type }).then(function (res) { if (res.stats == 200) { $scope.zhtj_list = res.dataList || [];//表格列表 $scope.zhtj_req_total = res.title.req_total;//请求总数 $scope.zhtj_req_phone = res.title.req_phone;//请求电话总数 $scope.zhtj_req_wxweb = res.title.req_wxweb;//请求微信/web总数 $scope.zhtj_req_msg = res.title.req_msg;//请求电话留言总数 $scope.zhtj_req_desk = res.title.req_desk;//请求柜台总数 $scope.zhtj_trans_total = res.title.trans_total;//工单转换总数 $scope.zhtj_p_total = res.title.p_total;//工单转换直接处理数 $scope.zhtj_unp_total = res.title.unp_total;//工单转换处理工单数 } }) break; case 'DHTJ'://电话统计 $scope.dhtj_list = null; // 请求列表 api_event_form.fetchDhtjList({ "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "sortData": name, "sortType": type }).then(function (res) { if (res.stats == 200) { $scope.dhtj_list = res.dataList || [];//表格列表 $scope.dhtj_req_total = res.title.req_total;//来电总数 $scope.dhtj_req_answer = res.title.req_answer;//接听数量 $scope.dhtj_req_miss = res.title.req_miss;//未接数量 $scope.dhtj_p_total = res.title.p_total;//电话建单总数 $scope.dhtj_p_phone = res.title.p_phone;//直接解决 $scope.dhtj_unp_phone = res.title.unp_phone;//派单数量 } }) break; case 'WEB'://微信/WEB统计 $scope.web_list = null; // 请求列表 api_event_form.fetchWebList({ "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "sortData": name, "sortType": type }).then(function (res) { if (res.stats == 200) { $scope.web_list = res.dataList || [];//表格列表 $scope.web_req_total = res.title.req_total;//微信/WEB报修总数 $scope.web_req_trans = res.title.req_trans;//转换数量 $scope.web_req_reject = res.title.req_reject;//未受理数量 $scope.web_trans_total = res.title.trans_total;//微信/WEB转换总数 $scope.web_p_total = res.title.p_total;//直接解决 $scope.web_unp_total = res.title.unp_total;//派单 } }) break; case 'DHLYTJ'://电话留言统计 $scope.dhlytj_list = null; // 请求列表 api_event_form.fetchDhlytjList({ "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "sortData": name, "sortType": type }).then(function (res) { if (res.stats == 200) { $scope.dhlytj_list = res.dataList || [];//表格列表 $scope.dhlytj_req_total = res.title.req_total;//电话留言总数 $scope.dhlytj_req_trans = res.title.req_trans;//建单总数 $scope.dhlytj_req_reject = res.title.req_reject;//不受理总数 $scope.dhlytj_trans_total = res.title.trans_total;//电话留言转换总数 $scope.dhlytj_p_total = res.title.p_total;//直接解决总数 $scope.dhlytj_unp_total = res.title.unp_total;//派单总数 } }) break; } }; //导出 $scope.export = function () { var postData = { "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "sortData": $scope.name, "sortType": $scope.type, report: {} } switch ($scope.tap) { case 'ZHTJ'://综合统计 postData.key = 'mdv2_service_repot_all'; postData.titles = ['人员', '建单数量', '直接处理数量', '处理工单数', '电话接听数', '微信/web报修处理数', '留言处理数', '柜台受理数']; break; case 'DHTJ'://电话统计 postData.key = 'mdv2_service_repot_phone'; postData.titles = ['人员', '接听数量', '建单数量', '直接解决', '派单数量']; break; case 'WEB'://微信/WEB统计 postData.key = 'mdv2_service_repot_wechat_web'; postData.titles = ['人员', '受理报修数', '不受理数', '转换数量', '直接解决数量', '派单数量']; break; case 'DHLYTJ'://电话留言统计 postData.key = 'mdv2_service_repot_msg'; postData.titles = ['人员', '受理总数', '不受理总数', '建单总数', '直接解决总数', '派单总数'] break; } var wt_url = api_bpm.downDataModel('report', 1).getRequestedUrl() $http({ url: wt_url, method: 'POST', data: JSON.stringify(postData), headers: { 'Accept': '*/*' }, responseType: 'arraybuffer' }).success(function (data, status, headers, config) { var fileName = ''; switch ($scope.tap) { case 'ZHTJ'://综合统计 fileName = '综合统计'; break; case 'DHTJ'://电话统计 fileName = '电话统计'; break; case 'WEB'://微信/WEB统计 fileName = '微信/WEB统计'; break; case 'DHLYTJ'://电话留言统计 fileName = '电话留言统计'; break; } // var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1]; var file = new Blob([data], { type: 'application/vnd.ms-excel' }); var fileURL = URL.createObjectURL(file); var a = document.createElement('a'); a.href = fileURL; a.target = '_blank'; a.download = fileName + '.xls'; document.body.appendChild(a); a.click(); }).error(function (data, status, headers, config) { }); }; //初始化 $scope.mdxquery('total', 'desc'); $scope.sortActive = 'totaltop'; $scope.name = 'total';//表格排序,字段名称 $scope.type = 'desc';//表格排序,排序方式desc,asc $scope.direction = 'top';//箭头方向 top,bottom }])