kpi-analysis-form-echarts.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div :class="$style.title">
  3. <span class="header_sd-header_common"
  4. ><span :class="['toptitle', $style.toptitle]">{{ title }}</span></span
  5. >
  6. <div>
  7. <div v-show="!hasData">
  8. <a-empty />
  9. </div>
  10. <div v-show="hasData">
  11. <sd-echart :key="tableKey" :class="$style.echarts" :options="echartsData" autoresize />
  12. </div>
  13. <div v-show="hasData">
  14. <sd-data-table
  15. :key="tableKey"
  16. ref="dataTable"
  17. :class="$style.childTable"
  18. row-key="indi_id"
  19. :columns="columns"
  20. form-id="kpiIndiDef"
  21. data-url="api/xcoa-mobile/v1/kpi-assay/getKpiAssayList"
  22. :modal-props="{ class: 'noBottom' }"
  23. :process-req="processReq"
  24. :process-res="processRes"
  25. @dataLoaded="dataLoaded"
  26. >
  27. </sd-data-table>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import 'echarts/lib/chart/treemap'
  34. import 'echarts/lib/chart/line'
  35. import 'echarts/lib/chart/pictorialBar'
  36. import 'echarts/lib/component/title'
  37. import 'echarts/lib/chart/bar'
  38. import 'echarts/lib/component/legend'
  39. import 'echarts/lib/component/legendScroll'
  40. import 'echarts/lib/component/tooltip'
  41. import kpiAnalysisFormService from './kpi-analysis-form-service'
  42. import components from './_import-components/kpi-analysis-form-echarts-import'
  43. export default {
  44. name: 'KpiAnalysisFormEcharts',
  45. metaInfo: {
  46. title: 'KpiAnalysisFormEcharts',
  47. },
  48. components,
  49. props: {
  50. title: {
  51. type: String,
  52. default: '',
  53. },
  54. indiId: {
  55. type: Number,
  56. default: -1,
  57. require: true,
  58. },
  59. params: {
  60. type: Object,
  61. default: () => {
  62. return {}
  63. },
  64. require: true,
  65. },
  66. },
  67. data() {
  68. return {
  69. hasData: false,
  70. columns: [],
  71. tableKey: 0,
  72. echartsData: {
  73. tooltip: {
  74. trigger: 'axis',
  75. },
  76. legend: {
  77. selectedMode: false,
  78. bottom: 15,
  79. data: [],
  80. },
  81. grid: {
  82. left: '3%',
  83. right: '4%',
  84. bottom: '35',
  85. containLabel: true,
  86. },
  87. xAxis: {
  88. type: 'category',
  89. boundaryGap: false,
  90. data: [],
  91. show: false,
  92. },
  93. yAxis: {
  94. type: 'value',
  95. },
  96. series: [],
  97. },
  98. }
  99. },
  100. created() {
  101. kpiAnalysisFormService.getKpiAssayHeader(this.params).then((resData) => {
  102. this.columns = [
  103. {
  104. title: '序号',
  105. customRender: (text, record, index) => `${index + 1}`,
  106. width: '80px',
  107. },
  108. {
  109. title: '监测单位',
  110. dataIndex: '监测单位',
  111. },
  112. ]
  113. resData.data.forEach((item) => {
  114. if (item !== '监测单位') {
  115. this.echartsData.xAxis.data.push(item)
  116. this.columns.push({
  117. title: item,
  118. dataIndex: item,
  119. })
  120. }
  121. })
  122. this.tableKey++
  123. })
  124. },
  125. methods: {
  126. dataLoaded() {
  127. this.$refs.dataTable.$refs.table.reset()
  128. },
  129. processReq(req) {
  130. req.data = {
  131. ...req.data,
  132. ...this.params,
  133. indiId: this.indiId,
  134. pageIndex: req.data.startPosition,
  135. pageSize: req.data.maxResults,
  136. }
  137. return req
  138. },
  139. processRes(res) {
  140. this.echartsData.series = []
  141. this.echartsData.legend.data = []
  142. this.hasData = true
  143. if (res.data.length === 0) this.hasData = false
  144. res.data.forEach((item) => {
  145. const data = []
  146. this.echartsData.xAxis.data.forEach((xAxis) => {
  147. data.push(item[xAxis])
  148. })
  149. this.echartsData.series.push({
  150. name: item['监测单位'],
  151. type: 'line',
  152. stack: 'Total',
  153. data: data,
  154. })
  155. this.echartsData.legend.data.push({
  156. name: item['监测单位'],
  157. icon: 'roundRect',
  158. })
  159. })
  160. if ((this.columns.length !== 0) | (res.data.length === 0)) return res
  161. this.tableKey++
  162. return res
  163. // if ((this.columns.length !== 0) | (res.data.length === 0)) return res
  164. // this.columns.push({
  165. // title: '序号',
  166. // customRender: (text, record, index) => `${index + 1}`,
  167. // width: '80px',
  168. // })
  169. // const row = res.data[0]
  170. // for (const key in row) {
  171. // this.columns.push({
  172. // title: key,
  173. // dataIndex: key,
  174. // })
  175. // }
  176. // this.tableKey++
  177. // return res
  178. },
  179. },
  180. }
  181. </script>
  182. <style module lang="scss">
  183. @use '@/common/design' as *;
  184. .title {
  185. text-align: center;
  186. }
  187. .toptitle {
  188. color: #404040;
  189. font-weight: bold;
  190. font-size: 22px;
  191. }
  192. .echarts {
  193. width: 90%;
  194. margin: auto;
  195. }
  196. .child-table {
  197. :global(.ant-table-body) {
  198. overflow: auto;
  199. }
  200. table:first-child {
  201. colgroup {
  202. :not(col:first-child) {
  203. width: 150px;
  204. }
  205. }
  206. }
  207. }
  208. </style>