iam-audit-twopie.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <span>
  3. <a-empty
  4. v-show="!hasData | !selectYear | !selectUnidId"
  5. :class="$style.empty"
  6. :description="description"
  7. ></a-empty>
  8. <sd-echart
  9. v-show="hasData && selectYear && selectUnidId"
  10. :class="$style.onepieClass"
  11. :options="chartData"
  12. autoresize
  13. />
  14. </span>
  15. </template>
  16. <script>
  17. import 'echarts/lib/chart/line'
  18. import 'echarts/lib/component/polar'
  19. import 'echarts/lib/component/legend'
  20. import 'echarts/lib/component/tooltip'
  21. import 'echarts/lib/component/title'
  22. import iamAuditDscService from '../iam-audit-dsc-service'
  23. import components from './_import-components/iam-audit-twopie-import'
  24. export default {
  25. name: 'IamAuditTwopie',
  26. metaInfo: {
  27. title: 'IamAuditOnepie',
  28. },
  29. components,
  30. props: {
  31. /**
  32. * 统计的组织ID
  33. */
  34. unidId: {
  35. type: Array,
  36. default: () => {
  37. return []
  38. },
  39. },
  40. /**
  41. * 统计的年份
  42. */
  43. planYear: {
  44. type: String,
  45. default: null,
  46. },
  47. },
  48. data() {
  49. return {
  50. hasData: false, // 是否检查出数据
  51. chartData: {
  52. tooltip: {
  53. trigger: 'axis',
  54. formatter: function(params) {
  55. let res = params[0].name
  56. for (var i = 0, l = params.length; i < l; i++) {
  57. const seriesId = JSON.parse(params[i].seriesId)
  58. res +=
  59. '<br/>' +
  60. params[i].marker +
  61. seriesId.NAME +
  62. ' ' +
  63. seriesId.TYPE_CN +
  64. ' : ' +
  65. params[i].value
  66. }
  67. return res
  68. },
  69. },
  70. legend: {
  71. type: 'scroll',
  72. data: [],
  73. bottom: 0,
  74. },
  75. grid: {
  76. left: 20,
  77. right: 20,
  78. bottom: 30,
  79. top: 30,
  80. containLabel: true,
  81. },
  82. toolbox: {
  83. feature: {
  84. saveAsImage: {},
  85. },
  86. },
  87. xAxis: {
  88. type: 'category',
  89. boundaryGap: false,
  90. data: [],
  91. },
  92. yAxis: {
  93. type: 'value',
  94. },
  95. series: [],
  96. },
  97. }
  98. },
  99. computed: {
  100. // 因为props传值不会自动更新,使用计算值
  101. selectYear() {
  102. return this.planYear
  103. },
  104. // 因为props传值不会自动更新,使用计算值
  105. selectUnidId() {
  106. if (this.unidId.length > 0) {
  107. return this.unidId[0].name
  108. } else {
  109. return null
  110. }
  111. },
  112. description() {
  113. if (!this.selectYear | !this.selectUnidId) {
  114. return '未选择年份以及审计机构'
  115. } else {
  116. return '暂无数据'
  117. }
  118. },
  119. },
  120. created() {
  121. // 获取项目总览
  122. this.getData()
  123. },
  124. methods: {
  125. getData() {
  126. // 如果没有选时间或组织机构,则直接返回
  127. if (!this.selectYear | !this.selectUnidId) {
  128. return
  129. }
  130. // 获取项目总览
  131. const columns = ['0_NAME', '0_TYPE_CN']
  132. for (let i = parseFloat(this.selectYear) - 2; i < parseFloat(this.selectYear) + 3; i++) {
  133. columns.push(i + '')
  134. }
  135. const params = {
  136. columns: columns.join(','),
  137. maxResults: 9999,
  138. startPosition: 0,
  139. expressions: [],
  140. dateStart: parseFloat(this.selectYear) - 2 + '',
  141. dateEnd: parseFloat(this.selectYear) + 2 + '',
  142. unitNames: "'" + this.selectUnidId + "'",
  143. pageIndex: 0,
  144. pageSize: 9999,
  145. unitIds: "'" + this.unidId[0].id + "'",
  146. }
  147. iamAuditDscService.getProjectTrends(params).then((res) => {
  148. if (res.data.data.length === 0) {
  149. return
  150. }
  151. this.hasData = true
  152. const chartData = {
  153. legend: [],
  154. xAxis: [],
  155. series: [],
  156. }
  157. let startYear = parseFloat(this.selectYear) - 2
  158. const endYear = parseFloat(this.selectYear) + 2
  159. while (startYear <= endYear) {
  160. chartData.xAxis.push(startYear.toString())
  161. startYear++
  162. }
  163. res.data.data.forEach((item, index) => {
  164. chartData.legend.push(item['0_TYPE_CN'])
  165. const seriesData = chartData.xAxis.map((year) => {
  166. return item[year] ? item[year] : 0
  167. })
  168. chartData.series.push({
  169. name: item['0_TYPE_CN'],
  170. type: 'line',
  171. stack: index,
  172. data: seriesData,
  173. id: JSON.stringify({
  174. NAME: item['0_NAME'],
  175. TYPE_CN: item['0_TYPE_CN'],
  176. TYPE: item['0_TYPE'],
  177. }),
  178. })
  179. })
  180. this.chartData.legend.data = chartData.legend
  181. this.chartData.xAxis.data = chartData.xAxis
  182. this.chartData.series = chartData.series
  183. })
  184. },
  185. },
  186. }
  187. </script>
  188. <style module lang="scss">
  189. @use '@/common/design' as *;
  190. .onepie-class {
  191. width: 100%;
  192. height: 300px;
  193. }
  194. .empty {
  195. padding-top: 80px;
  196. margin: 0;
  197. }
  198. </style>