comprehensive-query.js 9.5 KB

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