table-qc.vue 12 KB

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