smfw-ruhufangshi-analysis.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. start:"",
  11. end:"",
  12. pieData:[], //饼图数据
  13. tabnumber:0,
  14. tabledata0:[], //表格数据
  15. topData:{},
  16. //请求页面所需参数
  17. levelList:[{level:"4",areaLevel:"2"},{level:"3",areaLevel:"3"},{level:"2",areaLevel:"4"}], //两种搜索,地区等级对比
  18. areaLevel:"", // 2、市,3、区,4、社区,5、团队
  19. initareaLevel:"",
  20. initlevel: '',
  21. initarea: '',
  22. level: '',
  23. area: '',
  24. areaTitle: '',
  25. lowLevel: '',
  26. initlowLevel:"",
  27. lowCode: '',
  28. chooseYear: '',
  29. userRole: '',
  30. pieShow:true,
  31. pieShow1:true,
  32. reqListLength:1,
  33. },
  34. components: {
  35. vuedals: Vuedals.Component
  36. },
  37. mounted: function () {
  38. var vm=this
  39. //初始化数据
  40. initData(vm);
  41. },
  42. methods: {
  43. getData:function(isNext,type){ //是否下转
  44. var vm = this
  45. var params={
  46. areaLevel: vm.areaLevel,
  47. level: vm.level,
  48. area: vm.area,
  49. endDate: vm.end,
  50. startDate: vm.start,
  51. lowLevel: vm.lowLevel,
  52. areaTitle:vm.areaTitle
  53. }
  54. loadData([0,1,2,3], vm); //刷新数据
  55. if(isNext){
  56. //存储请求所带的参数
  57. reqList.push(params);
  58. vm.reqListLength=reqList.length
  59. }else{
  60. reqList[reqList.length-1]=params
  61. vm.reqListLength=reqList.length
  62. }
  63. },
  64. //表格tab切换/下转
  65. getnewdata:function(arg){
  66. var vm = this
  67. vm.lowLevel=arg.lowLevel||""
  68. if(arg.level){
  69. vm.level = arg.level
  70. vm.areaLevel = _.find(vm.levelList,{level:vm.level}).areaLevel
  71. }
  72. if(arg.area){
  73. vm.area = arg.area
  74. }
  75. if(arg.areaTitle){
  76. vm.areaTitle = arg.areaTitle
  77. }
  78. vm.getData(arg.level) //有传level,说明是下转
  79. },
  80. //重新搜索
  81. initSearchHandle: function (arg) {
  82. var vm=this
  83. vm.start = arg.start
  84. vm.end = arg.end
  85. //搜索时,取消下转记录
  86. vm.area=vm.initarea
  87. vm.areaLevel=vm.initareaLevel
  88. vm.level=vm.initlevel
  89. vm.lowLevel = vm.initlowLevel
  90. reqList=[{}]; //搜索时清空历史记录,重新搜索
  91. vm.getData()
  92. vm.initTable()
  93. },
  94. showTab:function(){
  95. },
  96. backClick:function(){
  97. var vm=this
  98. if (reqList.length == 1) {
  99. history.go(-1);
  100. } else {
  101. var preInfo = reqList.pop();
  102. var info = reqList[reqList.length - 1];
  103. vm.areaLevel = info.areaLevel;
  104. vm.level = info.level;
  105. vm.area = info.area;
  106. vm.lowLevel = info.lowLevel;
  107. vm.getData()
  108. vm.$refs.tableRef0.changeTab({level:vm.level,lowlevel:vm.lowLevel}) //表格tab
  109. }
  110. },
  111. bindEvent:function(){
  112. var vm=this
  113. //监听后退按钮的操作
  114. EventBus.$on("back-click", function (arg) {
  115. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  116. vm.backClick()
  117. });
  118. //监听页面刷新
  119. EventBus.$on("refresh-click", function (arg) {
  120. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  121. initData(vm)
  122. });
  123. $("#main").removeClass("c-hide");
  124. },
  125. initTable:function(){
  126. var vm=this
  127. vm.$refs.tableRef0.initTable({
  128. tabList:[{name:"各区",level:"4",lowlevel:"3",isShow:true},{name:"社区",level:"3",lowlevel:"4",isShow:true},{name:"团队",level:"2",lowlevel:"5",isShow:true}],
  129. //表格表头
  130. headers:[{thead:"排名",param:"name",canclick:true},{thead:"访视人数",param:"rehabilitationTotalAmount0"}],
  131. tabnumber:vm.tabnumber
  132. })
  133. },
  134. },
  135. })
  136. function initData(vm) {
  137. //获得缓存中缓存的角色权限
  138. var userRole = window.sessionStorage.getItem("selectedRole");
  139. if (!userRole) {
  140. return false;
  141. }
  142. vm.userRole = JSON.parse(userRole);
  143. //level:2、市,3、区,4、社区,5、团队
  144. vm.initareaLevel = vm.areaLevel = vm.userRole.code == '350200' ? 2 : vm.userRole.code.length == 6 ? 3 : 4;
  145. vm.initlevel = vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  146. vm.lowLevel = vm.initlowLevel = vm.userRole.code == '350200' ? 3 : vm.userRole.code.length == 6 ? 4 : 5;
  147. vm.initarea =vm.area = vm.userRole.code;
  148. vm.areaTitle = vm.userRole.name;
  149. vm.tabnumber=vm.areaLevel==4?1:vm.areaLevel==3?2:3 //表格显示的tab数
  150. //初始化时间
  151. EventBus.$emit("init-FilterDate")
  152. vm.bindEvent()
  153. }
  154. function initReqParams(vm) {
  155. var reqParam = [{
  156. url: "statistics/getHomeVisitTotalHead", //头部
  157. reqType: 'get',
  158. data:{
  159. startDate: vm.start,
  160. endDate: vm.end,
  161. area: vm.area,
  162. level: vm.areaLevel, //2、市,3、区,4、社区,5、团队
  163. index:150,
  164. },
  165. },{
  166. url: "statistics/getSpecialistTypeCircle", //访视对象分析150
  167. reqType: 'get',
  168. data:{
  169. startDate: vm.start,
  170. endDate: vm.end,
  171. area: vm.area,
  172. level: vm.areaLevel, //等级,4 市 3区 2社区 1团队
  173. index:150,
  174. },
  175. },{
  176. url: "statistics/getSpecialistTypeCircle", //访视完成情况分析152
  177. reqType: 'get',
  178. data:{
  179. startDate: vm.start,
  180. endDate: vm.end,
  181. area: vm.area,
  182. level: vm.areaLevel, //等级,4 市 3区 2社区 1团队
  183. index:152,
  184. },
  185. },{
  186. url: "statistics/rehabilitationLowLevel", //列表151
  187. reqType: 'get',
  188. data:{
  189. startDate: vm.start,
  190. endDate: vm.end,
  191. area: vm.area,
  192. level: vm.areaLevel, //等级,4 市 3区 2社区 1团队
  193. sort: 1,
  194. lowLevel:vm.lowLevel||"", //等级 5:团队 4社区机构 3区级 2市级,
  195. index:151,
  196. },
  197. }];
  198. return reqParam;
  199. }
  200. function loadData(loadArr, vm) {
  201. //获取其他请求的参数
  202. var reqParams = initReqParams(vm),
  203. reqPromise = [],
  204. newArr = []; //记录非顶部请求的请求数组
  205. for (i = 0; i < loadArr.length; i++) {
  206. var j = loadArr[i];
  207. var param = reqParams[j];
  208. reqPromise.push(httpRequest.get(param.url, {
  209. data: param.data
  210. }));
  211. newArr.push(loadArr[i]);
  212. }
  213. vm.isloading=true
  214. if (reqPromise.length > 0) {
  215. Promise.all(reqPromise).then(function (ress) {
  216. var res1, res2, res3, res4, res5;
  217. for (var i = 0; i < loadArr.length; i++) {
  218. var j = loadArr[i] + 1;
  219. if (j == 1) { res1 = ress[i]; }
  220. if (j == 2) { res2 = ress[i]; }
  221. if (j == 3) { res3 = ress[i]; }
  222. if (j == 4) { res4 = ress[i]; }
  223. if (j == 5) { res5 = ress[i]; }
  224. }
  225. if(res1&& res1.status == 200){
  226. vm.topData=res1.data
  227. }
  228. if(res2&& res2.status == 200){
  229. if(res2.data.length==0||(res2.data.length==1&&!res2.data[0].slaveKey1Name)){
  230. vm.pieShow=false
  231. }else{
  232. vm.pieShow=true
  233. vm.$nextTick(function(){
  234. handlePieData({elId:"pieChart", arry:res2.data, title:{}, colors:colors,position:['30%', '51%'], radius:['70%', '90%'],nameparam:"slaveKey1Name",param:"total"})
  235. })
  236. }
  237. }
  238. if(res3&& res3.status == 200){
  239. if(res3.data.length==0||(res3.data.length==1&&!res3.data[0].slaveKey1Name)){
  240. vm.pieShow1=false
  241. }else{
  242. vm.pieShow1=true
  243. vm.$nextTick(function(){
  244. handlePieData({elId:"pieChart1", arry:res3.data, title:{}, colors:colors,position:['30%', '51%'], radius:['70%', '90%'],nameparam:"slaveKey1Name",param:"total"})
  245. })
  246. }
  247. }
  248. if(res4&& res4.status == 200){
  249. vm.tabledata0=listHandle(res4.data,"rehabilitationTotalAmount0", vm);
  250. }
  251. vm.isloading=false
  252. })
  253. }
  254. }
  255. function listHandle(list,param, vm){
  256. var topArr = [];
  257. if(list.length==1&&!list[0].name){
  258. list=[]
  259. }
  260. topArr = soreRank(getKeyValueArr(list, param||"amount"));
  261. var newlist = _.map(list, function(o, index){
  262. o.rank=topArr[index]
  263. return o
  264. });
  265. EventBus.$emit("render-area-data",{
  266. });
  267. return newlist
  268. }