report.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!-- -->
  2. <template>
  3. <div class="chart-template chart-template-withperiod">
  4. <p>
  5. <span> 问题整改</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 id="question_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. import { question } from "@/api/board/cockpit.js";
  30. const types = [
  31. {
  32. text: "今天",
  33. value: "1",
  34. },
  35. {
  36. text: "近7天",
  37. value: "2",
  38. },
  39. {
  40. text: "近30天",
  41. value: "3",
  42. },
  43. {
  44. text: "近90天",
  45. value: "4",
  46. },
  47. {
  48. text: "本年",
  49. value: "5",
  50. },
  51. ];
  52. export default {
  53. props: ["orgId"],
  54. data() {
  55. return {
  56. data: {
  57. all: [],
  58. completed: [],
  59. name: [],
  60. },
  61. types,
  62. activeName: types[0].value,
  63. };
  64. },
  65. components: {},
  66. computed: {},
  67. watch: {
  68. orgId: {
  69. deep: true,
  70. handler(val) {
  71. this.resetTimer();
  72. this.getData();
  73. },
  74. },
  75. data: {
  76. deep: true,
  77. handler() {
  78. this.initMap();
  79. },
  80. },
  81. },
  82. created() {
  83. // this.types = types;
  84. this.maxDisplay = 16;
  85. this.refreshTime = 1 * 10 * 1000;
  86. this.isMouseOver = false;
  87. },
  88. async mounted() {
  89. window.addEventListener("resize", this.windowResize);
  90. },
  91. beforeDestroy() {
  92. this.timer && clearInterval(this.timer);
  93. this.timer = null;
  94. window.removeEventListener("resize", this.windowResize);
  95. },
  96. methods: {
  97. handleClick() {
  98. this.resetTimer();
  99. this.getData();
  100. },
  101. handleMouseEnter() {
  102. this.isMouseOver = true;
  103. },
  104. handleMouseLeave() {
  105. this.isMouseOver = false;
  106. },
  107. async getData() {
  108. // let bs = parseInt(this.activeName) + 1;
  109. // this.data = {
  110. // all: 500*bs,
  111. // unconfirm: 112*bs, //未确认
  112. // auditing: 20*bs, //异议审批中
  113. // unreform: 50*bs, //待整改
  114. // notQuestion: 4*bs,
  115. // reformed: (500 - 112 - 20 - 50 - 4)*bs,
  116. // };
  117. let r = (await question({ orgId: this.orgId, period: this.activeName })).data;
  118. this.data = r;
  119. if(r.total==0){
  120. this.data.reformRate=100;
  121. }else{
  122. this.data.reformRate=((r.reformed/r.total)*100).toFixed(0);
  123. }
  124. },
  125. windowResize() {
  126. this.myChart && this.myChart.resize();
  127. },
  128. initMap() {
  129. this.myChart && this.myChart.dispose();
  130. // 基于准备好的dom,初始化echarts实例
  131. this.myChart = echarts.init(document.getElementById("question_Chart"));
  132. let chartData = [
  133. {
  134. name: "未确认",
  135. value: this.data.unconfirm,
  136. },
  137. {
  138. name: "异议审批中",
  139. value: this.data.auditing,
  140. },
  141. {
  142. name: "待整改",
  143. value: this.data.unreform,
  144. },
  145. {
  146. name: "异议隐患",
  147. value: this.data.notQuestion,
  148. },
  149. {
  150. name: "整改完成",
  151. value: this.data.reformed,
  152. },
  153. ];
  154. let t = this;
  155. // 指定图表的配置项和数据
  156. var option = {
  157. title: {
  158. left: "center",
  159. },
  160. tooltip: {
  161. trigger: "item",
  162. formatter: "{a} <br/>{b} : {c} ({d}%)",
  163. },
  164. legend: {
  165. type: "scroll",
  166. orient: "vertical",
  167. right: 10,
  168. top: 20,
  169. bottom: 20,
  170. data: chartData.map((d) => d.name),
  171. formatter: function (name) {
  172. let d = chartData.find((c) => c.name === name);
  173. return d.name + " " + d.value + "项";
  174. },
  175. textStyle: {
  176. color: "white",
  177. },
  178. },
  179. series: [
  180. {
  181. name: "问题整改",
  182. type: "pie",
  183. radius: ["65%", "85%"],
  184. center: ["30%", "50%"],
  185. data: chartData,
  186. label: {
  187. show: true,
  188. position: "center",
  189. color: "#fff",
  190. fontSize: 14,
  191. formatter: function (value) {
  192. return `总数:${t.data.total}\n\n整改率:${t.data.reformRate}%`;
  193. },
  194. },
  195. emphasis: {
  196. itemStyle: {
  197. shadowBlur: 10,
  198. shadowOffsetX: 0,
  199. shadowColor: "rgba(0, 0, 0, 0.5)",
  200. },
  201. },
  202. },
  203. ],
  204. };
  205. if (option && typeof option === "object") {
  206. this.myChart.setOption(option);
  207. }
  208. },
  209. resetTimer() {
  210. this.timer && clearInterval(this.timer);
  211. this.timer = setInterval(() => {
  212. if (this.isMouseOver) {
  213. return;
  214. }
  215. this.activeName = getNextPeriod(this.types, this.activeName);
  216. this.getData();
  217. }, this.refreshTime);
  218. },
  219. },
  220. };
  221. </script>
  222. <style lang="less" scoped></style>