report.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!-- -->
  2. <template>
  3. <div class="chart-template chart-template-withperiod">
  4. <p>
  5. <span> {{title}} </span>
  6. </p>
  7. <div>
  8. <el-tabs v-model="activeName" @tab-click="handleClick">
  9. <el-tab-pane
  10. v-for="t in types"
  11. :key="t.value"
  12. :label="t.text"
  13. :name="t.value"
  14. ></el-tab-pane>
  15. </el-tabs>
  16. </div>
  17. <div ref='chart'></div>
  18. </div>
  19. </template>
  20. <script>
  21. import "./../../board.scss";
  22. import * as echarts from "echarts";
  23. import {
  24. findMaxIndex,
  25. getChartDOMSize,
  26. getNextPeriod,
  27. getPeriodText,
  28. } from "../../utils.js";
  29. const types = [
  30. {
  31. text: "今天",
  32. value: "0",
  33. },
  34. {
  35. text: "近7天",
  36. value: "1",
  37. },
  38. {
  39. text: "近30天",
  40. value: "2",
  41. },
  42. {
  43. text: "近90天",
  44. value: "3",
  45. },
  46. {
  47. text: "本年",
  48. value: "4",
  49. },
  50. ];
  51. export default {
  52. props: {
  53. orgId:{
  54. type:String,
  55. isRequired:true
  56. },
  57. title:{
  58. type:String,
  59. isRequired:true
  60. }
  61. },
  62. data() {
  63. return {
  64. data: {
  65. all: [],
  66. completed: [],
  67. name: [],
  68. },
  69. activeName: types[0].value,
  70. };
  71. },
  72. components: {},
  73. computed: {},
  74. watch: {
  75. orgId: {
  76. deep: true,
  77. handler(val) {
  78. this.resetTimer();
  79. this.getData();
  80. },
  81. },
  82. data: {
  83. deep: true,
  84. handler() {
  85. this.initMap();
  86. },
  87. },
  88. },
  89. created() {
  90. this.types = types;
  91. this.maxDisplay = 16;
  92. this.refreshTime = 1 * 10 * 1000;
  93. this.isMouseOver = false;
  94. },
  95. async mounted() {
  96. window.addEventListener("resize", this.windowResize);
  97. },
  98. beforeDestroy() {
  99. this.timer && clearInterval(this.timer);
  100. this.timer = null;
  101. window.removeEventListener("resize", this.windowResize);
  102. },
  103. methods: {
  104. handleClick() {
  105. this.resetTimer();
  106. this.getData();
  107. },
  108. handleMouseEnter() {
  109. this.isMouseOver = true;
  110. },
  111. handleMouseLeave() {
  112. this.isMouseOver = false;
  113. },
  114. async getData() {
  115. let bs = parseInt(this.activeName) + 1;
  116. this.data = {
  117. all: [210 * bs, 101 * bs, 117 * bs, 78 * bs, 107 * bs, 105 * bs],
  118. completed: [155 * bs, 99 * bs, 110 * bs, 78 * bs, 104 * bs, 102 * bs],
  119. name: ["福州", "漳州", "泉州", "三明", "南平", "宁德"],
  120. };
  121. this.data.rate=[];
  122. this.data.all.forEach((v,i)=>{
  123. this.data.rate[i]=this.data.completed[i]/this.data.all[i]*100
  124. })
  125. console.info(this.data)
  126. },
  127. windowResize() {
  128. this.myChart && this.myChart.resize();
  129. },
  130. initMap() {
  131. this.myChart && this.myChart.dispose();
  132. let c=this.$refs["chart"];
  133. // 基于准备好的dom,初始化echarts实例
  134. this.myChart = echarts.init(
  135. c
  136. // document.getElementById("commAlarmEvent_Chart")
  137. );
  138. let t = this;
  139. // 指定图表的配置项和数据
  140. var option = {
  141. // color: ["#82D5AE"],
  142. tooltip: {
  143. trigger: "axis",
  144. confine: true,
  145. axisPointer: {
  146. type: "shadow",
  147. },
  148. formatter:"{c}%"
  149. },
  150. legend: {
  151. show:true,
  152. textStyle:{
  153. color:"rgb(245, 245, 245)"
  154. }
  155. },
  156. grid: {
  157. left: "3%",
  158. right: "4%",
  159. bottom: "2%",
  160. top: "40px",
  161. containLabel: true,
  162. },
  163. xAxis: [
  164. {
  165. type: "category",
  166. data: this.data.name,
  167. // data: this.mapdata.totalDataVo.xlist,
  168. axisTick: {
  169. alignWithLabel: true,
  170. },
  171. axisLine: {
  172. show: true,
  173. lineStyle: {
  174. type: "solid",
  175. color: "rgb(245, 245, 245)", //左边线的颜⾊
  176. },
  177. },
  178. axisLabel: {
  179. interval: 0,
  180. rotate: -30,
  181. fontSize: 12,
  182. color: "#fff",
  183. },
  184. },
  185. ],
  186. yAxis: [
  187. {
  188. type: "value",
  189. minInterval: 1,
  190. // max: function (value) {
  191. // let m = value.max == Math.ceil(value.max) ? Math.ceil(value.max * 1.0001) : Math.ceil(value.max);
  192. // return m
  193. // },
  194. },
  195. ],
  196. series: [
  197. // {
  198. // name: "总数",
  199. // type: "bar",
  200. // barWidth: "14",
  201. // // label: {
  202. // // show: true,
  203. // // position: 'top',
  204. // // },
  205. // data: this.data.all,
  206. // },
  207. {
  208. name: "完成率",
  209. type: "bar",
  210. barWidth: "14",
  211. // label: {
  212. // show: true,
  213. // position: 'top',
  214. // },
  215. data: this.data.rate,
  216. itemStyle: {
  217. normal: {
  218. label: {
  219. formatter: function (param) {
  220. // if (t.data.all[param.dataIndex]) {
  221. // let rate = param.value / t.data.all[param.dataIndex];
  222. // return (Math.floor(rate * 1000) / 10).toFixed(1) + "%";
  223. // } else {
  224. // return "";
  225. // }
  226. return param.value.toFixed(1) + "%"
  227. },
  228. show: true,
  229. position: "top",
  230. textStyle: {
  231. fontWeight: "bolder",
  232. fontSize: "12",
  233. color: "rgb(245, 245, 245)",
  234. },
  235. },
  236. },
  237. },
  238. },
  239. ],
  240. };
  241. if (option && typeof option === "object") {
  242. this.myChart.setOption(option);
  243. }
  244. },
  245. resetTimer() {
  246. this.timer && clearInterval(this.timer);
  247. this.timer = setInterval(() => {
  248. if (this.isMouseOver) {
  249. return;
  250. }
  251. this.activeName = getNextPeriod(this.types, this.activeName);
  252. this.getData();
  253. }, this.refreshTime);
  254. },
  255. },
  256. };
  257. </script>
  258. <style lang="less" scoped></style>