workOrderTrend.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <moduleEnclosure title="近30天工单趋势">
  3. <template v-slot:rightce>
  4. <el-tabs v-model="tabCurrent" type="card" @tab-click="changeTab">
  5. <el-tab-pane v-for="(item, index) in tabList" :key="index" :label="item" :name="item"></el-tab-pane>
  6. </el-tabs>
  7. </template>
  8. <div class="all-container">
  9. <div id="workorderEcharts1" style="width: 100%; height: 100%"></div>
  10. </div>
  11. </moduleEnclosure>
  12. </template>
  13. <script>
  14. import vScrollView from 'v-scroll-view'
  15. import moduleEnclosure from '@/components/moduleEnclosure.vue';
  16. import * as echarts from 'echarts';
  17. import { getWorkorderTrend } from '@/api/bigView.js';
  18. export default {
  19. components: {
  20. moduleEnclosure,
  21. vScrollView
  22. },
  23. data() {
  24. return {
  25. tabList: [],
  26. tabCurrent: '',
  27. tableData: [],
  28. };
  29. },
  30. mounted() {
  31. this.dingshishuaxin()
  32. },
  33. beforeUnmount() {
  34. this.mouseenter();
  35. },
  36. watch: {
  37. tabCurrent() {
  38. this.mouseenter();
  39. this.dingshishuaxin()
  40. }
  41. },
  42. methods: {
  43. mouseenter() {
  44. if (this.TimeId) {
  45. clearTimeout(this.TimeId)
  46. }
  47. },
  48. dingshishuaxin() {
  49. this.initData();
  50. this.TimeId = setTimeout(() => {
  51. this.setbiuaoji()
  52. }, 3000)
  53. },
  54. getDate() {
  55. const today = new Date();
  56. const dates = [];
  57. for (let i = 0; i < 30; i++) {
  58. const d = new Date();
  59. d.setDate(today.getDate() - i);
  60. dates.unshift(d.toISOString().split('T')[0].slice(5, 11));
  61. }
  62. return dates;
  63. },
  64. setbiuaoji() {
  65. var index = this.tabList.indexOf(this.tabCurrent)
  66. if (index >= (this.tabList.length - 1)) {
  67. this.tabCurrent = this.tabList[0]
  68. } else {
  69. this.tabCurrent = this.tabList[index + 1]
  70. }
  71. },
  72. changeTab(item) {
  73. this.tabCurrent = item.name;
  74. this.initEcharts();
  75. },
  76. initData() {
  77. getWorkorderTrend().then(res => {
  78. this.tabList = res.data.map(o => o.lx);
  79. if (this.tabCurrent == "") {
  80. this.setbiuaoji()
  81. }
  82. this.tableData = res.data;
  83. this.initEcharts();
  84. })
  85. },
  86. initEcharts() {
  87. var chartDom = document.getElementById('workorderEcharts1');
  88. var myChart = echarts.init(chartDom);
  89. var option;
  90. option = {
  91. title: {
  92. text: ''
  93. },
  94. tooltip: {
  95. confine: true,
  96. trigger: 'axis',
  97. transitionDuration: 0,
  98. backgroundColor: '#092a66',
  99. borderColor: '#0462b5',
  100. borderRadius: 8,
  101. borderWidth: 2,
  102. padding: [5, 10],
  103. axisPointer: {
  104. type: 'line',
  105. lineStyle: {
  106. type: 'dashed',
  107. color: '#8AB1DC',
  108. },
  109. },
  110. textStyle: {
  111. color: '#ffffff'
  112. }
  113. },
  114. legend: {
  115. icon: 'circle',
  116. itemWidth: 8,
  117. itemHeight: 8,
  118. itemGap: 10,
  119. top: '16',
  120. right: '10',
  121. data: ['已完工', '未完工'],
  122. textStyle: {
  123. color: '#ffffff',
  124. },
  125. },
  126. grid: {
  127. left: '3%',
  128. right: '4%',
  129. bottom: '3%',
  130. containLabel: true
  131. },
  132. toolbox: {
  133. // feature: {
  134. // saveAsImage: {}
  135. // }
  136. },
  137. xAxis: {
  138. type: 'category',
  139. boundaryGap: false,
  140. axisLine: {
  141. lineStyle: {
  142. color: '#ffffff', // x轴文字颜色
  143. }
  144. },
  145. splitLine: {
  146. show: true,
  147. lineStyle: {
  148. color: '#364D95', // x轴辅助线颜色
  149. }
  150. },
  151. data: this.getDate()
  152. },
  153. yAxis: {
  154. type: 'value',
  155. name: "(单/台)",
  156. nameTextStyle: {
  157. color: "#aaa",
  158. nameLocation: "start",
  159. // align: 'right'
  160. },
  161. axisLine: {
  162. lineStyle: {
  163. color: '#ffffff', // y轴文字颜色
  164. }
  165. },
  166. splitLine: {
  167. show: true,
  168. lineStyle: {
  169. color: '#364D95', // y轴辅助线颜色
  170. }
  171. }
  172. },
  173. series: [
  174. {
  175. name: '已完工',
  176. type: 'line',
  177. stack: 'Total',
  178. itemStyle: {
  179. normal: {
  180. color: '#44E28F',
  181. },
  182. },
  183. data: this.tableData.find(o => o.lx == this.tabCurrent).unitNum
  184. },
  185. {
  186. name: '未完工',
  187. type: 'line',
  188. stack: 'Total',
  189. itemStyle: {
  190. normal: {
  191. color: '#D73A79',
  192. },
  193. },
  194. data: this.tableData.find(o => o.lx == this.tabCurrent).unitNumWwg
  195. },
  196. ]
  197. };
  198. option && myChart.setOption(option);
  199. }
  200. },
  201. };
  202. </script>
  203. <style scoped lang="scss">
  204. ::v-deep .el-tabs {
  205. width: 100%;
  206. .el-tabs__header {
  207. margin-bottom: 0;
  208. border-bottom: none;
  209. }
  210. .el-tabs__nav {
  211. border: none;
  212. }
  213. .el-tabs__nav-prev {
  214. line-height: 30px;
  215. }
  216. .el-tabs__nav-next {
  217. line-height: 30px;
  218. }
  219. .el-tabs__item {
  220. width: 50px;
  221. height: 30px;
  222. line-height: 30px;
  223. color: #ffffff;
  224. border: 1px solid #254280 !important;
  225. font-size: 12px;
  226. font-weight: bold;
  227. margin-right: 10px;
  228. padding: 0 !important;
  229. text-align: center;
  230. &:last-child {
  231. margin-right: 0;
  232. }
  233. &.is-active {
  234. border: 1px solid #153781 !important;
  235. color: #1a8dc8;
  236. }
  237. }
  238. }
  239. .all-container {
  240. width: 100%;
  241. height: 100%;
  242. box-sizing: border-box;
  243. padding-top: 16px;
  244. }
  245. </style>