table-qc.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <table class="com-table">
  3. <thead>
  4. <tr>
  5. <th
  6. v-for="(col, index) of data.column"
  7. :key="index"
  8. :class="{ light: col.is_light }"
  9. :style="{ width: col.width }"
  10. @click="onSort(col)"
  11. >
  12. {{ col.name }}
  13. </th>
  14. </tr>
  15. </thead>
  16. <!-- <el-scrollbar> -->
  17. <tbody>
  18. <tr v-for="(row, index) of tableData" :key="index">
  19. <td
  20. v-for="(col, i) of data.column"
  21. :key="i"
  22. :style="{
  23. width: col.width,
  24. textAlign: col.field == 'wtCode' ? 'center' : 'right',
  25. }"
  26. :class="{
  27. light: hoverRow == row || hoverCol == col,
  28. num: col.is_num,
  29. 'always-light': col.is_light || row.is_light,
  30. }"
  31. @mouseenter="hover(row, col)"
  32. @mouseleave="leave()"
  33. >
  34. <component
  35. :is="col.type ? col.type : 'div'"
  36. v-bind="col.props"
  37. v-html="template(col, row[col.field])"
  38. @click="onClick(col, row)"
  39. ></component>
  40. </td>
  41. </tr>
  42. </tbody>
  43. <!-- </el-scrollbar> -->
  44. <el-pagination
  45. class="mg-t-8"
  46. v-if="pageable"
  47. @current-change="handleCurrentChange"
  48. :current-page="currentPage4"
  49. :page-size="pageSize"
  50. layout="total, prev, pager, next, jumper"
  51. :total="data.total"
  52. ></el-pagination>
  53. <el-dialog
  54. v-model="dialogShow"
  55. width="70%"
  56. top="40px"
  57. custom-class="modal"
  58. :close-on-click-modal="true"
  59. >
  60. <template #title>
  61. <div class="dialog-title">
  62. <div class="title">{{ dialogTitle }}</div>
  63. </div>
  64. </template>
  65. <div class="chart" id="chartDiv" height="500px"></div>
  66. </el-dialog>
  67. </table>
  68. </template>
  69. <script>
  70. import * as echarts from "echarts";
  71. export default {
  72. // 名称
  73. name: "ComTable",
  74. // 使用组件
  75. components: {},
  76. // 传入参数
  77. props: {
  78. data: Object,
  79. // hover 样式
  80. showHover: {
  81. type: Boolean,
  82. default: true,
  83. },
  84. // 列高亮
  85. showColHover: {
  86. type: Boolean,
  87. default: false,
  88. },
  89. canScroll: {
  90. type: Boolean,
  91. default: true,
  92. },
  93. pageSize: {
  94. type: Number,
  95. default: 0,
  96. },
  97. height: {
  98. type: String,
  99. default: "",
  100. },
  101. },
  102. // 自定义事件
  103. emits: {
  104. // 分页事件
  105. onPagging: null,
  106. },
  107. // 数据
  108. data() {
  109. let that = this;
  110. return {
  111. hoverRow: -1,
  112. hoverCol: -1,
  113. sortCol: "",
  114. sortType: "",
  115. currentPage: 1,
  116. dialogShow: false,
  117. dialogTitle: "",
  118. dialogData: {},
  119. myChart: null,
  120. };
  121. },
  122. computed: {
  123. tableData() {
  124. let that = this;
  125. if (this.sortCol == "") {
  126. return this.data.data;
  127. } else {
  128. let data = this.data.data;
  129. data.sort((a, b) => {
  130. let rev = 1;
  131. if (that.sortType == "ASC") rev = 1;
  132. else if (that.sortType == "DESC") rev = -1;
  133. if (a[that.sortCol] > b[that.sortCol]) return rev * 1;
  134. if (a[that.sortCol] < b[that.sortCol]) return rev * -1;
  135. return 0;
  136. });
  137. return data;
  138. }
  139. },
  140. pageable() {
  141. return this.pageSize != 0;
  142. },
  143. pages() {
  144. if (this.pageable) return parseInt(this.data.total / this.pageSize) + 1;
  145. else return 0;
  146. },
  147. startRow() {
  148. if (this.pageable) return (this.currentPage - 1) * this.pageSize;
  149. else return 0;
  150. },
  151. endRow() {
  152. if (this.pageable) return this.currentPage * this.pageSize;
  153. else return this.data.data.length;
  154. },
  155. },
  156. // 函数
  157. methods: {
  158. clearCheckBox(time) {
  159. this.$nextTick(() => {
  160. setTimeout(() => {
  161. const domArray = document.querySelectorAll(".curCheckBox");
  162. for (let i = 0; i < domArray.length; i++) {
  163. domArray[i].checked = false;
  164. }
  165. }, time || 300);
  166. });
  167. },
  168. onClick(col, row) {
  169. const curIndex = row.curIndex;
  170. this.clearChart();
  171. let subUrl = "";
  172. let data = {};
  173. let method = "GET";
  174. if ("deviationRate2" == col.field) {
  175. data.type = "sjbz";
  176. subUrl = curIndex
  177. ? "/leaderboard/getCurvechatAjax"
  178. : "/leaderboard/curveMonthchatAjax";
  179. }
  180. // else if ("deviationRate1" == col.field) {
  181. // data.type = "sjzy";
  182. // } else if ("deviationRate3" == col.field) {
  183. // data.type = "zybz";
  184. // }
  185. else if ("monthDeviationRate" == col.field) {
  186. data.type = "hb";
  187. subUrl = curIndex
  188. ? "/leaderboard/curvechatAjaxhb"
  189. : "/leaderboard/curveMonthchatAjaxhb";
  190. } else if ("yearDeviationRate" == col.field) {
  191. data.type = "tb";
  192. subUrl = curIndex
  193. ? "/leaderboard/curvechatAjaxtb"
  194. : "/leaderboard/curveMonthchatAjaxtb";
  195. } else if ("standardDeviationRate" == col.field) {
  196. data.type = "bg";
  197. subUrl = curIndex
  198. ? "/leaderboard/curvechatAjaxbg"
  199. : "/leaderboard/curveMonthchatAjaxbg";
  200. } else {
  201. return 0;
  202. }
  203. this.dialogShow = true;
  204. this.dialogTitle = "曲线偏差率排行";
  205. if (curIndex) {
  206. data.recorddate = row.recordDate;
  207. } else {
  208. data.year = row.year;
  209. data.month = row.month;
  210. }
  211. data["wtId"] = row.windturbineId;
  212. let that = this;
  213. that.API.requestData({
  214. baseURL: process.env.VUE_APP_NEW_WISDOM,
  215. method,
  216. subUrl,
  217. data,
  218. success(res) {
  219. if (res.code === 200) {
  220. const linedata1 = [];
  221. const linedata2 = [];
  222. const names = [res.data.name1, res.data.name2];
  223. res.data.datas.forEach((item, index) => {
  224. linedata1.push(item["value2"]);
  225. linedata2.push(item["value3"]);
  226. });
  227. that.dialogShow = true;
  228. that.dialogTitle = "曲线偏差率排行";
  229. that.initChart(linedata1, linedata2, names);
  230. }
  231. },
  232. });
  233. },
  234. clearChart() {
  235. const chartDom = document.getElementById("chartDiv");
  236. chartDom && chartDom.removeAttribute("_echarts_instance_");
  237. },
  238. initChart(data1, data2, names) {
  239. let that = this;
  240. let myChart = echarts.init(document.getElementById("chartDiv"));
  241. let option = {
  242. color: ["#05bb4c", "#4b55ae"],
  243. tooltip: {
  244. trigger: "axis",
  245. },
  246. legend: {
  247. show: true,
  248. data: names,
  249. right: 56,
  250. icon: "circle",
  251. itemWidth: 6,
  252. inactiveColor: "#606769",
  253. textStyle: {
  254. color: "#B3BDC0",
  255. fontSize: 12,
  256. },
  257. },
  258. grid: {
  259. top: 32,
  260. left: 40,
  261. right: 40,
  262. bottom: 24,
  263. },
  264. xAxis: [
  265. {
  266. type: "category",
  267. boundaryGap: false,
  268. axisLabel: {
  269. formatter: "{value}",
  270. fontSize: 9.35925925925926,
  271. textStyle: {
  272. color: "#606769",
  273. },
  274. },
  275. axisLine: {
  276. show: false,
  277. },
  278. data: [
  279. "0",
  280. "1",
  281. "2",
  282. "3",
  283. "4",
  284. "5",
  285. "6",
  286. "7",
  287. "8",
  288. "9",
  289. "10",
  290. "11",
  291. "12",
  292. "13",
  293. "14",
  294. "15",
  295. "16",
  296. "17",
  297. "18",
  298. "19",
  299. "20",
  300. "21",
  301. "22",
  302. "23",
  303. "24",
  304. "25",
  305. ],
  306. },
  307. ],
  308. yAxis: [
  309. {
  310. type: "value",
  311. name: "(W)",
  312. axisLabel: {
  313. formatter: "{value}",
  314. fontSize: 9.35925925925926,
  315. },
  316. axisLine: {
  317. show: false,
  318. },
  319. splitLine: {
  320. show: true,
  321. lineStyle: {
  322. color: "#606769",
  323. type: "dashed",
  324. },
  325. },
  326. },
  327. ],
  328. series: [
  329. {
  330. name: names[0],
  331. type: "line",
  332. smooth: true,
  333. showSymbol: false,
  334. zlevel: 0,
  335. lineStyle: {
  336. normal: {
  337. color: "#05bb4c",
  338. width: 1,
  339. },
  340. emphasis: {
  341. color: "#05bb4c",
  342. },
  343. },
  344. areaStyle: {
  345. normal: {
  346. color: {
  347. colorStops: [
  348. {
  349. offset: 0,
  350. color: "rgba(5,187,76,0.3)",
  351. },
  352. {
  353. offset: 1,
  354. color: "rgba(5,187,76,0.1)",
  355. },
  356. ],
  357. x: 0,
  358. y: 0,
  359. x2: 0,
  360. y2: 1,
  361. type: "linear",
  362. global: false,
  363. },
  364. shadowColor: "rgba(5,187,76,0.1)",
  365. shadowBlur: 10,
  366. },
  367. emphasis: {
  368. color: {
  369. colorStops: [
  370. {
  371. offset: 0,
  372. color: "rgba(5,187,76,0.3)",
  373. },
  374. {
  375. offset: 1,
  376. color: "rgba(5,187,76,0.1)",
  377. },
  378. ],
  379. x: 0,
  380. y: 0,
  381. x2: 0,
  382. y2: 1,
  383. type: "linear",
  384. global: false,
  385. },
  386. shadowColor: "rgba(5,187,76,0.1)",
  387. shadowBlur: 10,
  388. },
  389. },
  390. yAxisIndex: 0,
  391. data: data1,
  392. },
  393. {
  394. name: names[1],
  395. type: "line",
  396. smooth: true,
  397. showSymbol: false,
  398. zlevel: 2,
  399. lineStyle: {
  400. normal: {
  401. color: "#606769",
  402. width: 1,
  403. },
  404. emphasis: {
  405. color: "#fa8c16",
  406. },
  407. },
  408. areaStyle: {
  409. normal: {
  410. color: "transparent",
  411. shadowColor: "rgba(250,140,22,0.1)",
  412. shadowBlur: 10,
  413. },
  414. emphasis: {
  415. color: {
  416. colorStops: [
  417. {
  418. offset: 0,
  419. color: "rgba(250,140,22,0.3)",
  420. },
  421. {
  422. offset: 1,
  423. color: "rgba(250,140,22,0.1)",
  424. },
  425. ],
  426. x: 0,
  427. y: 0,
  428. x2: 0,
  429. y2: 1,
  430. type: "linear",
  431. global: false,
  432. },
  433. shadowColor: "rgba(250,140,22,0.1)",
  434. shadowBlur: 10,
  435. },
  436. },
  437. yAxisIndex: 0,
  438. data: data2,
  439. },
  440. ],
  441. };
  442. myChart.clear();
  443. myChart.setOption(option);
  444. this.resize = function () {
  445. myChart.resize();
  446. };
  447. window.addEventListener("resize", this.resize);
  448. myChart.resize();
  449. },
  450. onSort(col) {
  451. if (col.sortable == true) {
  452. this.sortCol = col.field;
  453. switch (this.sortType) {
  454. case "":
  455. this.sortType = "DESC";
  456. break;
  457. case "DESC":
  458. this.sortType = "ASC";
  459. break;
  460. case "ASC":
  461. this.sortType = "";
  462. break;
  463. }
  464. }
  465. },
  466. template(col, data) {
  467. if (!col.template) return data;
  468. else return col.template(data);
  469. },
  470. hover(row, col) {
  471. if (this.showHover) {
  472. this.hoverRow = row;
  473. if (this.showColHover) this.hoverCol = col;
  474. }
  475. },
  476. leave() {
  477. this.hoverRow = -1;
  478. this.hoverCol = -1;
  479. },
  480. handleCurrentChange(val) {
  481. this.currentPage = val;
  482. this.$emit("onPagging", {
  483. pageIndex: this.currentPage,
  484. pageSize: this.pageSize,
  485. start: this.startRow,
  486. end: this.endRow,
  487. });
  488. },
  489. },
  490. // 生命周期钩子
  491. // 创建前
  492. beforeCreate() {},
  493. // 创建后
  494. created() {},
  495. // 渲染前
  496. beforeMount() {},
  497. // 渲染后
  498. mounted() {},
  499. beforeUpdate() {},
  500. updated() {},
  501. };
  502. </script>
  503. <style lang="less" scoped>
  504. .chart {
  505. width: 100%;
  506. height: 500px;
  507. }
  508. ::v-deep.com-table {
  509. height: calc(100% - 51px);
  510. thead {
  511. height: 24px;
  512. }
  513. tbody {
  514. height: calc(100% - 24px);
  515. overflow-y: auto;
  516. }
  517. }
  518. </style>