table-qc.vue 12 KB

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