sign-progress.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. var reqList = []; //记录请求的参数和url,用于后退时使用
  2. Vue.use(Vuedals.default);
  3. new Vue({
  4. el: "#main",
  5. data: {
  6. appname: "签约进展",
  7. isback: true,
  8. isrefresh: true,
  9. isfilter: true,
  10. isopen: false,
  11. //请求页面所需参数
  12. level: '',
  13. area: '',
  14. areaTitle: '',
  15. index: '3',
  16. selectedDateType: 1, //折线图坐标值1-日,2-周,3-月
  17. endDate: '',
  18. startDate: '',
  19. lowLevel: '',
  20. lowCode: '',
  21. chooseYear: '',
  22. userRole: '',
  23. analysisType: "1", // 筛选维度的id, 1-按任务,2-按人口,3-高血压,4-糖尿病,5-65岁以上人群
  24. analysisName: "按任务",
  25. signRateData: {
  26. signRateText: "",
  27. signRate: "",
  28. signAmount: "",
  29. signRateAll: "",
  30. completeRateText: "",
  31. completeRate: "",
  32. completeAmount: "",
  33. completeRateAll: ""
  34. },
  35. yearHtml: "",
  36. contentHtml: "",
  37. isloading:false, //加载中
  38. year1:'0',
  39. year2:'0',
  40. year3:'0',
  41. },
  42. components: {
  43. vuedals: Vuedals.Component
  44. },
  45. methods: {
  46. lowlevelTotal:function(){
  47. var vm = this
  48. var url = "/statistics/leveltwo_increment"
  49. params = {
  50. area:vm.area,
  51. level:vm.level,
  52. endDate: vm.endDate,
  53. index:187,
  54. slaveKey2:vm.lowCode,
  55. };
  56. httpRequest.get(url,{data:params}).then(function(res){
  57. if(res.status == 200) {
  58. var index187 = res.data.index_187
  59. index187.forEach(function(t){
  60. t.value = t.amount
  61. t.name = '签约' + t.name
  62. if(t.code == 1) {
  63. vm.year1 = t.value
  64. }else if(t.code == 2) {
  65. vm.year2 = t.value
  66. }else if(t.code == 3) {
  67. vm.year3 = t.value
  68. }
  69. })
  70. var myChart = echarts.init(document.getElementById('mainTu'));
  71. var option;
  72. option = {
  73. color:['#0EBF97','#15AAE0','#935DF6'],
  74. series: [
  75. {
  76. type: 'pie',
  77. radius: ['55%', '70%'],
  78. avoidLabelOverlap: false,
  79. center:[80,'50%'],
  80. label: {
  81. normal: {
  82. show: false,
  83. position: 'center'
  84. }
  85. },
  86. emphasis: {
  87. label: {
  88. show: true,
  89. fontSize: 14,
  90. formatter: function(e, e1, e2, e3){
  91. var data = e.data
  92. return ['{a|'+data.name+'}', '{b|'+ data.rate +'%}'].join('\n')
  93. },
  94. rich: {
  95. a: {
  96. lineHeight: 20
  97. },
  98. b: {
  99. lineHeight: 20
  100. },
  101. }
  102. }
  103. },
  104. data:index187
  105. }
  106. ]
  107. };
  108. myChart.setOption(option);
  109. myChart.on('click', function (params) {
  110. for(var i=0; i<3; i++){
  111. if(i != params.dataIndex){
  112. myChart.dispatchAction({
  113. type: 'downplay',
  114. dataIndex: i
  115. });
  116. } else {
  117. myChart.dispatchAction({
  118. type: 'highlight',
  119. dataIndex: i
  120. });
  121. }
  122. }
  123. });
  124. $('#qianyueNXList>div').on('click', function(){
  125. myChart.dispatchAction({
  126. type: 'downplay',
  127. dataIndex: [0,1,2]
  128. });
  129. myChart.dispatchAction({
  130. type: 'highlight',
  131. dataIndex: $(this).index(),
  132. });
  133. })
  134. }
  135. })
  136. return
  137. sendGet(url, params, null, function(res){
  138. if(res.status == 200){
  139. if(res.data&&res.data.index_187) {
  140. $('#qianyueMap').show()
  141. $('#no_result_wrap').hide()
  142. var index187 = res.data.index_187
  143. }else{
  144. $('#qianyueMap').hide()
  145. $('#no_result_wrap').show()
  146. }
  147. }else{
  148. mui.toast(res.msg);
  149. }
  150. }, true);
  151. },
  152. getNewLineData: function(arg) {
  153. this.selectedDateType = arg.dateType;
  154. loadData([1], this);
  155. },
  156. getAreaData: function(arg) {
  157. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  158. if(arg.level == this.level) {
  159. this.lowLevel = arg.lowLevel;
  160. loadData([2], this);
  161. } else {
  162. this.level = arg.level;
  163. this.lowLevel = arg.lowLevel;
  164. this.area = arg.area;
  165. this.areaTitle = arg.areaTitle;
  166. loadData([0, 1, 2], this);
  167. }
  168. EventBus.$emit('update-area-name', {
  169. areaName: this.areaTitle
  170. });
  171. //存储请求所带的参数
  172. reqList.push({
  173. level: this.level,
  174. area: this.area,
  175. areaTitle: this.areaTitle,
  176. index: this.index,
  177. endDate: this.endDate,
  178. startDate: this.startDate,
  179. lowLevel: this.lowLevel,
  180. lowCode: this.lowCode,
  181. analysisType: this.analysisType,
  182. })
  183. }
  184. },
  185. mounted: function() {
  186. //初始化数据
  187. initData(this);
  188. //获得顶部各tab的值
  189. loadData([0, 1, 2], this); //参数组数表示请求的区域为上中下
  190. //存储请求所带的参数
  191. reqList.push({
  192. level: this.level,
  193. area: this.area,
  194. areaTitle: this.areaTitle,
  195. index: this.index,
  196. endDate: this.endDate,
  197. startDate: this.startDate,
  198. lowLevel: this.lowLevel,
  199. lowCode: this.lowCode,
  200. analysisType: this.analysisType
  201. });
  202. this.lowlevelTotal()
  203. //设置监听器, 监听折线图日期变化
  204. var vm = this;
  205. //监听后退按钮的操作
  206. EventBus.$on("back-click", function(arg) {
  207. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  208. if(reqList.length == 1) {
  209. history.go(-1);
  210. } else {
  211. var preInfo = reqList.pop();
  212. var info = reqList[reqList.length - 1];
  213. vm.level = info.level;
  214. vm.area = info.area;
  215. vm.areaTitle = info.areaTitle;
  216. vm.lowLevel = info.lowLevel;
  217. vm.index = info.index;
  218. vm.lowCode = info.lowCode;
  219. loadData([0, 1, 2], vm);
  220. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  221. }
  222. });
  223. //监听页面刷新
  224. EventBus.$on("refresh-click", function(arg) {
  225. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  226. loadData([0, 1, 2], vm);
  227. });
  228. //弹出筛选框
  229. EventBus.$on('filter-click', function(arg) {
  230. //弹框显示筛选条件
  231. Vuedals.Bus.$emit('new', {
  232. title: '条件筛选',
  233. onClose: function(data) {
  234. vm.chooseYear = data.chooseYear;
  235. vm.startDate = getStartDate(vm.chooseYear);
  236. vm.endDate = getEndDate(vm.chooseYear);
  237. vm.lowCode = data.lowCode;
  238. vm.analysisType = data.id;
  239. vm.analysisName = data.name;
  240. // vm.yearHtml = data.yearHtml;
  241. // vm.contentHtml = data.contentHtml;
  242. //请求参数重置,页面类型重新开始
  243. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  244. vm.area = vm.userRole.code;
  245. vm.areaTitle = vm.userRole.name;
  246. EventBus.$emit('update-area-name', {
  247. areaName: vm.areaTitle
  248. });
  249. vm.selectedDateType = 1;
  250. //然后清空请求列表数组
  251. reqList.splice(0, reqList.length);
  252. loadData([0, 1, 2], vm); //刷新数据
  253. //存储请求所带的参数
  254. reqList.push({
  255. level: vm.level,
  256. area: vm.area,
  257. areaTitle: vm.areaTitle,
  258. index: vm.index,
  259. endDate: vm.endDate,
  260. startDate: vm.startDate,
  261. lowLevel: vm.lowLevel,
  262. lowCode: vm.lowCode,
  263. analysisType: vm.analysisType
  264. });
  265. EventBus.$emit('update-statistics-year', {
  266. selectDate: vm.chooseYear + "年"
  267. }); //更新年份
  268. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  269. EventBus.$emit('update-dimension-name', {
  270. dimensionVal: data.name
  271. }); //更新维度名称
  272. },
  273. component: 'sign-progress-filter',
  274. props: {
  275. chooseYear: vm.chooseYear,
  276. analysisType: vm.analysisType,
  277. lowCode: vm.lowCode,
  278. analysisName: vm.analysisName
  279. // yearHtml: vm.yearHtml,
  280. // contentHtml: vm.contentHtml
  281. }
  282. });
  283. });
  284. $("#main").removeClass("c-hide");
  285. }
  286. })
  287. function initData(vm) {
  288. //获得缓存中缓存的角色权限
  289. var userRole = window.sessionStorage.getItem("selectedRole");
  290. if(!userRole) {
  291. return false;
  292. }
  293. vm.userRole = JSON.parse(userRole);
  294. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  295. vm.area = vm.userRole.code;
  296. vm.areaTitle = vm.userRole.name;
  297. var now = new Date();
  298. if(now.getMonth() >= 6 || now.getFullYear()>=2023) {
  299. vm.chooseYear = now.getFullYear();
  300. } else {
  301. vm.chooseYear = now.getFullYear() - 1;
  302. }
  303. vm.startDate = getStartDate(vm.chooseYear);
  304. vm.endDate = getEndDate(vm.chooseYear);
  305. //更新头部信息
  306. EventBus.$emit('update-all-prompt-info', {
  307. areaName: vm.areaTitle,
  308. selectDate: vm.chooseYear + "年",
  309. dimensionVal: vm.analysisName
  310. });
  311. }
  312. function initReqParams(vm) {
  313. vm.index = 13;
  314. if(vm.lowCode) {
  315. vm.index = 17;
  316. }
  317. reqParam = [{
  318. url: "/statistics/sign_info",
  319. reqType: 'get',
  320. data: {
  321. level: vm.level,
  322. area: vm.area,
  323. lowCode: vm.lowCode,
  324. year: vm.chooseYear,
  325. endDate: vm.endDate
  326. }
  327. }, {
  328. url: "/statistics/interval_total",
  329. reqType: 'get',
  330. data: {
  331. level: vm.level,
  332. area: vm.area,
  333. startDate: vm.startDate,
  334. endDate: vm.endDate,
  335. interval: vm.selectedDateType,
  336. index: vm.index,
  337. lowCode: vm.lowCode
  338. }
  339. }, {
  340. url: "/statistics/lowlevel_all",
  341. reqType: 'get',
  342. data: {
  343. sort: 1,
  344. date: vm.endDate,
  345. level: vm.level,
  346. index: vm.index,
  347. area: vm.area,
  348. lowCode: vm.lowCode
  349. }
  350. }];
  351. if(vm.lowLevel) {
  352. reqParam[2].data.lowLevel = vm.lowLevel;
  353. }
  354. return reqParam;
  355. }
  356. function getTopTagDatas(data, vm) {
  357. vm.signRateData.signRateText = parseFloat(data.signRate.rate).toFixed(2) + "%"
  358. vm.signRateData.signRate = parseFloat(data.signRate.rate) / 100;
  359. vm.signRateData.signAmount = data.signRate.sign;
  360. vm.signRateData.signRateAll = data.signRate.people;
  361. vm.signRateData.completeRateText = parseFloat(data.signTaskRate.rate).toFixed(2) + "%"
  362. vm.signRateData.completeRate = parseFloat(data.signTaskRate.rate) / 100;
  363. vm.signRateData.completeAmount = data.signTaskRate.sign;
  364. vm.signRateData.completeRateAll = data.signTaskRate.people;
  365. var val1 = vm.signRateData.signRateAll - vm.signRateData.signAmount
  366. var signArr = [{
  367. name: '签约量',
  368. value: vm.signRateData.signAmount
  369. }, {
  370. name: '未签约量',
  371. value: val1 > 0 ? val1 : 0
  372. }];
  373. var val2 = vm.signRateData.completeRateAll - vm.signRateData.completeAmount;
  374. var completeArr = [{
  375. name: '完成量',
  376. value: vm.signRateData.completeAmount
  377. }, {
  378. name: '未达标量',
  379. value: val2 > 0 ? val2 : 0
  380. }];
  381. var signChart = drawPieChart('signMain', signArr, ['#12b7f5', '#ebebf5'], true); //签约率
  382. var completeChart = drawPieChart('completeMain', completeArr, ['#12b7f5', '#ebebf5'], true); //完成率
  383. window.onresize = function() {
  384. signChart.resize();
  385. completeChart.resize();
  386. window.lineCharts.resize(); //日周月折线图
  387. }
  388. }
  389. function loadData(loadArr, vm) {
  390. //获取其他请求的参数
  391. var reqParams = initReqParams(vm),
  392. reqPromise = [],
  393. newArr = []; //记录非顶部请求的请求数组
  394. for(i = 0; i < loadArr.length; i++) {
  395. var j = loadArr[i];
  396. var param = reqParams[j];
  397. reqPromise.push(httpRequest.get(param.url, {
  398. data: param.data
  399. }));
  400. newArr.push(loadArr[i]);
  401. }
  402. vm.isloading=true
  403. if(reqPromise.length > 0) {
  404. Promise.all(reqPromise).then(function(ress) {
  405. vm.isloading=false
  406. var res1, res2, res3;
  407. for(var i = 0; i < loadArr.length; i++) {
  408. var j = loadArr[i] + 1;
  409. if(j == 1) {
  410. res1 = ress[i];
  411. }
  412. if(j == 2) {
  413. res2 = ress[i];
  414. }
  415. if(j == 3) {
  416. res3 = ress[i];
  417. }
  418. }
  419. if(res1 && res1.status == 200) {
  420. getTopTagDatas(res1.data, vm);
  421. }
  422. if(res2 && res2.status == 200) {
  423. handleSecondPanelData(res2.data, vm);
  424. }
  425. if(res3) {
  426. if(res3.status == 200) {
  427. listHandle(res3.data, vm);
  428. } else {
  429. console.log(res3.msg);
  430. }
  431. }
  432. })
  433. }
  434. }
  435. function handleSecondPanelData(data, vm) {
  436. var xDatas = [],
  437. yDatas = [],
  438. names = [],
  439. taskNum = vm.lowCode ? data.index_17.taskNum : data.index_1.taskNum,
  440. colors = ['#12b7f5'],
  441. index_names = {
  442. 'index_1': '总签约人数'
  443. };
  444. for(var p in data) {
  445. names.push(index_names[p]);
  446. var xData = _.map(data[p].data, function(o) {
  447. return o.range;
  448. });
  449. var yData = _.map(data[p].data, function(o) {
  450. return o.amount;
  451. });
  452. xDatas.push(xData);
  453. yDatas.push(yData);
  454. }
  455. EventBus.$emit("draw-line-chart", {
  456. panelName: "签约量趋势",
  457. quotaNames: names,
  458. xData: xDatas[0],
  459. yDatas: yDatas,
  460. colors: colors,
  461. markLineValue: taskNum,
  462. markLineName: "目标量"
  463. });
  464. }
  465. function listHandle(data, vm) {
  466. for(i in data) {
  467. var list = data[i];
  468. var topArr = [];
  469. topArr = soreRank(getKeyValueArr(list, 'amount'));
  470. var arr = _.map(list, function(o, index) {
  471. var cols = [o.name];
  472. if(vm.analysisType == "2" && vm.level > 2 && vm.lowLevel != 1) { //按人口
  473. cols.push(o.num);
  474. } else {
  475. cols.push(o.amount);
  476. }
  477. if(vm.level > 2 && vm.lowLevel != 1) {
  478. cols.push(o.signTaskNum);
  479. cols.push(parseFloat(o.rate).toFixed(2) + "%");
  480. } else if(vm.chooseYear != "2016") {
  481. cols.push(o.signRegulationNum);
  482. }
  483. return {
  484. rank: topArr[index],
  485. code: o.code,
  486. name: o.name,
  487. cols: cols
  488. }
  489. });
  490. var headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量"), "目标率", "当前签约率"]; //analysisType=2 为按人口
  491. if(vm.lowLevel == 1 || vm.level == 2) { //团队
  492. if(vm.chooseYear =="2016"){
  493. headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量")];
  494. }else{
  495. headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量"), "调控量"];
  496. }
  497. }
  498. EventBus.$emit("render-area-data", {
  499. level: vm.level,
  500. area: vm.area,
  501. lowLevel: vm.lowLevel,
  502. headers: headers,
  503. rows: arr
  504. });
  505. }
  506. }