comprehensive-query.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. Vue.use(Vuedals.default);
  2. new Vue({
  3. el: "#main",
  4. data: {
  5. height:"",
  6. isloading:false, //加载中
  7. start:"",
  8. end:"",
  9. tabledata:[], //表格数据
  10. levelList:[{level:"4",areaLevel:"2"},{level:"3",areaLevel:"3"},{level:"2",areaLevel:"4"}], //两种搜索,地区等级对比
  11. areaLevel:"", // 2、市,3、区,4、社区,5、团队
  12. initareaLevel:"",
  13. initlevel: '',
  14. initarea: '',
  15. level: '',
  16. area: '',
  17. areaTitle: '',
  18. index: '121',
  19. lowLevel: '',
  20. initlowLevel:"",
  21. years:[],
  22. chooseYear: '',
  23. userRole: '',
  24. treedata: [],
  25. tableHeader:[],
  26. defaultProps: {
  27. children: 'children',
  28. label: 'label'
  29. },
  30. pickerOptions:{
  31. disabledDate(time) {
  32. return time.getTime() > Date.now()
  33. },
  34. },
  35. radio:'1',
  36. timeLevel: 2,
  37. searchJson:{},
  38. currentPage:1,
  39. currentSize:10,
  40. datatotal:0,
  41. rangeList:[],
  42. rangeCode:"",
  43. areaList:[],
  44. areaCode:"",
  45. communityList:[{code:"",name:"全部"}],
  46. communityCode:"",
  47. teamList:[{code:"",name:"全部"}],
  48. teamCode:"",
  49. },
  50. components: {
  51. vuedals: Vuedals.Component
  52. },
  53. watch: {
  54. rangeCode: function (val) {
  55. var vm=this
  56. if(vm.initlevel != 2){
  57. vm.communityCode=""
  58. }
  59. vm.teamCode=""
  60. vm.getTreeList()
  61. },
  62. areaCode:function(val){
  63. var vm=this
  64. vm.selChange(3)
  65. },
  66. communityCode:function(val){
  67. var vm=this
  68. vm.selChange(5)
  69. },
  70. },
  71. mounted: function () {
  72. var vm=this
  73. //初始化数据
  74. initData(vm);
  75. vm.height = document.body.offsetHeight - 85
  76. window.onresize = function () {
  77. vm.height = document.body.offsetHeight - 85
  78. console.log(vm.height)
  79. }
  80. },
  81. methods: {
  82. getTreeList:function(){
  83. var vm=this
  84. statisticAPI.exportTreeList({rang:vm.rangeCode}).then(function(res){
  85. if(res.status == 200){
  86. vm.treedata = [],jindex=0
  87. _.each(res.data,function(item,index){
  88. vm.treedata.push({
  89. id:"p_"+jindex,
  90. label:index,
  91. children:[]
  92. })
  93. _.each(item,function(citem,cindex){
  94. vm.treedata[jindex].children.push({
  95. id:cindex,
  96. label:citem,
  97. })
  98. })
  99. jindex++
  100. })
  101. }
  102. })
  103. },
  104. beforeReq:function(flag){
  105. var vm=this,startDate="",endDate="",checked=[]
  106. if(vm.radio=="1"){
  107. startDate = getStartDate(vm.chooseYear)
  108. endDate = getEndDate(vm.chooseYear)
  109. vm.timeLevel = 2
  110. }else{
  111. if(!vm.start&&!vm.end){
  112. this.$message({
  113. message: '请选择创建时间',
  114. type: 'warning'
  115. });
  116. return false
  117. }else{
  118. if(vm.start>vm.end){
  119. this.$message({
  120. message: '开始时间应早于结束时间',
  121. type: 'warning'
  122. });
  123. return false
  124. }else{
  125. startDate = vm.start
  126. endDate = vm.end
  127. vm.timeLevel = 1
  128. }
  129. }
  130. }
  131. var checkTree = vm.$refs.tree.getCheckedNodes(true);
  132. if(checkTree.length){
  133. if(!flag){
  134. vm.tableHeader = []
  135. }
  136. _.each(checkTree,function(item,index){
  137. if(!flag){
  138. vm.tableHeader.push({prop:item.label,label:item.label})
  139. }
  140. checked.push(item.id)
  141. })
  142. }else{
  143. this.$message({
  144. message: '请选择搜索指标!',
  145. type: 'warning'
  146. });
  147. return false
  148. }
  149. return {start:startDate,end:endDate,checked:checked.join(",")}
  150. },
  151. searchHandle:function(){
  152. var vm = this,searchJson=undefined
  153. console.log("before-pass")
  154. searchJson = vm.beforeReq()
  155. if(searchJson){
  156. vm.currentPage = 1
  157. vm.searchJson = {
  158. startDate:searchJson.start,
  159. endDate:searchJson.end,
  160. quotaStr:searchJson.checked,
  161. range:vm.rangeCode,
  162. team:vm.teamCode,
  163. hospital:vm.communityCode,
  164. area:vm.areaCode=="350200"?"":vm.areaCode,
  165. size:vm.currentSize,
  166. page:vm.currentPage,
  167. timeLevel: vm.timeLevel
  168. }
  169. vm.getStatisticDataList()
  170. }
  171. },
  172. getStatisticDataList:function(){
  173. var vm = this
  174. vm.isloading = true
  175. var params=JSON.parse(JSON.stringify(vm.searchJson))
  176. params.page = vm.currentPage
  177. statisticAPI.getStatisticDataList(params).then(function(res){
  178. if(res.status == 200) {
  179. vm.tabledata = res.data.data
  180. vm.datatotal = res.data.total
  181. if(vm.tabledata.length){
  182. vm.tableHeader=[]
  183. _.each(vm.tabledata[0],function(item,index){
  184. if(index!="town"&&index!="townName"&&index!="hospital"&&index!="hospitalName"&&index!="area"&&index!="areaName"&&index!="code"&&index!="name")
  185. vm.tableHeader.push({prop:index,label:index})
  186. })
  187. }
  188. } else {
  189. vm.$message.error(res.msg)
  190. }
  191. vm.isloading = false
  192. })
  193. },
  194. exportHandle:function(){
  195. var vm =this
  196. var vm = this,searchJson=undefined
  197. searchJson = vm.beforeReq('export')
  198. if(searchJson){
  199. var areaCode = vm.areaCode=="350200"?"":vm.areaCode
  200. let str = httpRequest.server + 'statisticsExport/export?startDate='+searchJson.start+'&endDate='+searchJson.end+'&quotaStr='+searchJson.checked+'&range='+vm.rangeCode+'&area='+areaCode+'&hospital='+vm.communityCode+'&team='+vm.teamCode+'&timeLevel='+vm.timeLevel
  201. console.log(str)
  202. window.location.href = str
  203. }
  204. },
  205. backClick:function(){
  206. history.go(-1);
  207. },
  208. bindEvent:function(){
  209. var vm=this
  210. //监听后退按钮的操作
  211. EventBus.$on("back-click", function (arg) {
  212. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  213. vm.backClick()
  214. });
  215. //监听页面刷新
  216. EventBus.$on("refresh-click", function (arg) {
  217. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  218. initData(vm)
  219. });
  220. $("#main").removeClass("c-hide");
  221. },
  222. handleCurrentChange:function(val) {
  223. this.currentPage = val
  224. this.getStatisticDataList()
  225. },
  226. //获取省市区 type:区3
  227. getDistrict: function(type,code,name) {
  228. var vm=this,list = [],param=""
  229. if(type == 3){
  230. list = [{code:code,name:name}]
  231. param = "area"
  232. }else if(type == 5){
  233. list = [{code:"",name:"全部"}]
  234. param = "community"
  235. }
  236. var params={
  237. type:type,code:code
  238. }
  239. homeAPI.getDistrict(params).then(function(res) {
  240. if(res.status == 200) {
  241. vm[param+"List"]=list.concat(res.list)
  242. vm[param+"Code"]=vm[param+"List"][0].code
  243. } else {
  244. vm.$message.error(res.msg)
  245. }
  246. })
  247. },
  248. selChange:function(type){
  249. var vm=this,name=""
  250. if(type == 3){
  251. vm.initSelOption("community")
  252. vm.initSelOption("team")
  253. vm.getCommunityHospital()
  254. }else if(type == 5){
  255. vm.initSelOption("team")
  256. vm.teamListByArea()
  257. }
  258. },
  259. initSelOption:function(param){
  260. var vm=this
  261. vm[param+"List"]=[{code:"",name:"全部"}]
  262. if(param == "team"){
  263. vm[param+"List"]=[{id:"",name:"全部"}]
  264. }
  265. vm[param+"Code"]=vm[param+"List"][0].code||vm[param+"List"][0].id
  266. },
  267. getCommunityHospital:function() {
  268. var vm=this,list = [{code:"",name:"全部"}],param="community"
  269. homeAPI.getCommunityHospital({area:vm.areaCode=='350200'?"":vm.areaCode}).then(function(res) {
  270. if(res.status == 200) {
  271. vm[param+"List"]=list.concat(res.data)
  272. vm[param+"Code"]=vm[param+"List"][0].code
  273. } else {
  274. vm.$message.error(res.msg)
  275. }
  276. })
  277. },
  278. teamListByArea:function() {
  279. var vm=this,list = [{id:"",name:"全部"}],param="team"
  280. homeAPI.teamListByArea({area:vm.areaCode=='350200'?"":vm.areaCode,hospital:vm.communityCode}).then(function(res) {
  281. if(res.status == 200) {
  282. vm[param+"List"]=list.concat(res.data)
  283. vm[param+"Code"]=vm[param+"List"][0].id
  284. } else {
  285. vm.$message.error(res.msg)
  286. }
  287. })
  288. }
  289. },
  290. })
  291. function initData(vm) {
  292. //获得缓存中缓存的角色权限
  293. var userRole = window.sessionStorage.getItem("selectedRole");
  294. if (!userRole) {
  295. return false;
  296. }
  297. vm.userRole = JSON.parse(userRole);
  298. //level:2、市,3、区,4、社区,5、团队
  299. vm.initareaLevel = vm.areaLevel = vm.userRole.code == '350200' ? 2 : vm.userRole.code.length == 6 ? 3 : 4;
  300. vm.initlevel = vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  301. // vm.lowLevel = vm.initlowLevel = vm.userRole.code == '350200' ? 3 : vm.userRole.code.length == 6 ? 2 : 1;
  302. vm.initarea =vm.area = vm.userRole.code;
  303. vm.areaTitle = vm.userRole.name;
  304. vm.rangeList=[{name:"按区",code:"town"},{name:"按社区",code:"hospital"},{name:"按团队",code:"team"}]
  305. if(vm.initlevel == 4){ //市获取区
  306. vm.getDistrict(3,vm.initarea,vm.areaTitle.substr(0,3))
  307. vm.rangeCode = vm.rangeList[0].code
  308. }else if(vm.initlevel == 3){ //区获取社区
  309. vm.areaList = [{code:vm.initarea,name:vm.areaTitle}]
  310. vm.areaCode = vm.initarea
  311. vm.rangeCode = vm.rangeList[0].code
  312. }else if(vm.initlevel == 2){ //社区获取团队
  313. vm.communityList = [{code:vm.initarea,name:vm.areaTitle}]
  314. vm.communityCode = vm.initarea
  315. vm.rangeList.shift()
  316. vm.rangeCode = vm.rangeList[0].code
  317. }
  318. vm.searchJson.range = vm.rangeCode
  319. //初始化时间
  320. var now = new Date();
  321. vm.end = now.format("yyyy-MM-dd")
  322. var start = now.getTime() - 30*24*60*60*1000
  323. vm.start = new Date(start).format("yyyy-MM-dd")
  324. vm.nowyear = vm.chooseYear = now.getFullYear()
  325. vm.nowmonth = now.getMonth()+1
  326. vm.years = []
  327. for(i=vm.nowyear; i>=2016; i--){
  328. vm.years.push(i)
  329. }
  330. vm.tabledata = []
  331. vm.bindEvent()
  332. }