prescription-analysis.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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.areaTile = vm.userRole.name;
  163. var now = new Date();
  164. vm.endDate = now.format("yyyy-MM-dd");
  165. }
  166. function initReqParams(vm){
  167. //sumType: 1-订单统计,2-费用统计,3-配送统计,4-年龄统计
  168. var reqParam = [];
  169. switch(vm.sumType){
  170. case 1:
  171. //tagCode: 1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
  172. reqParam = [{
  173. url: "/statistics/getPrescriptionCount",
  174. data: {level: vm.level, area: vm.area, disease: vm.disease}
  175. },{
  176. url: "/statistics/getPrescriptionTotalHistogram",
  177. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.tagCode, interval: vm.dateType}
  178. },{
  179. url: "/statistics/getPrescriptionTotalLowLevel",
  180. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  181. }];
  182. break;
  183. case 2:
  184. //dateType: 折线图坐标值1-日,2-周,3-月
  185. //tagCode: 1.总量,2.平均值
  186. vm.startDate = getBeforeMonthStartDate(3, vm.dateType);
  187. reqParam = [{
  188. url: "/statistics/getPrescriptionCost",
  189. data: {level: vm.level, area: vm.area, disease: vm.disease}
  190. },{
  191. url: "/statistics/getPrescriptionCostAvgLine",
  192. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.dateType, startDate: vm.startDate, endDate: vm.endDate}
  193. },{
  194. url: "/statistics/getPrescriptionCostLowLevel",
  195. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  196. }];
  197. break;
  198. case 3:
  199. //tagCode: 1.自取,2.快递配送,3.健管师配送
  200. reqParam = [{
  201. url: "/statistics/getPrescriptionDispatchingTotal",
  202. data: {level: vm.level, area: vm.area, disease: vm.disease}
  203. },{
  204. url: "/statistics/getPrescriptionDispatchingHistogram",
  205. data: {level: vm.level, area: vm.area, disease: vm.disease, type: vm.tagCode, interval: vm.dateType}
  206. },{
  207. url: "/statistics/getPrescriptionDispatchingLowLevel",
  208. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease, type: vm.tagCode}
  209. }];
  210. break;
  211. case 4:
  212. reqParam = [{
  213. url: "/statistics/getPrescriptionAgeTotal",
  214. data: {level: vm.level, area: vm.area, disease: vm.disease}
  215. },{
  216. url: "/statistics/getPrescriptionAgeHistogram",
  217. data: {level: vm.level, area: vm.area, disease: vm.disease}
  218. },{
  219. url: "/statistics/getPrescriptionAgeLowLevel",
  220. data: {level: vm.level, lowlevel: vm.lowLevel, area: vm.area, disease: vm.disease}
  221. }];
  222. break;
  223. default:
  224. reqParam = [];
  225. break;
  226. };
  227. return reqParam;
  228. }
  229. function loadData(loadArr, vm){
  230. //获取其他请求的参数
  231. var reqParams = initReqParams(vm),
  232. reqPromise = [];
  233. for(i=0; i<loadArr.length; i++){
  234. var j = loadArr[i];
  235. var param = reqParams[j];
  236. reqPromise.push(httpRequest.get(param.url, {data: param.data}));
  237. }
  238. if(reqPromise.length > 0){
  239. Promise.all(reqPromise).then(function(ress){
  240. var res1, res2, res2;
  241. for(var i=0; i<loadArr.length; i++){
  242. var j = loadArr[i] + 1;
  243. if(j == 1){
  244. res1 = ress[i];
  245. }
  246. if(j == 2){
  247. res2 = ress[i];
  248. }
  249. if(j == 3){
  250. res3 = ress[i];
  251. }
  252. }
  253. if(res1){
  254. if(res1.status == 200){
  255. handleTopPanelData(res1.data, vm);
  256. }else{
  257. console.log(res1.msg);
  258. }
  259. }
  260. if(res2){
  261. if(res2.status == 200){
  262. handleSecondPanelData(res2.data, vm);
  263. }else{
  264. console.log(res2.msg);
  265. }
  266. }
  267. if(res3){
  268. if(res3.status == 200){
  269. listHandle(res3.data, vm);
  270. }else{
  271. console.log(res3.msg);
  272. }
  273. }
  274. })
  275. }
  276. }
  277. function handleTopPanelData(data, vm){
  278. switch(vm.sumType){
  279. case 1:
  280. vm.orderTagDatas = {
  281. total: data.total,
  282. finishCount: data.finishCount,
  283. patientCancelCount: data.patientCancelCount,
  284. noReviewedCount: data.noReviewedCount,
  285. processingCount: data.processingCount,
  286. payOuttimeCount: data.payOuttimeCount
  287. };
  288. break;
  289. case 2:
  290. vm.paymentData = {
  291. sum: data.sum,
  292. avg: data.avg
  293. }
  294. break;
  295. case 3:
  296. vm.expressData = {
  297. self: data.seltTotal,
  298. doctor: data.deliveryTotal,
  299. delivery: data.doctorTotal
  300. }
  301. break;
  302. case 4:
  303. var len = vm.ageDatas.length,
  304. color = ['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
  305. objName = ['0age', '7age', '19age', '31age', '51age', '65age'],
  306. arr = [];
  307. for(i=0; i<len; i++){
  308. vm.ageDatas[i].value = data[objName[i]];
  309. }
  310. //绘制饼图
  311. drawPieChart("agePie", vm.ageDatas, color);
  312. }
  313. }
  314. function handleSecondPanelData(data, vm){
  315. switch(vm.sumType){
  316. case 1:
  317. case 3:
  318. var color = "#17b3ec",
  319. xAxisData = [],
  320. seriesData = [];
  321. for(i=0; i<data.length; i++){
  322. var item = data[i];
  323. xAxisData.push(item.date);
  324. seriesData.push(item.count);
  325. }
  326. var names;
  327. if(vm.sumType == 1){
  328. names = ["续方总量", "已完成", "居民取消", "审核未通过", "进行中", "其他原因取消"];
  329. }else if(vm.sumType == 3){
  330. names = ["居民自取", "物流配送", "健管师配送"];
  331. }
  332. EventBus.$emit("draw-bar-chart", {
  333. panelName: "近半年统计",
  334. xData: xAxisData,
  335. yData: seriesData,
  336. quotaName: names[vm.tagCode - 1],
  337. color: color,
  338. unit: "笔"
  339. });
  340. break;
  341. case 2:
  342. var yDatas = [],
  343. colors = ['#12b7f5'];
  344. var xData = _.map(data, function(o){
  345. return o.date;
  346. });
  347. var yData = _.map(data, function(o){
  348. return o.avg;
  349. });
  350. yDatas.push(yData);
  351. EventBus.$emit("draw-line-chart", {
  352. panelName : "近三个月人均费用趋势",
  353. quotaNames : ["人均费用"],
  354. xData : xData,
  355. yDatas : yDatas,
  356. colors : colors,
  357. unit: "元"
  358. });
  359. break;
  360. case 4:
  361. var color = "#17b3ec",
  362. xAxisData = ['0~6岁', '7~18岁', '19~30岁', '31~50岁', '51~64岁', '65岁以上'],
  363. fieldName = ['0ageRate', '7ageRate', '19ageRate', '31ageRate', '51ageRate', '65ageRate']
  364. seriesData = [];
  365. for(i=0; i<6; i++){
  366. seriesData.push(parseInt(data[fieldName[i]]));
  367. }
  368. drawBarChart("ageBar", xAxisData, seriesData, color, "人均使用次数");
  369. break;
  370. }
  371. }
  372. function listHandle(data, vm){
  373. var list = data;
  374. var topArr = soreRank(getKeyValueArr(list, 'val'));
  375. var arr = _.map(list, function(o, index){
  376. var cols = [o.name, o.val];
  377. return {
  378. rank: topArr[index],
  379. code: o.code,
  380. name: o.name,
  381. cols: cols
  382. }
  383. });
  384. var headers = {
  385. '1': ["排名", "续方总量", "已完成", "居民取消", "审核未通过", "进行中", "其他原因取消"],
  386. '2': ["排名", "费用总计", "人均费用"],
  387. '3': ["排名", "居民自取", "物流配送", "健管师配送"],
  388. '4': ["排名", "绑定设备"],
  389. };
  390. EventBus.$emit("render-area-data",{
  391. level: vm.level,
  392. area: vm.area,
  393. lowLevel: vm.lowLevel,
  394. headers:["排名", headers[vm.sumType][vm.tagCode]],
  395. rows: arr
  396. });
  397. }
  398. /*
  399. * months : 月份差距(例如months=3,则获取今天往前数3个月的那天的值)
  400. */
  401. function getBeforeMonthStartDate(months,type){
  402. //type: 折线图坐标值1-日,2-周,3-月
  403. //从1号开始算每个月开始的时间
  404. var sDate = new Date(),
  405. now = new Date();
  406. sDate.setMonth(now.getMonth() - months + 1);// 包含本月算一个月
  407. var sDateStr = sDate.format("yyyy-MM-dd");
  408. var startDate = "";
  409. if(type == '3'){
  410. startDate = sDateStr.substr(0,8)+"01";
  411. }else{
  412. startDate = sDateStr;
  413. }
  414. return startDate;
  415. }