prescription-analysis.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. var reqList = [];
  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: true,
  11. //页面请求参数
  12. level: '',
  13. area: '',
  14. areaTitle: '',
  15. userRole: {},
  16. lowLevel: '3', //市级对应lowLevel为3,逐级递减
  17. dateType: 1, //折线图坐标值1-日,2-周,3-月
  18. startDate: "",
  19. endDate: "",
  20. tagCode: 1, //顶部各个tag标签对应的值
  21. sumType: 1, //记录从筛选页面选择的统计维度 1-订单统计,2-费用统计,3-配送统计,4-年龄统计
  22. sumTypeName: "订单统计",
  23. disease: "", //疾病类型
  24. diseaseName: "全部",
  25. orderTagDatas: {
  26. total: 0,
  27. finishCount: 0,
  28. patientCancelCount: 0,
  29. noReviewedCount: 0,
  30. processingCount: 0,
  31. payOuttimeCount: 0
  32. },
  33. paymentData: {
  34. sum: 0,
  35. avg: 0
  36. },
  37. expressData: {
  38. self: 0,
  39. doctor: 0,
  40. delivery: 0
  41. },
  42. ageDatas: [
  43. {name: "0~6岁", color: "#ff5442", value: 0},
  44. {name: "7~18岁", color: "#ffc800", value: 0},
  45. {name: "19~30岁", color: "#4ce428", value: 0},
  46. {name: "31~50岁", color: "#24bbfa", value: 0},
  47. {name: "51~64岁", color: "#fb5dab", value: 0},
  48. {name: "65岁以上", color: "#9b5ffd", value: 0}]
  49. },
  50. components: {
  51. vuedals: Vuedals.Component
  52. },
  53. mounted: function(){
  54. //初始化数据
  55. initData(this);
  56. //获得顶部各tab的值
  57. loadData([0,1,2], this); //参数组数表示请求的区域为上中下
  58. //存储请求所带的参数
  59. reqList.push({
  60. level: this.level,
  61. area: this.area,
  62. areaTitle: this.areaTitle,
  63. endDate: this.endDate,
  64. startDate: this.startDate,
  65. lowLevel: this.lowLevel,
  66. tagCode: this.tagCode,
  67. sumType: this.sumType,
  68. disease: this.disease,
  69. dateType: this.dateType
  70. });
  71. //设置监听器, 监听折线图日期变化
  72. var vm = this;
  73. //监听后退按钮的操作
  74. EventBus.$on("back-click", function(arg){
  75. if(reqList.length == 1){
  76. history.go(-1);
  77. }
  78. else{
  79. var preInfo = reqList.pop();
  80. var info = reqList[reqList.length - 1];
  81. vm.level = info.level;
  82. vm.area = info.area;
  83. vm.areaTitle = info.areaTitle;
  84. vm.lowLevel = info.lowLevel;
  85. vm.tagCode = info.tagCode;
  86. vm.sumType = info.sumType;
  87. vm.disease = info.disease;
  88. vm.dateType = info.dateType;
  89. loadData([0,1,2], vm);
  90. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  91. }
  92. });
  93. //监听页面刷新
  94. EventBus.$on("refresh-click", function(arg){
  95. loadData([0,1,2], vm);
  96. });
  97. //弹出筛选框
  98. EventBus.$on('filter-click', function(arg) {
  99. //弹框显示筛选条件
  100. Vuedals.Bus.$emit('new', {
  101. title: '条件筛选',
  102. onClose:function(data){
  103. vm.sumType = data.sumType;
  104. vm.sumTypeName = data.sumTypeName;
  105. vm.disease = data.disease;
  106. vm.diseaseName = data.diseaseName;
  107. //将参数职位初始值
  108. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  109. vm.lowLevel = vm.level - 1;
  110. vm.area = vm.userRole.code;
  111. vm.areaTitle = vm.userRole.name;
  112. vm.dateType = 1;
  113. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  114. //然后清空请求列表数组
  115. reqList.splice(0, reqList.length);
  116. loadData([0, 1, 2], vm);//刷新数据
  117. //存储请求所带的参数
  118. reqList.push({
  119. level: vm.level,
  120. area: vm.area,
  121. areaTitle: vm.areaTitle,
  122. endDate: vm.endDate,
  123. startDate: vm.startDate,
  124. lowLevel: vm.lowLevel,
  125. tagCode: vm.tagCode,
  126. sumType: vm.sumType,
  127. disease: vm.disease,
  128. dateType: vm.dateType
  129. });
  130. EventBus.$emit('update-statistics-year',{selectDate: vm.sumTypeName} );//显示统计维度的名称
  131. EventBus.$emit('update-dimension-name', {dimensionVal: vm.diseaseName});//显示疾病类型的名称
  132. EventBus.$emit('update-statistics-time', {});//更新统计时间
  133. },
  134. component: 'prescription-filter',
  135. props: {
  136. sumType: vm.sumType,
  137. disease: vm.disease
  138. }
  139. });
  140. });
  141. },
  142. methods: {
  143. changeTagCode: function(val){
  144. this.tagCode = val;
  145. if(this.sumType == 2){
  146. //费用统计只查看人均费用的变化趋势
  147. loadData([2], this);
  148. }else{
  149. loadData([1,2], this);
  150. }
  151. //存储请求所带的参数
  152. reqList.push({
  153. level: this.level,
  154. area: this.area,
  155. areaTitle: this.areaTitle,
  156. endDate: this.endDate,
  157. startDate: this.startDate,
  158. lowLevel: this.lowLevel,
  159. tagCode: this.tagCode,
  160. sumType: this.sumType,
  161. disease: this.disease,
  162. dateType: this.dateType
  163. })
  164. },
  165. getBarData: function(arg){
  166. this.dateType = arg.dateType;
  167. loadData([1], this);
  168. },
  169. getPaymentLineData: function(arg){
  170. this.dateType = arg.dateType;
  171. loadData([1], this);
  172. },
  173. getBottomAreaData: function(arg){
  174. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  175. if(arg.level == this.level){
  176. this.lowLevel = arg.lowLevel;
  177. loadData([2], this);
  178. }else{
  179. this.level = arg.level;
  180. //长处方这边level改了lowLevel也需要跟着一起变
  181. this.lowLevel = arg.level - 1;
  182. this.area = arg.area;
  183. this.areaTitle = arg.areaTitle;
  184. loadData([0,1,2], this);
  185. }
  186. EventBus.$emit('update-area-name', {areaName: this.areaTitle});
  187. //存储请求所带的参数
  188. reqList.push({
  189. level: this.level,
  190. area: this.area,
  191. areaTitle: this.areaTitle,
  192. endDate: this.endDate,
  193. startDate: this.startDate,
  194. lowLevel: this.lowLevel,
  195. tagCode: this.tagCode,
  196. sumType: this.sumType,
  197. disease: this.disease,
  198. })
  199. }
  200. }
  201. });
  202. function initData(vm){
  203. //获得缓存中缓存的角色权限
  204. var userRole = window.localStorage.getItem("selectedRole");
  205. if(!userRole){
  206. return false;
  207. }
  208. vm.userRole = JSON.parse(userRole);
  209. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  210. vm.lowLevel = vm.level - 1;
  211. vm.area = vm.userRole.code;
  212. vm.areaTitle = vm.userRole.name;
  213. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  214. var now = new Date();
  215. vm.endDate = now.format("yyyy-MM-dd");
  216. EventBus.$emit('update-statistics-year',{selectDate: vm.sumTypeName} );//显示统计维度的名称
  217. EventBus.$emit('update-dimension-name', {dimensionVal: vm.diseaseName});//显示疾病类型的名称
  218. }
  219. function initReqParams(vm){
  220. //sumType: 1-订单统计,2-费用统计,3-配送统计,4-年龄统计
  221. var reqParam = [];
  222. switch(vm.sumType){
  223. case 1:
  224. //tagCode: 1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
  225. reqParam = [{
  226. url: "/statistics/getPrescriptionCount",
  227. data: {level: vm.level, area: vm.area, disease: vm.disease}
  228. },{
  229. url: "/statistics/getPrescriptionTotalHistogram",
  230. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.tagCode, interval: vm.dateType}
  231. },{
  232. url: "/statistics/getPrescriptionTotalLowLevel",
  233. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  234. }];
  235. break;
  236. case 2:
  237. //dateType: 折线图坐标值1-日,2-周,3-月
  238. //tagCode: 1.总量,2.平均值
  239. vm.startDate = getBeforeMonthStartDate(3, vm.dateType);
  240. reqParam = [{
  241. url: "/statistics/getPrescriptionCost",
  242. data: {level: vm.level, area: vm.area, disease: vm.disease}
  243. },{
  244. url: "/statistics/getPrescriptionCostAvgLine",
  245. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.dateType, startDate: vm.startDate, endDate: vm.endDate}
  246. },{
  247. url: "/statistics/getPrescriptionCostLowLevel",
  248. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  249. }];
  250. break;
  251. case 3:
  252. //tagCode: 1.自取,2.快递配送,3.健管师配送
  253. reqParam = [{
  254. url: "/statistics/getPrescriptionDispatchingTotal",
  255. data: {level: vm.level, area: vm.area, disease: vm.disease}
  256. },{
  257. url: "/statistics/getPrescriptionDispatchingHistogram",
  258. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.tagCode, interval: vm.dateType}
  259. },{
  260. url: "/statistics/getPrescriptionDispatchingLowLevel",
  261. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  262. }];
  263. break;
  264. case 4:
  265. reqParam = [{
  266. url: "/statistics/getPrescriptionAgeTotal",
  267. data: {level: vm.level, area: vm.area, disease: vm.disease}
  268. },{
  269. url: "/statistics/getPrescriptionAgeHistogram",
  270. data: {level: vm.level, area: vm.area, disease: vm.disease}
  271. },{
  272. url: "/statistics/getPrescriptionAgeLowLevel",
  273. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease}
  274. }];
  275. break;
  276. default:
  277. reqParam = [];
  278. break;
  279. };
  280. return reqParam;
  281. }
  282. function loadData(loadArr, vm){
  283. //获取其他请求的参数
  284. var reqParams = initReqParams(vm),
  285. reqPromise = [];
  286. for(i=0; i<loadArr.length; i++){
  287. var j = loadArr[i];
  288. var param = reqParams[j];
  289. reqPromise.push(httpRequest.get(param.url, {data: param.data}));
  290. }
  291. if(reqPromise.length > 0){
  292. Promise.all(reqPromise).then(function(ress){
  293. var res1, res2, res2;
  294. for(var i=0; i<loadArr.length; i++){
  295. var j = loadArr[i] + 1;
  296. if(j == 1){
  297. res1 = ress[i];
  298. }
  299. if(j == 2){
  300. res2 = ress[i];
  301. }
  302. if(j == 3){
  303. res3 = ress[i];
  304. }
  305. }
  306. if(res1){
  307. if(res1.status == 200){
  308. handleTopPanelData(res1.data, vm);
  309. }else{
  310. console.log(res1.msg);
  311. }
  312. }
  313. if(res2){
  314. if(res2.status == 200){
  315. handleSecondPanelData(res2.data, vm);
  316. }else{
  317. console.log(res2.msg);
  318. }
  319. }
  320. if(res3){
  321. if(res3.status == 200){
  322. listHandle(res3.data, vm);
  323. }else{
  324. console.log(res3.msg);
  325. }
  326. }
  327. })
  328. }
  329. }
  330. function handleTopPanelData(data, vm){
  331. switch(vm.sumType){
  332. case 1:
  333. vm.orderTagDatas = {
  334. total: data.total,
  335. finishCount: data.finishCount,
  336. patientCancelCount: data.patientCancelCount,
  337. noReviewedCount: data.noReviewedCount,
  338. processingCount: data.processingCount,
  339. payOuttimeCount: data.payOuttimeCount
  340. };
  341. break;
  342. case 2:
  343. vm.paymentData = {
  344. sum: data.sum,
  345. avg: data.avg
  346. }
  347. break;
  348. case 3:
  349. vm.expressData = {
  350. self: data.seltTotal,
  351. doctor: data.deliveryTotal,
  352. delivery: data.doctorTotal
  353. }
  354. break;
  355. case 4:
  356. var len = vm.ageDatas.length,
  357. color = ['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
  358. objName = ['0age', '7age', '19age', '31age', '51age', '65age'],
  359. arr = [];
  360. for(i=0; i<len; i++){
  361. vm.ageDatas[i].value = data[objName[i]];
  362. }
  363. //绘制饼图
  364. drawPieChart("agePie", vm.ageDatas, color);
  365. }
  366. }
  367. function handleSecondPanelData(data, vm){
  368. switch(vm.sumType){
  369. case 1:
  370. case 3:
  371. var color = "#17b3ec",
  372. xAxisData = [],
  373. seriesData = [];
  374. for(i=0; i<data.length; i++){
  375. var item = data[i];
  376. xAxisData.push(item.date);
  377. seriesData.push(item.count);
  378. }
  379. var names;
  380. if(vm.sumType == 1){
  381. names = ["续方总量", "已完成", "居民取消", "审核未通过", "进行中", "其他原因取消"];
  382. }else if(vm.sumType == 3){
  383. names = ["居民自取", "物流配送", "健管师配送"];
  384. }
  385. EventBus.$emit("draw-bar-chart", {
  386. panelName: "近半年统计",
  387. xData: xAxisData,
  388. yData: seriesData,
  389. quotaName: names[vm.tagCode - 1],
  390. color: color,
  391. unit: "笔",
  392. selectedDateType: vm.dateType
  393. });
  394. break;
  395. case 2:
  396. var yDatas = [],
  397. colors = ['#12b7f5'];
  398. var xData = _.map(data, function(o){
  399. return o.date;
  400. });
  401. var yData = _.map(data, function(o){
  402. return o.avg;
  403. });
  404. yDatas.push(yData);
  405. EventBus.$emit("draw-line-chart", {
  406. panelName : "近三个月人均费用趋势",
  407. quotaNames : ["人均费用"],
  408. xData : xData,
  409. yDatas : yDatas,
  410. colors : colors,
  411. unit: "元",
  412. selectedDateType: vm.dateType
  413. });
  414. break;
  415. case 4:
  416. var color = "#17b3ec",
  417. xAxisData = ['0~6岁', '7~18岁', '19~30岁', '31~50岁', '51~64岁', '65岁以上'],
  418. fieldName = ['0ageRate', '7ageRate', '19ageRate', '31ageRate', '51ageRate', '65ageRate']
  419. seriesData = [];
  420. for(i=0; i<6; i++){
  421. seriesData.push(parseInt(data[fieldName[i]]));
  422. }
  423. drawBarChart("ageBar", xAxisData, seriesData, color, "人均使用次数");
  424. break;
  425. }
  426. }
  427. function listHandle(data, vm){
  428. var list = data;
  429. var topArr = soreRank(getKeyValueArr(list, 'val'));
  430. var arr = _.map(list, function(o, index){
  431. var cols = [o.name, o.val];
  432. return {
  433. rank: topArr[index],
  434. code: o.code,
  435. name: o.name,
  436. cols: cols
  437. }
  438. });
  439. var headers = {
  440. '1': ["排名", "续方总量", "已完成", "居民取消", "审核未通过", "进行中", "其他原因取消"],
  441. '2': ["排名", "费用总计", "人均费用"],
  442. '3': ["排名", "居民自取", "物流配送", "健管师配送"],
  443. '4': ["排名", "绑定设备"],
  444. };
  445. EventBus.$emit("render-area-data",{
  446. level: vm.level,
  447. area: vm.area,
  448. lowLevel: vm.lowLevel,
  449. headers:["排名", headers[vm.sumType][vm.tagCode]],
  450. rows: arr
  451. });
  452. }
  453. /*
  454. * months : 月份差距(例如months=3,则获取今天往前数3个月的那天的值)
  455. */
  456. function getBeforeMonthStartDate(months,type){
  457. //type: 折线图坐标值1-日,2-周,3-月
  458. //从1号开始算每个月开始的时间
  459. var sDate = new Date(),
  460. now = new Date();
  461. sDate.setMonth(now.getMonth() - months + 1);// 包含本月算一个月
  462. var sDateStr = sDate.format("yyyy-MM-dd");
  463. var startDate = "";
  464. if(type == '3'){
  465. startDate = sDateStr.substr(0,8)+"01";
  466. }else{
  467. startDate = sDateStr;
  468. }
  469. return startDate;
  470. }