jbsc-analysis.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. var reqList = [{}]; //记录请求的参数和url,用于后退时使用
  2. var colors={"0":"#5b9db5","1":"#ed7d31","2":"#a5a5a5",
  3. "3":"#ffc000","4":"#44c274","5":"#70ad47",
  4. "6":"#255e91","7":"#9e480e","8":"#7e7e7e","9":"#997300","10":"#264478","11":"#43682b","12":"#5b9db5"}
  5. Vue.use(Vuedals.default);
  6. new Vue({
  7. el: "#main",
  8. data: {
  9. isloading:false, //加载中
  10. valueName: "",
  11. optionsName: [{code:"",title:"全部"}],
  12. valueType:'',
  13. optionsType:[{name:'全部',code:''},{name:'等级医院',code:'1'},{name:'社区医院',code:'2'}],//预约类型
  14. dateValue: [],
  15. pickerOptions: {
  16. disabledDate: function(d) {
  17. return d > new Date();
  18. }
  19. },
  20. ptab:"132", //高危/预警人群分析 131性别、132服务类型
  21. pieData132:[], //饼图数据
  22. pieData131:[], //饼图数据
  23. pieShow131:true,
  24. pieShow132:true,
  25. tabnumber:0,
  26. headerList:[],
  27. tableData:[], //表格数据
  28. topData:{},
  29. //请求页面所需参数
  30. levelList:[{level:"4",areaLevel:"2"},{level:"3",areaLevel:"3"},{level:"2",areaLevel:"4"}], //两种搜索,地区等级对比
  31. areaLevel:"", // 2、市,3、区,4、社区,5、团队\
  32. initareaLevel:"",
  33. initlevel: '',
  34. initarea: '',
  35. level: '',
  36. area: '',
  37. areaTitle: '',
  38. index: '3',
  39. selectedDateType: 1, //折线图坐标值1-日,2-周,3-月
  40. lowLevel: '',
  41. lowCode: '',
  42. chooseYear: '',
  43. userRole: '',
  44. reqListLength:1,
  45. },
  46. components: {
  47. vuedals: Vuedals.Component
  48. },
  49. mounted: function () {
  50. var vm=this
  51. //初始化数据
  52. initData(vm);
  53. vm.getOptionsName() //获取搜索疾病列表
  54. vm.getData()
  55. vm.bindEvent()
  56. },
  57. methods: {
  58. getData:function(isNext,type){ //是否下转
  59. var vm = this
  60. var params={
  61. areaLevel: vm.areaLevel,
  62. level: vm.level,
  63. area: vm.area,
  64. endDate: vm.dateValue[1],
  65. startDate: vm.dateValue[0],
  66. lowLevel: vm.lowLevel
  67. }
  68. if(type=="type"){ //改变预约类型,不会更改转诊率和预警率
  69. loadData([1,2,3,4], vm); //刷新数据
  70. }else{
  71. loadData([0,1,2,3,4], vm); //刷新数据
  72. }
  73. if(isNext){
  74. //存储请求所带的参数
  75. reqList.push(params);
  76. vm.reqListLength=reqList.length
  77. }else{
  78. reqList[reqList.length-1]=params
  79. vm.reqListLength=reqList.length
  80. }
  81. },
  82. //表格tab切换/下转
  83. getnewdata:function(arg){
  84. var vm = this
  85. vm.lowLevel=arg.lowLevel||""
  86. if(arg.level){
  87. vm.level = arg.level
  88. vm.areaLevel = _.find(vm.levelList,{level:vm.level}).areaLevel
  89. }
  90. if(arg.area){
  91. vm.area = arg.area
  92. }
  93. if(arg.areaTitle){
  94. vm.areaTitle = arg.areaTitle
  95. }
  96. vm.getData(arg.level) //有传level,说明是下转
  97. },
  98. //时间选择
  99. changeDate: function (type) {
  100. var vm=this
  101. if(vm.dateValue[0]&&vm.dateValue[1]&&vm.dateValue[0]<=vm.dateValue[1]){
  102. //搜索时,取消下转记录
  103. vm.area=vm.initarea
  104. vm.areaLevel=vm.initareaLevel
  105. vm.level=vm.initlevel
  106. vm.lowLevel = ""
  107. reqList=[{}]; //搜索时清空历史记录,重新搜索
  108. vm.getData(false,type)
  109. vm.initTable()
  110. }else{
  111. vm.$message({
  112. message: '请完善时间选择',
  113. type: 'warning'
  114. });
  115. }
  116. },
  117. //获取疾病筛查表
  118. getOptionsName:function(){
  119. var vm=this
  120. vm.optionsName = [{code:"",title:"全部"}]
  121. var params={}
  122. jbscAPI.surveyTemplates(params).then(function(res) {
  123. if(res.status == 200) {
  124. vm.optionsName=vm.optionsName.concat(res.data)
  125. } else {
  126. vm.$message.error(res.msg)
  127. }
  128. })
  129. },
  130. //筛查表切换
  131. seleName:function(){
  132. var vm=this
  133. vm.changeDate()
  134. },
  135. //预约类型切换
  136. seleType:function(){
  137. var vm=this
  138. vm.changeDate("type")
  139. },
  140. //切换饼图
  141. changePie:function(){
  142. var vm=this
  143. if(vm['pieData'+vm.ptab].length==0||(vm['pieData'+vm.ptab].length==1&&!vm['pieData'+vm.ptab][0].name)){
  144. vm["pieShow"+vm.ptab]=false
  145. }else{
  146. vm["pieShow"+vm.ptab]=true
  147. }
  148. setTimeout(function(){
  149. handlePieData({elId:"pieChart"+vm.ptab,arry: vm['pieData'+vm.ptab], title:{},colors: colors,param:"total"})
  150. },50)
  151. },
  152. backClick:function(){
  153. var vm=this
  154. if (reqList.length == 1) {
  155. history.go(-1);
  156. } else {
  157. var preInfo = reqList.pop();
  158. var info = reqList[reqList.length - 1];
  159. vm.areaLevel = info.areaLevel;
  160. vm.level = info.level;
  161. vm.area = info.area;
  162. vm.lowLevel = info.lowLevel;
  163. vm.getData()
  164. vm.$refs.tableRef.changeTab({level:vm.level,lowlevel:vm.lowLevel}) //表格tab
  165. }
  166. },
  167. bindEvent:function(){
  168. var vm=this
  169. //监听后退按钮的操作
  170. EventBus.$on("back-click", function (arg) {
  171. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  172. vm.backClick()
  173. });
  174. //监听页面刷新
  175. EventBus.$on("refresh-click", function (arg) {
  176. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  177. loadData([0, 1,2,3,4], vm);
  178. });
  179. $("#main").removeClass("c-hide");
  180. },
  181. initTable:function(){
  182. var vm=this
  183. vm.$refs.tableRef.initTable({
  184. //表格表头 lowlevel等级 1:团队 2社区机构 3区级 4市级
  185. headers:[{thead:"名称",param:"name",canclick:true},{thead:"居民预约量",param:"reservationTotal1Amount0"},
  186. {thead:"代预约量",param:"reservationTota2Amount0"},{thead:"预约总量",param:"reservationTotalAmount0"}],
  187. tabnumber:vm.tabnumber
  188. })
  189. },
  190. },
  191. })
  192. function initData(vm) {
  193. //获得缓存中缓存的角色权限
  194. var userRole = window.sessionStorage.getItem("selectedRole");
  195. if (!userRole) {
  196. return false;
  197. }
  198. vm.userRole = JSON.parse(userRole);
  199. //level:2、市,3、区,4、社区,5、团队
  200. vm.initareaLevel = vm.areaLevel = vm.userRole.code == '350200' ? 2 : vm.userRole.code.length == 6 ? 3 : 4;
  201. vm.initlevel = vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  202. vm.initarea =vm.area = vm.userRole.code;
  203. vm.areaTitle = vm.userRole.name;
  204. vm.tabnumber=vm.areaLevel==4?1:vm.areaLevel==3?2:3 //表格显示的tab数
  205. //初始化时间
  206. var now = new Date();
  207. vm.dateValue[1] = new Date().format("yyyy-MM-dd");
  208. var start= new Date();
  209. start.setDate(1)
  210. vm.dateValue[0] = start.format("yyyy-MM-dd")
  211. vm.initTable()
  212. }
  213. function initReqParams(vm) {
  214. var param={
  215. startDate: vm.dateValue[0],
  216. endDate: vm.dateValue[1],
  217. area: vm.area,
  218. level: vm.areaLevel, //2、市,3、区,4、社区,5、团队
  219. slaveKey1 : vm.valueName, // 问卷标题
  220. slaveKey2 : vm.valueType, //代预约类型 1、医院2、社区
  221. }
  222. var reqParam = [{
  223. url: "third/surveyStatis/total", //转诊率和预警率
  224. reqType: 'get',
  225. data:{},
  226. },{
  227. url: "third/surveyStatis/surveyArea", //高危/预警人群分析--饼图
  228. reqType: 'get',
  229. data:{},
  230. }, {
  231. url: "third/surveyStatis/surveyArea", //高危/预警人群分析--饼图
  232. reqType: 'get',
  233. data:{},
  234. }, {
  235. url: "third/surveyStatis/line", //预约趋势分析--折线图
  236. reqType: 'get',
  237. data:{},
  238. },{
  239. url: "third/surveyStatis/lowlevel_all", //预约量分析--表格
  240. reqType: 'get',
  241. data:{},
  242. }];
  243. _.each(reqParam,function(item,index){
  244. item.data=JSON.parse(JSON.stringify(param))
  245. if(index==0){
  246. reqParam[index].data.index="128" //注释:128预约总量
  247. }else if(index==1){
  248. reqParam[index].data.index="131" //131性别、132服务类型
  249. }else if(index==2){
  250. reqParam[index].data.index="132" //131性别、132服务类型
  251. }else if(index==3){
  252. reqParam[index].data.index="128,129,130" //128预约总量、129居民预约量130,代预约量
  253. }else if(index==4){
  254. reqParam[index].data.index="128,129,130" //128预约总量、129居民预约量130,代预约量
  255. reqParam[index].data.sort= 1
  256. reqParam[index].data.level= vm.level
  257. if(vm.lowLevel){
  258. reqParam[index].data.lowLevel = vm.lowLevel
  259. }
  260. }
  261. })
  262. return reqParam;
  263. }
  264. function loadData(loadArr, vm) {
  265. //获取其他请求的参数
  266. var reqParams = initReqParams(vm),
  267. reqPromise = [],
  268. newArr = []; //记录非顶部请求的请求数组
  269. for (i = 0; i < loadArr.length; i++) {
  270. var j = loadArr[i];
  271. var param = reqParams[j];
  272. reqPromise.push(httpRequest.get(param.url, {
  273. data: param.data
  274. }));
  275. newArr.push(loadArr[i]);
  276. }
  277. vm.isloading=true
  278. if (reqPromise.length > 0) {
  279. Promise.all(reqPromise).then(function (ress) {
  280. var res1, res2, res3, res4, res5;
  281. for (var i = 0; i < loadArr.length; i++) {
  282. var j = loadArr[i] + 1;
  283. if (j == 1) { res1 = ress[i]; }
  284. if (j == 2) { res2 = ress[i]; }
  285. if (j == 3) { res3 = ress[i]; }
  286. if (j == 4) { res4 = ress[i]; }
  287. if (j == 5) { res5 = ress[i]; }
  288. }
  289. if (res1 && res1.status == 200) {
  290. vm.topData=res1.data
  291. }
  292. if (res2 && res2.status == 200) {
  293. // res2={"msg":"查询成功!","data":[{"total":100,"code":"1","name":"女"},{"total":200,"code":"2","name":"男"},{"total":30,"code":"3","name":"未知"}],"status":200}
  294. vm.pieData131=res2.data
  295. }
  296. if (res3 && res3.status == 200) {
  297. // res3={"msg":"查询成功!","data":[{"total":11,"code":"1","name":"普通人群"},{"total":11,"code":"10","name":"重性精神疾病"},{"total":11,"code":"11","name":"残疾人"},{"total":0,"code":"12","name":"结核病"},{"total":0,"code":"3","name":"老年人"},{"total":0,"code":"4","name":"高血压"},{"total":0,"code":"5","name":"糖尿病"},{"total":11,"code":"6","name":"孕产妇"},{"total":0,"code":"7","name":"0-6岁儿童"},{"total":0,"code":"8","name":"贫困人口"},{"total":0,"code":"9","name":"计生特殊人群"}],"status":200}
  298. vm.pieData132=res3.data
  299. }
  300. if (res4 && res4.status == 200) {
  301. handleSecondPanelData(res4.data, vm);
  302. }
  303. if (res5 && res5.status == 200) {
  304. listHandle(res5.data, vm);;
  305. }
  306. vm.changePie()
  307. vm.isloading=false
  308. })
  309. }
  310. }
  311. function handleSecondPanelData(data, vm) {
  312. var xDatas = [],
  313. yDatas = [],
  314. names = [],
  315. colors = ['#12b7f5', '#cd67fd','#FF9526'],
  316. labels = {'128': '预约总量', '129': '居民预约量', '130': '代预约量'}
  317. index_names = {'index_128': '预约总量', 'index_129': '居民预约量', 'index_130': '代预约量'};
  318. for(var p in data){
  319. names.push(index_names[p]);
  320. xData = _.map(data[p], function(o){
  321. return o.range;
  322. });
  323. yData = _.map(data[p], function(o){
  324. return o.amount;
  325. });
  326. xDatas.push(xData);
  327. yDatas.push(yData);
  328. }
  329. EventBus.$emit("draw-line-chart", {
  330. panelName : "预约趋势分析",
  331. quotaNames : names,
  332. xData : xDatas[0],
  333. yDatas : yDatas,
  334. colors : colors,
  335. selectedDateType: vm.selectedDateType,
  336. nowlineid : "lineChart",
  337. noDateType: true,
  338. chartheight:"322",
  339. unit:"人次",
  340. noshowDate:true,
  341. });
  342. }
  343. function listHandle(list, vm){
  344. var topArr = [];
  345. if(list.length==1&&!list[0].name){
  346. list=[]
  347. }
  348. topArr = soreRank(getKeyValueArr(list, 'reservationTotalAmount0'));
  349. vm.tableData = _.map(list, function(o, index){
  350. o.rank=topArr[index]
  351. return o
  352. });
  353. EventBus.$emit("render-area-data",{
  354. });
  355. }
  356. //获取结束时间
  357. function getEndDate(chooseYear) {
  358. chooseYear = parseInt(chooseYear);
  359. var endDate = new Date((chooseYear + 1) + '-06-29'),
  360. now = new Date();
  361. var yesterday = new Date(now.setDate(now.getDate() - 1))
  362. if (yesterday <= endDate) {
  363. return yesterday.format("yyyy-MM-dd");
  364. } else {
  365. return (chooseYear + 1) + '-06-29';
  366. }
  367. }