lianglvanalysis.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. var self;
  2. var type, level, area, title,sort=1,banerIndex;
  3. var path = {};
  4. var roleLevel, userRole;
  5. var paramsss = null;
  6. var startDate = getStartDate();//近3月的开始时间
  7. var endDate = getDateBefore(1);//近3月的结束时间
  8. var customHeight = 63;//自定义折线图、柱状图混合表中各项的高度
  9. var scroller1 = null;
  10. mui.plusReady(function() {
  11. plus.nativeUI.showWaiting();
  12. self = plus.webview.currentWebview();
  13. type = self.type;
  14. level = self.level;
  15. area = self.area;
  16. mui.later(function(){
  17. mui.fire(self, "loadData", {type: type, level: level, area: area});
  18. },500)
  19. //下拉刷新初始化
  20. initScroller();
  21. });
  22. function initScroller(){
  23. window.scroller1 = $("#wrapper1").initScroll(
  24. {
  25. pullDownAction: function(){
  26. $(".pullUp").hide();
  27. plus.nativeUI.showWaiting();
  28. $(".pullDown").show();
  29. loadAllData(curLeveArr);
  30. if($(".c-lab-mor #labLi2").css("display")!="none"){
  31. $(".c-lab-mor #labLi1").addClass("hit");
  32. }
  33. $(".c-lab-mor #labLi2").removeClass("hit");
  34. $(".div-list").show();
  35. $(".div-list2").hide();
  36. },pullUpAction: function() {
  37. $(".pullUp").hide();
  38. return false;
  39. }
  40. }
  41. );
  42. scroller1.on('beforeScrollStart',function() {
  43. console.log(scroller1.pointX);
  44. });
  45. }
  46. //plusReady调用完成后才可以调用plus的api
  47. window.addEventListener("loadData", function(e) {
  48. // userRole = plus!=null ?JSON.parse(plus.storage.getItem("userRole"))[0]:{} ;
  49. userRole = plus!=null ? JSON.parse(plus.storage.getItem("selectedRole")) : {};
  50. roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  51. type = e.detail.type;
  52. $('.type-'+ type).show();
  53. level = e.detail.level || roleLevel;
  54. area = e.detail.area || userRole.code;
  55. title = e.detail.title || userRole.name;
  56. load(type, level, area,startDate, endDate);
  57. plus.storage.setItem("userLevel",level+"");
  58. plus.storage.setItem("userArea",area);
  59. $('#tjTitle').html(level==4? "各区进展" : level==3? "各社区进展" : "各团队进展");
  60. $('#sqTitle').html(level==4? "各社区进展" : level==3? "各区进展" : "各社区进展");
  61. if(level==4){
  62. title = title.substring(0,3);
  63. }
  64. $("#title").html(title);
  65. $(".c-lab-mor #labLi2").removeClass("hit");
  66. $(".c-lab-mor #labLi1").addClass("hit");
  67. $(".div-list").show();
  68. $(".div-list2").hide();
  69. });
  70. var old_back = mui.back;
  71. var curLeveArr = null;
  72. mui.back = function(){
  73. var arr = JSON.parse(plus.storage.getItem("levelArr"));
  74. if(arr==null || arr.length==0){
  75. plus.storage.removeItem("userLevel");
  76. plus.storage.removeItem("userArea");
  77. var mainPage =plus.webview.getWebviewById("admin.html");
  78. mui.fire(mainPage, "refreshData");
  79. self.close();
  80. }else{
  81. curLeveArr = arr.pop();
  82. plus.storage.setItem("levelArr",arr.length==0?plus.storage.removeItem("levelArr"):JSON.stringify(arr));
  83. $("#title").html(curLeveArr[0].title);
  84. loadAllData(curLeveArr);
  85. $(".c-lab-mor #labLi1").addClass("hit");
  86. $(".div-btn-group .div-btn").removeClass("active");
  87. $(".div-btn-group .div-btn[data-id='1']").addClass("active");
  88. }
  89. }
  90. $(function(){
  91. $(".mui-switch").find(".mui-switch-handle").css("left","-16px");
  92. $(".c-lab-mor li").removeClass("hit");
  93. $(".c-lab-mor li").eq(0).addClass("hit");
  94. //标签切换
  95. $(".c-lab-mor li").click(function(){
  96. var tabid = $(this).attr("id");
  97. var top = $(this).offset().top;
  98. $(".c-lab-mor li").removeClass("hit");
  99. $(this).addClass("hit");
  100. if(tabid=="labLi1"){
  101. $(".div-list").show();
  102. $(".div-list2").hide();
  103. }else{
  104. $(".div-list").hide();
  105. $(".div-list2").show();
  106. $(".div-list2 li .div-name,.div-list2 li .div-amount").each(function(){
  107. if($(this).height()==21){
  108. $(this).addClass("mt20")
  109. }else if($(this).height()==42){
  110. $(this).addClass("mt10")
  111. }
  112. })
  113. }
  114. scroller1.refresh();
  115. window.onscroll = function () {
  116. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  117. if(top!=-1 && top>0){
  118. window.scrollTo(0,top);
  119. top = -1;
  120. }
  121. }
  122. });
  123. $(".demo-comtop").on("click","h1",function(){
  124. $(".lin-mask").show();
  125. $(".lin-sel-group").show();
  126. });
  127. $(".lin-mask").on("click",function(){
  128. $(".lin-mask").hide();
  129. $(".lin-sel-group").hide();
  130. });
  131. $(".lin-sel-group").on("click","li",function(){
  132. var index = $(this).attr("data-index") || "";
  133. var dataID = $(this).attr("data-id");
  134. $(".lin-sel-group li").removeClass("checked");
  135. $(this).addClass("checked");
  136. $(".lin-mask").trigger("click");
  137. $(".p-qiu-title").html($(this).find("label").html());
  138. $("#Dtitle").html($(this).find("label").html()).attr("data-index",index).attr("data-id",dataID);
  139. //重新加载数据
  140. plus.nativeUI.showWaiting();
  141. loadAllData(curLeveArr);
  142. if($(".c-lab-mor #labLi2").css("display")!="none"){
  143. $(".c-lab-mor #labLi1").addClass("hit");
  144. }
  145. $(".c-lab-mor #labLi2").removeClass("hit");
  146. $(".div-list").show();
  147. $(".div-list2").hide();
  148. });
  149. });
  150. /*****************************************************************************/
  151. /***** 统计数据初始化 **********/
  152. /*****************************************************************************/
  153. function loadData(type, level, area, from, to){
  154. var params = {level: level, area: area, startDate: from, endDate: to}
  155. params.index = parseInt($("#Dtitle").attr("data-index"));
  156. var arr = [{endDate:endDate,area:params.area,level:params.level},
  157. {level: level, area: area, startDate: from, endDate: to, interval:$('.div-btn-group .div-btn.active').attr('data-id'),index:13},
  158. {sort:1,date:endDate,level:params.level,index:params.index,area:params.area}];
  159. if($(".c-lab-mor #labLi2").css("display")!="none"){
  160. var lowLevel = 2;
  161. if(level==3) lowLevel= 3;
  162. arr.push({sort:1,date:endDate,level:4,index:params.index,area:"350200",lowLevel:lowLevel});
  163. }
  164. curLeveArr = arr;
  165. loadAllData(arr);
  166. }
  167. function loadAllData(arr){
  168. plus.nativeUI.showWaiting();
  169. var interval = $('.div-btn-group .div-btn.active').attr('data-id');
  170. //1-1:数据截止
  171. // sendPost("/statistics/time",null,function(res){
  172. // },function(res){
  173. // if(res.status=="200"){
  174. // var date = res.data || "";//(res.data && res.data.substring(11,16)) || "";
  175. // $(".jiezhi-time").html(date)
  176. // }
  177. // })
  178. $(".jiezhi-time").html(endDate)
  179. //签约率、完成率
  180. sendPost("/statistics/sszq_qwrq_info", arr[0], null, countHandle);
  181. //1-3:左边列表
  182. //市管:( level:4 ) ------区所有数据
  183. //区管:( level:3 ) ------社区所有数据
  184. //社区管:( level:2 ) ----团队所有数据
  185. // arr[2].lowCode = lowCode;
  186. if($("#Dtitle").attr("data-id")=="1"){
  187. arr[2].index = 18;
  188. }else{
  189. arr[2].index = 19;
  190. }
  191. sendPost("/statistics/lowlevel_all", arr[2], null, listHandle);
  192. $("#tjTitle").html(arr[0].tagName1);
  193. if(arr.length>3 && roleLevel!=2 && roleLevel!=3){
  194. //1-4:右边列表
  195. //市管:( level:4 , lowLevel:2 ) ------社区所有数据
  196. //区管:( level:4 , lowLevel:3 ) ------区所有数据
  197. //社区管:( level:4 , lowLevel:2 ) ----社区所有数据
  198. // arr[3].lowCode = lowCode;
  199. if($("#Dtitle").attr("data-id")=="1"){
  200. arr[3].index = 18;
  201. }else{
  202. arr[3].index = 19;
  203. }
  204. sendPost("/statistics/lowlevel_all", arr[3], null, list2Handle);
  205. $(".c-lab-mor #labLi2").show();
  206. $("#sqTitle").html(arr[0].tagName2)
  207. }else{
  208. $(".c-lab-mor #labLi2").hide();
  209. }
  210. }
  211. function countHandle(res){
  212. if(res.status == 200) {
  213. res = res.data;
  214. console.log(JSON.stringify(res))
  215. var data,rate,countRate;
  216. if($("#Dtitle").attr("data-id")=="1"){//三师转签
  217. data = res.sszq.rate/100;
  218. rate = res.sszq.rate==0?'0%':res.sszq.rate.toString().substring(0,res.sszq.rate.length-2) + "%";
  219. countRate = res.sszq.amount+"/"+res.sszq.num;
  220. }else{//高危人群
  221. data = res.gwrq.rate/100;
  222. rate = res.gwrq.rate==0?'0%':res.gwrq.rate.toString().substring(0,res.gwrq.rate.length-2) + "%";
  223. countRate = res.gwrq.amount+"/"+res.gwrq.num;
  224. }
  225. $('#qieyuelv').waterbubble({
  226. // txt: res.signRate.rate.substring(0,res.signRate.rate.length-2) + "%",
  227. data: data,
  228. waterColor: '#12B7F5',
  229. lineWidth:0,
  230. radius: 75,
  231. textColor: 'rgba(0, 0, 0, 0.8)',
  232. font: 'bold 25px arial'
  233. });
  234. $(".p-baifenlv").html(rate)
  235. $(".p-qianyuelv").html(countRate);
  236. } else {
  237. mui.toast(res.msg);
  238. }
  239. }
  240. function listHandle(res){
  241. if(res.status == 200) {
  242. res = res.data;
  243. for(var k in res){
  244. var list = res[k];
  245. var resultData = soreQLY(list);
  246. var topArr = soreRank(rateArr(resultData));
  247. var resultStr = "";
  248. var topClass = "";
  249. var qylResultStr = "";
  250. var qylClass = "c-a0dc28";
  251. if(curLeveArr[1].level==2){
  252. qylClass = "c-17b8ec";
  253. }
  254. for(var j in resultData){
  255. var item = resultData[j];
  256. switch (j){
  257. case "0":
  258. topClass="cb-EA5B3A";
  259. break;
  260. case "1":
  261. topClass="cb-FF8746";
  262. break;
  263. case "2":
  264. topClass="cb-69CA2E";
  265. break;
  266. default:
  267. topClass="cb-3DA9CE";
  268. break;
  269. }
  270. resultStr+='<li data-name="'+item.name+'" data-code="'+item.code+'">'+
  271. '<div class="div-top '+topClass+'">'+topArr[j]+'</div>'+
  272. '<div class="div-name f-fs14">'+item.name+'</div>'+
  273. '</li>';
  274. }
  275. $(".div-list .list-ul").html(resultStr);
  276. $(".div-list li .div-name,.div-list li .div-amount").each(function(){
  277. if($(this).height()==21){
  278. $(this).addClass("mt20")
  279. }else if($(this).height()==42){
  280. $(this).addClass("mt10")
  281. }
  282. })
  283. //加载图表数据
  284. var nameArrs = nameArr(resultData).reverse();//名称
  285. $("#chart-main").height(list.length*customHeight+100);
  286. if(curLeveArr[1].level!=2){
  287. $(".div-list .div-right-content").show();
  288. $(".div-list .div-right-team-content").hide();
  289. var rateArrS = rateArr(resultData).reverse();//签约率
  290. echartsCCFun("chart-main",rateArrS,nameArrs);//区进展、社区进展的图表
  291. }
  292. scroller1.refresh();
  293. plus.nativeUI.closeWaiting();
  294. }
  295. $(".div-list .list-ul").off("click").on("click",".div-name",function(event){
  296. if(curLeveArr[1].level==3) return false;
  297. var indexParam = parseInt($("#Dtitle").attr("data-index"));
  298. var customArr = [];
  299. if($(".c-lab-mor #labLi2").css("display")=="none"){
  300. customArr.push({endDate:endDate,area:area,level:level,title:$("#title").html(),tagName1:$("#tjTitle").html()},
  301. {level: level, area: area, startDate: startDate, endDate: endDate, interval:"1",index:indexParam},
  302. {sort:1,date:endDate,level:level,index:indexParam,area:area});
  303. }else{
  304. level = parseInt(plus.storage.getItem("userLevel"));
  305. area = plus.storage.getItem("userArea");
  306. var lowLevel = 2;if(level==3) lowLevel= 3;
  307. customArr.push({endDate:endDate,area:area,level:level,title:$("#title").html(),tagName1:$("#tjTitle").html(),tagName2:$("#sqTitle").html()},
  308. {level: level, area: area, startDate: startDate, endDate: endDate, interval:"1",index:indexParam},
  309. {sort:1,date:endDate,level:level,index:indexParam,area:area},
  310. {sort:1,date:endDate,level:4,index:indexParam,area:"350200",lowLevel:lowLevel});
  311. }
  312. if(plus.storage.getItem("levelArr")==null){
  313. var arr = [];
  314. arr.push(customArr);
  315. plus.storage.setItem("levelArr",JSON.stringify(arr));
  316. }else{
  317. var existArr = JSON.parse(plus.storage.getItem("levelArr"));
  318. existArr.push(customArr);
  319. plus.storage.setItem("levelArr",JSON.stringify(existArr));
  320. }
  321. level = curLeveArr[1].level;
  322. level--;
  323. $(".c-lab-mor #labLi2").removeClass("hit").hide();
  324. $(".div-list2").hide();
  325. $(".div-list").show();
  326. area = $(this).closest("li").attr("data-code");
  327. load(type, level, area, startDate, endDate);
  328. var name = $(this).closest("li").attr("data-name");
  329. title = name;
  330. $("#title").html(title);
  331. // mui.fire(plus.webview.getWebviewById("qianyuetongji2.html"),
  332. // "setTitle", {title: name});
  333. $('#tjTitle').html(level==4? "各区进展" : level==3? "各社区进展" : "各团队进展");
  334. $('#sqTitle').html(level==4? "各社区进展" : level==3? "各区进展" : "各社区进展");
  335. path[level] = {type: type, level: level, area: area, from: startDate, to: endDate, title: name};
  336. event.preventDefault();
  337. return false;
  338. });
  339. } else {
  340. mui.toast(res.msg);
  341. }
  342. }
  343. function list2Handle(res){
  344. if(res.status == 200) {
  345. res = res.data;
  346. for(var k in res){
  347. var list = res[k];
  348. var resultData = soreQLY(list);
  349. var topArr = soreRank(rateArr(resultData));
  350. var resultStr = "";
  351. var qylResultStr = "";
  352. var topClass = "";
  353. for(var j in resultData){
  354. var item = resultData[j];
  355. switch (j){
  356. case "0":
  357. topClass="cb-EA5B3A";
  358. break;
  359. case "1":
  360. topClass="cb-FF8746";
  361. break;
  362. case "2":
  363. topClass="cb-69CA2E";
  364. break;
  365. default:
  366. topClass="cb-3DA9CE";
  367. break;
  368. }
  369. resultStr+='<li data-name="'+item.name+'" data-code="'+item.code+'">'+
  370. '<div class="div-top '+topClass+'">'+topArr[j]+'</div>'+
  371. '<div class="div-name f-fs14">'+item.name+'</div>'+
  372. '</li>';
  373. }
  374. $(".div-list2 .list-ul").html(resultStr);
  375. //加载图表数据(市管和社管看所有社区数据、区管看所有区数据)
  376. $(".div-list2 .div-right-content").show();
  377. $("#chart-main2").height(list.length*customHeight+100);
  378. $("#chart-main2").width($(window).width());
  379. var rateArrS = rateArr(resultData).reverse();//签约率
  380. var nameArrs = nameArr(resultData).reverse();//名称
  381. echartsCCFun("chart-main2",rateArrS,nameArrs);//区进展、社区进展的图表
  382. setTimeout(function(){
  383. scroller1.refresh();
  384. plus.nativeUI.closeWaiting();
  385. },1000)
  386. }
  387. //点击名称事件
  388. $(".div-list2 .list-ul").off("click").on("click",".div-name",function(){
  389. var indexParam = parseInt($("#Dtitle").attr("data-index"));
  390. var customArr = [];
  391. if($(".c-lab-mor #labLi2").css("display")=="none"){
  392. customArr.push({endDate:endDate,area:area,level:level,title:$("#title").html(),tagName1:$("#tjTitle").html()},
  393. {level: level, area: area, startDate: startDate, endDate: endDate, interval:"1",index:indexParam},
  394. {sort:1,date:endDate,level:level,index:indexParam,area:area});
  395. }else{
  396. level = parseInt(plus.storage.getItem("userLevel"));
  397. area = plus.storage.getItem("userArea");
  398. var lowLevel = 2;if(level==3) lowLevel= 3;
  399. customArr.push({endDate:endDate,area:area,level:level,title:$("#title").html(),tagName1:$("#tjTitle").html(),tagName2:$("#sqTitle").html()},
  400. {level: level, area: area, startDate: startDate, endDate: endDate, interval:"1",index:indexParam},
  401. {sort:1,date:endDate,level:level,index:indexParam,area:area},
  402. {sort:1,date:endDate,level:4,index:indexParam,area:"350200",lowLevel:lowLevel});
  403. }
  404. if(plus.storage.getItem("levelArr")==null){
  405. var arr = [];
  406. arr.push(customArr);
  407. plus.storage.setItem("levelArr",JSON.stringify(arr));
  408. }else{
  409. var existArr = JSON.parse(plus.storage.getItem("levelArr"));
  410. existArr.push(customArr);
  411. plus.storage.setItem("levelArr",JSON.stringify(existArr));
  412. }
  413. level = curLeveArr[1].level;
  414. if(level==4) return false;
  415. if(level==3 && roleLevel==3){
  416. level=3;
  417. }
  418. if(roleLevel==4 || roleLevel==2){
  419. level = 2;
  420. }
  421. $(".c-lab-mor #labLi2").removeClass("hit").hide();
  422. $(".div-list2").hide();
  423. $(".div-list").show();
  424. area = $(this).closest("li").attr("data-code");
  425. load(type, level, area, startDate, endDate);
  426. var name = $(this).closest("li").attr("data-name");
  427. title = name;
  428. $("#title").html(title);
  429. // mui.fire(plus.webview.getWebviewById("qianyuetongji2.html"),
  430. // "setTitle", {title: name});
  431. $('#tjTitle').html(level==4? "各区进展" : level==3? "各社区进展" : "各团队进展");
  432. $('#sqTitle').html(level==4? "各社区进展" : level==3? "各区进展" : "各社区进展");
  433. path[level] = {type: type, level: level, area: area, from: startDate, to: endDate, title: name}
  434. });
  435. } else {
  436. mui.toast(res.msg);
  437. }
  438. }
  439. function load(type, level, area, from, to){
  440. path[level] = {type: type, level: level, area: area, from: from, to: to}
  441. loadData(type, level, area, from, to);
  442. }
  443. function assAmount(list){
  444. var all = 0;
  445. for(var k in list){
  446. all += list[k].amount;
  447. }
  448. return all;
  449. }
  450. //排名方法
  451. function soreRank(arr) {
  452. var temp = [];
  453. var lis = [];
  454. for(var i=0;i<arr.length;i++)
  455. lis.push(arr[i])
  456. lis = _.uniq(lis);
  457. // lis.sort();
  458. // lis.reverse();
  459. for(var i=0;i<arr.length;i++)
  460. temp[i] = lis.indexOf(arr[i])+1;
  461. return temp;
  462. }
  463. //签约率排序
  464. function soreQLY(arr) {
  465. var resArr = [];
  466. for(var i=0;i<arr.length;i++){
  467. var item = arr[i];
  468. item.rate = parseFloat(item.rate);
  469. resArr.push(item)
  470. }
  471. var eventData = _.chain(resArr)
  472. // 根据date日期字段排序
  473. .sortBy("rate").reverse()
  474. // 对集合中每一对象进行处理,返回新的集合
  475. .map(function (item) {
  476. return {
  477. amount: item.amount,
  478. code: item.code,
  479. rate: item.rate,
  480. name: item.name,
  481. num: item.num
  482. }
  483. }).value();
  484. console.log(JSON.stringify(eventData))
  485. return eventData;
  486. }
  487. //名称数据
  488. function nameArr(list){
  489. var nameArr = [];
  490. for(var k in list){
  491. nameArr.push(list[k].name);
  492. }
  493. return nameArr;
  494. }
  495. //签约量数据
  496. function amountArr(list){
  497. var amountArr = [];
  498. for(var k in list){
  499. amountArr.push(list[k].amount/1000);
  500. }
  501. return amountArr;
  502. }
  503. //签约率数据
  504. function rateArr(list){
  505. var rateArr = [];
  506. for(var k in list){
  507. var rate = list[k].rate?parseFloat(list[k].rate).toFixed(2):0.00;
  508. rateArr.push(rate);
  509. }
  510. return rateArr;
  511. }
  512. //人口数数据
  513. function personArr(list){
  514. var personArr = [];
  515. for(var k in list){
  516. personArr.push(list[k].num/1000 || 0);
  517. }
  518. return personArr;
  519. }
  520. //任务量数据
  521. function taskArr(list){
  522. var taskArr = [];
  523. for(var k in list){
  524. taskArr.push(list[k].task/1000||0);
  525. }
  526. return taskArr;
  527. }
  528. //柱状图叠层 (人口数-签约量=人口数)
  529. function arr_dive(personArr,amountArr){
  530. var resultArr = [];
  531. for(var k in personArr){
  532. resultArr.push(personArr[k]-amountArr[k]);
  533. }
  534. return resultArr;
  535. }
  536. //柱状图叠层 (签约量-目标量=超出量)
  537. function arr_dive_ccl(amountArr,taskArr){
  538. var resultArr = [];
  539. var chaochuValue = 0;
  540. for(var k in taskArr){
  541. chaochuValue = amountArr[k]-taskArr[k]<0?0:amountArr[k]-taskArr[k];
  542. resultArr.push(chaochuValue);
  543. }
  544. return resultArr;
  545. }
  546. //柱状图叠层 (签约量)
  547. function arr_dive_qyl(amountArr,taskArr){
  548. var resultArr = [];
  549. for(var k in taskArr){
  550. if(taskArr[k]-amountArr[k]>0){//目标量-签约量>0
  551. resultArr.push(amountArr[k]);
  552. }else{//目标量-签约量<0
  553. resultArr.push(0);
  554. }
  555. }
  556. return resultArr;
  557. }
  558. //柱状图叠层 (目标量)
  559. function arr_dive_mbl(amountArr,taskArr){
  560. var resultArr = [];
  561. for(var k in taskArr){
  562. if(taskArr[k]-amountArr[k]>0){//目标量-签约量>0
  563. resultArr.push(taskArr[k]-amountArr[k]);
  564. }else{//目标量-签约量<0
  565. resultArr.push(taskArr[k]);
  566. }
  567. }
  568. return resultArr;
  569. }
  570. /**
  571. * 区进展、社区进展的图表
  572. * @param {Object} amountArrS
  573. * @param {Object} amountArrResult
  574. * @param {Object} taskArrS
  575. * @param {Object} rateArrS
  576. */
  577. function echartsCCFun(elementId,rateArrS,nameArr){
  578. var mblValue = $("#Dtitle").attr("data-id")=="1"?"15":"30";
  579. var myChart = echarts.init(document.getElementById(elementId));
  580. var height = rateArrS.length*customHeight;
  581. var option = {
  582. grid: {x:60,y: 30,height:height,borderWidth:0},
  583. yAxis : [
  584. {
  585. type : 'category',
  586. data : nameArr,
  587. axisLine: {show:false},
  588. axisTick: {show:false},
  589. splitArea: {show:false},
  590. splitLine: {show:false},
  591. axisLabel: {show:false}
  592. }
  593. ],
  594. xAxis : [
  595. {
  596. type : 'value',
  597. axisLine: {show:true,lineStyle:{color:'#cccccc'}},
  598. axisTick: {show:true,lineStyle:{color:'#cccccc'}},
  599. axisLabel:{formatter:'{value}%',textStyle:{color:'#cccccc'}},
  600. splitArea: {show:false},
  601. splitLine: {show:false}
  602. },
  603. {
  604. type : 'value',
  605. axisLine: {show:true,lineStyle:{color:'#cccccc'}},
  606. axisTick: {show:true,lineStyle:{color:'#cccccc'}},
  607. axisLabel:{formatter:'{value}',textStyle:{color:'#cccccc'}},
  608. splitArea: {show:false},
  609. splitLine: {show:false}
  610. }
  611. ],
  612. series : [
  613. {
  614. name:'目标量',
  615. type:'bar',
  616. barWidth : 20,//柱图宽度
  617. xAxisIndex:1,
  618. itemStyle: {normal: {barBorderRadius:0,color:'#17B3EC', label:{show:true, position: 'right',textStyle:{color:'#17B3EC'}}}},
  619. data:rateArrS
  620. }
  621. ]
  622. };
  623. myChart.setOption(option);
  624. }
  625. /**
  626. * 团队进展图表
  627. * @param {Object} amountArrS
  628. */
  629. function echartsTDFun(elementId,amountArrS,nameArr){
  630. var myChart = echarts.init(document.getElementById(elementId));
  631. var height = amountArrS.length*customHeight;
  632. var option = {
  633. calculable : true,
  634. grid: {x:60,y: 30,height:height,borderWidth:0},
  635. yAxis : [
  636. {
  637. type : 'category',
  638. // boundaryGap : false,
  639. data : nameArr,
  640. axisLine: {show:false},
  641. axisTick: {show:false},
  642. splitArea: {show:false},
  643. splitLine: {show:false},
  644. axisLabel: {show:false}
  645. }
  646. ],
  647. xAxis : [
  648. {
  649. type : 'value',
  650. axisLine: {show:false},
  651. axisTick: {show:false},
  652. axisLabel: {show:false},
  653. splitArea: {show:false},
  654. splitLine: {show:false}
  655. },
  656. {
  657. type : 'value',
  658. axisLine: {show:true,lineStyle:{color:'#cccccc'}},
  659. axisTick: {show:true,lineStyle:{color:'#cccccc'}},
  660. axisLabel:{formatter:'{value}',textStyle:{color:'#cccccc'}},
  661. splitArea: {show:false},
  662. splitLine: {show:false},
  663. }
  664. ],
  665. series : [
  666. {
  667. name:'签约量',
  668. type:'bar',
  669. barWidth : 20,//柱图宽度
  670. xAxisIndex:1,
  671. itemStyle: {normal: {barBorderRadius:0,color:'#17b8ec', label:{show:false, position: 'insideRight',textStyle:{color:'#fff'}}}},
  672. data:amountArrS
  673. }
  674. ]
  675. };
  676. myChart.setOption(option);
  677. }
  678. /**
  679. * 数字3位加一个逗号
  680. * @param {Object} n
  681. */
  682. function format_number(n){
  683. var b=parseInt(n).toString();
  684. var len=b.length;
  685. if(len<=3){return b;}
  686. var r=len%3;
  687. return r>0?b.slice(0,r)+","+b.slice(r,len).match(/\d{3}/g).join(","):b.slice(r,len).match(/\d{3}/g).join(",");
  688. }
  689. function clearData(type){
  690. $("#textTj li").removeClass("l-over");
  691. if(!banerIndex){
  692. if(type==1){
  693. $("#textTj li").eq(0).addClass("l-over");
  694. } else {
  695. $("#textTj li").eq(4).addClass("l-over");
  696. }
  697. }
  698. $('#l-jmfx').hide();
  699. $("#list").empty();
  700. $("#list2").empty();
  701. $(".l-data").html("0");
  702. }
  703. /*****************************************************************************/
  704. /***** 折线图初始化 **********/
  705. /*****************************************************************************/
  706. var dateData = {};
  707. function loadLineData(type, level, area, from, to, interval, index){
  708. // plus.nativeUI.showWaiting();
  709. var url = "/statistics/interval_total";
  710. var lowCode = $("#Dtitle").attr("data-lowCode") || "";
  711. var params = {level: level, area: area, startDate: from, endDate: to,
  712. interval: interval,index:index,lowCode:lowCode}
  713. sendPost(url, params, null, dateLineHandle);
  714. }
  715. /**
  716. * 獲取當前日期往前推三個月(當前日期減去三個月)
  717. * 返回日期格式:比如:2014-08-11(當前月為:2014-11-11)
  718. */
  719. function getStartDate() {
  720. var newDate = new Date();
  721. var startY = newDate.getFullYear();
  722. var startM = newDate.getMonth() - 3;
  723. var startD = newDate.getDate();
  724. // 日期賦值
  725. var mydate = new Date(startY, startM, startD);
  726. var strYear = mydate.getFullYear();
  727. //顯示的月份要加一,因為月份是從0開始的
  728. var strMonth = mydate.getMonth() + 1;
  729. var strDate = mydate.getDate();
  730. if (strMonth.toString().length == 1)
  731. strMonth = "0" + strMonth;
  732. if (strDate.toString().length == 1)
  733. strDate = "0" + strDate;
  734. var strStartDate = strYear + "-" + strMonth + "-" + strDate;
  735. return strStartDate;
  736. };
  737. /**
  738. * 获取多少天前的日期
  739. */
  740. function getDateBefore(days) {
  741. var now = new Date();
  742. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  743. var year = date.getFullYear();
  744. var month = date.getMonth() + 1;
  745. var day = date.getDate();
  746. var hour = date.getHours();
  747. var minute = date.getMinutes();
  748. var second = date.getSeconds();
  749. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  750. }
  751. function maxData(data){
  752. var maxData = Math.max.apply(Math,data);
  753. var yAxis = maxData<10?10:maxData;
  754. return yAxis;
  755. }
  756. //初始化折线图
  757. var taskNum = 0;
  758. function drawChart(dateData){
  759. $(".div-switch").show();
  760. var recordCount = 10;//一页显示几条数据
  761. var allRecordData = dateData.amountArr.reverse();
  762. var dateArr = dateData.dateArr.reverse();
  763. var resultData = _.groupBy(allRecordData,function(item,i){return Math.floor(i/recordCount)});
  764. var dateArrData = _.groupBy(dateArr,function(item,i){return Math.floor(i/recordCount)});
  765. //以下为折线图处理
  766. var gnum = Math.ceil(allRecordData.length / recordCount);
  767. var HandStartX,HandStartY,HandEndX,HandEndY,CountX,CountY,startPos,isScrolling,number=allRecordData.length,times=allRecordData.length%recordCount;
  768. var canvasStr = '<div class="div-layer"></div>';
  769. for(var x in resultData){
  770. canvasStr ='<canvas id="wcMotion'+x+'" class="canvas-wc animated" style="display:block"></canvas>'+canvasStr;
  771. }
  772. $(".l-zxt-inner").html(canvasStr);
  773. var dateType = $(".div-btn-group .div-btn.active").attr("data-id");
  774. window.setTimeout(function() {
  775. for(var x in resultData){
  776. var startDay = new Date(getDateBefore(times-1));
  777. var resultDateArr = dateArrData[x].reverse();
  778. var yAxis = taskNum;//maxData(resultData[x]);//求数据的最大值
  779. $('#wcMotion'+x).wcChart({
  780. height: 200, // width and height must be set if change
  781. yAxis:yAxis,
  782. day: startDay,
  783. points: [],
  784. dateArr:resultDateArr,
  785. dateType:dateType,
  786. data: resultData[x].reverse(),
  787. fill: {gradient: [["#17B3EC",.1], ["#17B3EC",.5]], gradientAngle: Math.PI * -45/180},
  788. animation: null // 修复bug#3298 【医生端】总体分析排版优化。(vivo手机)
  789. });
  790. if(x==0){
  791. $('#wcMotion'+x).show();
  792. }
  793. times+=recordCount;
  794. //折线图画布添加左滑和右滑效果
  795. var wcMotion = document.getElementById('wcMotion'+x);
  796. wcMotion.addEventListener('touchstart', function(event) {
  797. HandStartX=event.touches[0].clientX;
  798. HandStartY=event.touches[0].clientY;
  799. //touches数组对象获得屏幕上所有的touch,取第一个touch
  800. var touch = event.targetTouches[0];
  801. //取第一个touch的坐标值
  802. startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};
  803. //这个参数判断是垂直滚动还是水平滚动
  804. isScrolling = 0;
  805. }, false);
  806. wcMotion.addEventListener('touchend', function(event) {
  807. HandEndX=event.changedTouches[0].clientX;
  808. HandEndY=event.changedTouches[0].clientY;
  809. CountX=HandEndX-HandStartX;
  810. CountY=HandEndY-HandStartY;
  811. if((Math.abs(CountX)>Math.abs(CountY))&& Math.abs(CountX)>50){
  812. var targetMotion = $(event.target);
  813. if(CountX<0){
  814. if(targetMotion.next().length>0 && !targetMotion.next().hasClass("div-layer")){
  815. targetMotion.addClass("fadeOutLeft");
  816. targetMotion.next().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInLeft").addClass("fadeInRight").show();
  817. }
  818. console.log("左滑");
  819. }else{
  820. if(targetMotion.prev().length>0 && !targetMotion.prev().hasClass("div-layer")){
  821. targetMotion.addClass("fadeOutRight");
  822. targetMotion.prev().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInRight").addClass("fadeInLeft").show();
  823. }
  824. console.log("右滑");
  825. }
  826. }
  827. }, false);
  828. wcMotion.addEventListener('touchmove', function(event) {
  829. //当屏幕有多个touch或者页面被缩放过,就不执行move操作
  830. if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
  831. var touch = event.targetTouches[0];
  832. endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
  833. //isScrolling为1时,表示纵向滑动,0为横向滑动
  834. isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;
  835. if(isScrolling === 0){
  836. //阻止触摸事件的默认行为,即阻止滚屏
  837. event.preventDefault();
  838. }
  839. }, false);
  840. }
  841. }, 500);
  842. }
  843. function dateLineHandle(res){
  844. if(res.status==200){
  845. for(var p in res.data){
  846. taskNum = res.data[p].taskNum;
  847. dateData[p] = formatDateData(res.data[p].data);
  848. if(dateData[p].amountArr && dateData[p].amountArr.length>0){
  849. $('#l-jmfx').toggle(p == "index_13" );
  850. $(".l-zxt-con").hide();
  851. mui.later(function(){
  852. $(".l-zxt-con").show();
  853. }, 100);
  854. // $('#l-legend').hide();
  855. $("#echarts_wushuju").hide();
  856. $('#l-times').html(type==1? '(人)' : '(次)').hide();
  857. } else{
  858. $(".l-zxt-con").hide();
  859. $("#echarts_wushuju").show();
  860. // $('#l-legend').hide();
  861. }
  862. drawChart(dateData[p]);//初始化折线图
  863. }
  864. } else {
  865. mui.toast(res.msg);
  866. }
  867. plus.nativeUI.closeWaiting();
  868. }
  869. //折线图数据格式转化
  870. function formatDateData(data){
  871. var dateArr = [];
  872. var amountArr = [];
  873. for(var k in data){
  874. dateArr.push(data[k].range.substring(5));
  875. amountArr.push(data[k].amount);
  876. }
  877. return {dateArr: dateArr, amountArr: amountArr};
  878. }
  879. window.addEventListener("toBack", function(e) {
  880. mui.back();
  881. });
  882. //弹出遮罩
  883. $(".icon-remark").on("click", function(e) {
  884. $(".modal-overlay").addClass("modal-overlay-visible");
  885. setTimeout(function(){
  886. $(".modal-content").show();
  887. },50)
  888. });
  889. $(".div-close").on("click",function(){
  890. $(".modal-overlay").removeClass("modal-overlay-visible");
  891. $(".modal-content").hide();
  892. })
  893. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);