prescription-analysis.js 15 KB

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