renew-analysis2.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. var scroller1,
  2. initLevel,
  3. level,
  4. code,
  5. title,
  6. preIndex = 0, //记录前一次请求时发送的index
  7. currType = 0; //记录当前选中的是签入(1)还是签出(0)
  8. var tags=[];
  9. var colorArr = ['ff5442', 'ffc800 ','4ce428', '24bbfa','fb5dab', "9b5ffd"],
  10. colorArr2 = ['9b5ffd', 'ffc800', 'fb5dab'];
  11. //记录index的对应的值, 签出和签入对应的各个level的值
  12. var indexArr = [{4: 41, 3: 39, 2: 35}, {4: 40, 3: 38, 2: 34}];
  13. var reqArr = []; //记录请求的信息
  14. var now = new Date(),
  15. endDate = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
  16. mui.init();
  17. mui.plusReady(function(){
  18. var self = plus.webview.currentWebview();
  19. initLevel = level = self.level;
  20. code = self.code;
  21. title = self.title;
  22. $("#title").text(title);
  23. plus.nativeUI.showWaiting();
  24. initPage();
  25. initScroller();
  26. bindEvents();
  27. });
  28. function initScroller(){
  29. scroller1 = $("#wrapper1").initScroll(
  30. {
  31. pullDownAction: function(){
  32. plus.nativeUI.showWaiting();
  33. var info = reqArr[reqArr.length - 1];
  34. getAnalysisData();
  35. loadListData(info.tags, info.params);
  36. },pullUpAction: function() {
  37. $(".pullUp").hide();
  38. return false;
  39. }
  40. }
  41. );
  42. }
  43. function initPage(){
  44. getAnalysisData();
  45. var index;
  46. switch (parseInt(level)){
  47. case 4: //市级
  48. index = indexArr[0][level]; //初始查看区签出数据
  49. tags = ["各区","社区","团队"];
  50. break;
  51. case 3://区级
  52. index = indexArr[0][level]; //初始查看机构的签出数据
  53. tags = ["社区","团队"];
  54. break;
  55. case 2: //社区级
  56. index = indexArr[0][level]; //初始查看团队的签出数据
  57. tags = ["团队"];
  58. break;
  59. default:
  60. break;
  61. }
  62. var params2 = {
  63. sort:1,
  64. level:level,
  65. area:code,
  66. date: endDate,
  67. index: index
  68. };
  69. reqArr.push({tags: tags, params: params2, currType: currType});
  70. loadListData(tags, params2);
  71. }
  72. //获得顶部统计数据和饼图的数据
  73. function getAnalysisData(){
  74. var url = "/statistics/getRenewAnalysis",
  75. params = {level: level, code: code};
  76. sendGet(url, params, null, getAnalysisHandler);
  77. }
  78. //获得底部tab的值
  79. function loadListData(tags, params, notReloadTag){
  80. //加载数据截止时间
  81. sendPost("/statistics/time",null,function(res){
  82. },function(res){
  83. if(res.status=="200"){
  84. var date = (res.data && res.data.substring(11,16)) || "";
  85. $(".jiezhi-time").html(date)
  86. }
  87. });
  88. //加载显示tab
  89. if(!notReloadTag){
  90. var tagStr = "",
  91. index = 0;
  92. for(var i=0;i<tags.length;i++){
  93. var classz = "";
  94. var dataClick = "false";//是否已点击过
  95. if(params.lowLevel){ //如果存在之前点击tab的记录
  96. if(tags.length == 3){
  97. if(params.lowLevel == 2 && i == 1){
  98. classz="hit";
  99. dataClick="true";
  100. index = i;
  101. }
  102. if(params.lowLevel == 1 && i == 2){
  103. classz="hit";
  104. dataClick="true";
  105. index = i;
  106. }
  107. }else if(tags.length == 2){
  108. if(params.lowLevel == 1 && i == 1){
  109. classz="hit";
  110. dataClick="true";
  111. index = i;
  112. }
  113. }
  114. }else{
  115. if(i == 0){
  116. classz="hit";
  117. dataClick="true";
  118. }
  119. }
  120. tagStr += '<li id="tab_'+i+'" class="'+classz+'" data-click="'+dataClick+'"><a href="#" class="c-f16">'+tags[i]+'</a></li>';
  121. }
  122. $(".c-lab-mor").html(tagStr);
  123. //将其他的内容tab隐藏
  124. $(".tab-panel").addClass("c-hide").eq(index).removeClass("c-hide");
  125. }
  126. //选中选择“签入”“签出”的tab
  127. var selectedId = $(".c-lab-mor li.hit").attr("id").split("tab_")[1];
  128. var $aList = $("#list"+selectedId).find(".tab a");
  129. $aList.removeClass("active");
  130. $($aList[currType]).addClass("active");
  131. var url = "/statistics/lowlevel_all";
  132. sendPost(url, params, null, listHandler);
  133. }
  134. function getAnalysisHandler(res){
  135. if(res.status == 200){
  136. $("#outNum").text(res.data.outNum);
  137. $("#inNum").text(res.data.inNum);
  138. var len = res.data.switchHealth.length,
  139. sum = 0;
  140. for(var i=0; i<len; i++){
  141. sum += res.data.switchHealth[i].num;
  142. }
  143. var arrObj = [];
  144. for(var j=0; j<len; j++){
  145. var obj = res.data.switchHealth[j];
  146. obj.color = colorArr[j];
  147. if(sum == 0){
  148. obj.value = "0.00";
  149. }else{
  150. var rate = (obj.num / sum * 100).toFixed(2);
  151. obj.value = rate;
  152. }
  153. arrObj.push(obj);
  154. }
  155. echartsZQFun(arrObj);
  156. var html = template("reson_tmp", {list:arrObj});
  157. $("#reasonList").empty().append(html);
  158. //填充转签分布图
  159. var fenbuArrObj = [{
  160. color: colorArr2[0],
  161. name: "跨区",
  162. value: parseFloat(res.data.switchTown).toFixed(2)
  163. },{
  164. color: colorArr2[1],
  165. name: '跨社区',
  166. value: parseFloat(res.data.switchHospital).toFixed(2)
  167. },{
  168. color: colorArr2[2],
  169. name: '跨团队',
  170. value: parseFloat(res.data.switchTeam).toFixed(2)
  171. }];
  172. echartsFBFun(fenbuArrObj);
  173. var html = template("reson_tmp", {list:fenbuArrObj});
  174. $("#fenbuList").empty().append(html);
  175. }else{
  176. mui.toast(res.msg);
  177. }
  178. plus.nativeUI.closeWaiting();
  179. }
  180. function listHandler(res){
  181. if(res.status == 200){
  182. var data = res.data;
  183. var curIndex;
  184. for(var k in data){
  185. curIndex = k.split("index_")[1];
  186. var list = data[k];
  187. var topArr = soreRank(amountArr(list));
  188. for(var j in list){
  189. list[j].top = topArr[j];
  190. }
  191. data.all = assAmount(list);
  192. data.amountName = parseInt(currType) ? "签入数":"签出数";
  193. data.list = list;
  194. data.level = level;
  195. //查找对应的tab的内容显示区域
  196. var id = $(".c-lab-mor li.hit").attr("id"),
  197. tabText = $(".c-lab-mor li.hit a").text(),
  198. selectedId = id.split("tab_")[1];
  199. if(tabText == "团队"){
  200. data.level = 2; //团队时不需要显示向右箭头
  201. }
  202. //判断是否存在上一次请求显示的内容
  203. var $preDiv = $("#listPanel"+selectedId).find(".l_index_"+preIndex);
  204. if($preDiv.length > 0){
  205. $preDiv.hide();
  206. }
  207. //判断是否存在div
  208. var $div = $("#listPanel"+selectedId).find(".l_"+k);
  209. var html = template('list_tmpl', data);
  210. if($div.length == 0){
  211. var ulHtml = '<ul class="l_'+k+' l-gq-list">'+html+'<ul>';
  212. $("#listPanel"+selectedId).empty().append(ulHtml);
  213. }else{
  214. $div.empty().append(html);
  215. $div.show();
  216. }
  217. }
  218. preIndex = curIndex;
  219. scroller1.refresh();
  220. }else{
  221. mui.toast(res.msg);
  222. }
  223. }
  224. template.helper("setRate", function(all, amount){
  225. if(all == 0)
  226. return 0;
  227. return (amount / all * 100).toFixed(2);
  228. });
  229. //排序
  230. function soreRank(arr) {
  231. var temp = [];
  232. var lis = [];
  233. for(var i=0;i<arr.length;i++)
  234. lis.push(arr[i])
  235. lis = _.uniq(lis);
  236. // lis.sort();
  237. // lis.reverse();
  238. for(var i=0;i<arr.length;i++)
  239. temp[i] = lis.indexOf(arr[i])+1;
  240. return temp;
  241. }
  242. //数量数组
  243. function amountArr(list){
  244. var amountArr = [];
  245. for(var k in list){
  246. amountArr.push(list[k].amount);
  247. }
  248. return amountArr;
  249. }
  250. //格式化数量
  251. function assAmount(list){
  252. var all = 0;
  253. for(var k in list){
  254. all += list[k].amount;
  255. }
  256. return all;
  257. }
  258. //绘制转签原因分析的图
  259. function echartsZQFun(arry){
  260. var m=this;
  261. var myChart = echarts.init(document.getElementById('reasonMain'));
  262. var option = {
  263. tooltip: {
  264. trigger: 'item',
  265. formatter: "{a} <br/>{b}: {c}%",
  266. position: ['50%', '50%']
  267. },
  268. color:['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
  269. series: [
  270. {
  271. name:'转签原因',
  272. type:'pie',
  273. radius : '65%',
  274. center:[70,'50%'],
  275. label: {
  276. normal: {
  277. show: false,
  278. textStyle: {
  279. color: "#000"
  280. }
  281. }
  282. },
  283. labelLine: {
  284. normal: {
  285. show: false
  286. }
  287. },
  288. data:arry
  289. }]
  290. };
  291. myChart.setOption(option);
  292. }
  293. //绘制分布图
  294. function echartsFBFun(arry){
  295. var m=this;
  296. var myChart = echarts.init(document.getElementById('fenbuMain'));
  297. var option = {
  298. tooltip: {
  299. trigger: 'item',
  300. formatter: "{a} <br/>{b}: {c}%",
  301. position: ['50%', '50%']
  302. },
  303. color:['#9b5ffd', '#ffc800', '#fb5dab'],
  304. series: [
  305. {
  306. name:'转签分布',
  307. type:'pie',
  308. radius : '65%',
  309. center:[70,'50%'],
  310. label: {
  311. normal: {
  312. show: false,
  313. textStyle: {
  314. color: "#000"
  315. }
  316. }
  317. },
  318. labelLine: {
  319. normal: {
  320. show: false
  321. }
  322. },
  323. data:arry
  324. }]
  325. };
  326. myChart.setOption(option);
  327. }
  328. function bindEvents(){
  329. //数据点击查看下一级数据
  330. $("body").on('tap',".l-gq-list li", function(){
  331. var tabText = $(".c-lab-mor li.hit a").text();
  332. if(tabText == "各区"){
  333. tags = ["社区","团队"];
  334. }else if(tabText == "社区"){
  335. tags = ["团队"];
  336. if((initLevel == level) && (initLevel == 4)){
  337. level --;
  338. }
  339. }else{
  340. //点击的是团队下的item
  341. return false;
  342. }
  343. title = $(this).attr("data-name");
  344. code = $(this).attr("data-code");
  345. $("#title").text(title);
  346. level --;
  347. var params = {
  348. sort:1,
  349. level:level,
  350. area:code,
  351. date: endDate,
  352. index: indexArr[currType][level]
  353. };
  354. reqArr.push({tags: tags, params: params, currType: currType});
  355. getAnalysisData();
  356. loadListData(tags, params);
  357. });
  358. //tab切换
  359. $("body").on('tap', '.c-lab-mor li', function(){
  360. var $this = $(this);
  361. if($this.hasClass("hit")){
  362. return false;
  363. }
  364. $(".c-lab-mor li").removeClass("hit");
  365. $this.addClass("hit");
  366. var selectedId = $this.attr("id").split("tab_")[1];
  367. $(".tab-panel").addClass("c-hide");
  368. $("#list"+selectedId).removeClass("c-hide");
  369. var tabText = $(".c-lab-mor li.hit a").text(),
  370. lowLevel = 0,
  371. index = indexArr[0][level];
  372. if(tabText == "社区"){
  373. if(initLevel == 4){
  374. lowLevel = 2;
  375. }
  376. index = indexArr[currType][3];
  377. }else if(tabText == "团队"){
  378. if(initLevel >= 3){
  379. lowLevel = 1;
  380. }
  381. index = indexArr[currType][2];
  382. }else{
  383. index = indexArr[currType][4];
  384. }
  385. var params = {
  386. sort:1,
  387. level:level,
  388. area:code,
  389. date: endDate,
  390. index: index
  391. };
  392. if(lowLevel){
  393. params.lowLevel = lowLevel;
  394. }
  395. reqArr.push({tags: tags, params: params, currType: currType});
  396. loadListData(tags, params, 1);
  397. });
  398. //签入签出切换
  399. $("body").on('tap', '.card .ui-col-1', function(){
  400. var $this = $(this);
  401. if($this.hasClass("card-active")){
  402. return false;
  403. }
  404. $this.siblings("div").removeClass("card-active");
  405. $this.addClass("card-active");
  406. var val = $this.attr("data-val"),
  407. tabText = $(".c-lab-mor li.hit").find("a").text(),
  408. lowLevel = 0,
  409. index = indexArr[val][level];
  410. currType = val;
  411. if(currType == "0"){
  412. $(".reason-panel").show();
  413. $(".locale-panel").hide();
  414. }else{
  415. $(".reason-panel").hide();
  416. $(".locale-panel").show();
  417. }
  418. if(tabText == "社区"){
  419. index = indexArr[val][3];
  420. }else if(tabText == "团队"){
  421. lowLevel = 1;
  422. index = indexArr[val][2];
  423. }else{
  424. index = indexArr[val][4];
  425. }
  426. var params = {
  427. sort:1,
  428. level:level,
  429. area:code,
  430. date: endDate,
  431. index: index
  432. };
  433. if(lowLevel){
  434. params.lowLevel = lowLevel;
  435. }
  436. // reqArr.push({tags: tags, params: params, currType: currType});
  437. loadListData(tags, params, 1);
  438. });
  439. }
  440. //返回事件
  441. var old_back = mui.back;
  442. mui.back = function(){
  443. if(reqArr.length == 1){
  444. old_back();
  445. }
  446. else{
  447. var preInfo = reqArr.pop();
  448. var info = reqArr[reqArr.length - 1];
  449. level = info.params.level;
  450. code = info.params.area;
  451. title = info.params.title;
  452. currType = info.currType;
  453. if(preInfo.params.level != level){
  454. getAnalysisData();
  455. }
  456. tags = info.tags;
  457. $("#title").html(title);
  458. loadListData(info.tags, info.params);
  459. }
  460. }