90b6605bd476e01cd5176b639fdcafbf211fe2d6.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <a-card size="small" :title="group.groupTxt">
  3. <a-dropdown slot="extra">
  4. <a-menu slot="overlay" >
  5. <template v-for="(chart,index) in group.charts">
  6. <a-menu-item @click="handleMenuClick(chart.head.code)" :key="index">{{chart.head.name}}</a-menu-item>
  7. </template>
  8. </a-menu>
  9. <a-button type="primary" size="small" class="ant-btn-background-ghost">详情<a-icon type="down"/></a-button>
  10. </a-dropdown>
  11. <bar-and-line :barFields="barFields" :lineFields="lineFields" :dataSource="dataSouce" :aliases="aliases"></bar-and-line>
  12. </a-card>
  13. </template>
  14. <script>
  15. import BarAndLine from '@/components/chart/BarAndLine'
  16. export default {
  17. name: 'GroupTemplateCombination',
  18. mixins: [],
  19. components: {
  20. BarAndLine
  21. },
  22. props: {
  23. group: {
  24. type: Object,
  25. default: {}
  26. }
  27. },
  28. data() {
  29. return {
  30. barType: '',
  31. barFields: [],
  32. lineFields: [],
  33. dataSouce: [],
  34. aliases: []// [{field:'name',alias:'姓名'}, {field:'sex',alias:'性别'}]
  35. }
  36. },
  37. mounted() {
  38. this.getDataSource()
  39. },
  40. methods: {
  41. getDataSource() {
  42. this.dataSouce = []
  43. this.group.charts.forEach((chart, i) => {
  44. const groupFields = chart.head.groupField.split(',')
  45. if (chart.head.graphType === 'line') {
  46. groupFields.forEach(groupField => {
  47. this.lineFields.push(groupField + 'line' + i)
  48. this.setAliases(chart.items, groupField, 'line' + i)
  49. })
  50. this.setChartData(chart, 'line' + i, this.dataSouce)
  51. } else if (chart.head.graphType === 'bar') {
  52. groupFields.forEach(groupField => {
  53. this.barFields.push(groupField + 'bar' + i)
  54. this.setAliases(chart.items, groupField, 'bar' + i)
  55. })
  56. this.setChartData(chart, 'bar' + i, this.dataSouce)
  57. }
  58. })
  59. },
  60. // 把多个图表的数据组合到一个数组里 [{step1bar0: 1234,step1line1: 100,stepbar0: 100,stepline1: 1234,type: "星期一"}]
  61. // key值上拼接line和索引 是为了key值防止重复
  62. setChartData(chart, type, dataSouce) {
  63. var datas
  64. if (chart.head.dataType === 'json' && chart.head.cgrSql) {
  65. datas = JSON.parse(data.head.cgrSql.replace(/↵/g, ''))
  66. } else if ((chart.head.dataType === 'sql' || chart.head.dataType === 'bean') && chart.head.aggregate === true) {
  67. datas = chart.data.aggregate
  68. } else if ((chart.head.dataType === 'sql' || chart.head.dataType === 'bean') && chart.head.aggregate === false) {
  69. datas = chart.data.data
  70. }
  71. const xaxisField = chart.head.xaxisField
  72. if (dataSouce.length <= 0) {
  73. datas.forEach((item, i) => {
  74. var data = {
  75. type: item[xaxisField]
  76. }
  77. const groupFields = chart.head.groupField.split(',')
  78. groupFields.forEach(groupField => {
  79. data[groupField + type] = item[groupField]
  80. })
  81. dataSouce.push(data)
  82. })
  83. } else {
  84. datas.forEach((item, i) => {
  85. if (i > dataSouce.length) {
  86. const obj = {
  87. type: item[xaxisField]
  88. }
  89. dataSouce.push(obj)
  90. } else {
  91. const groupFields = chart.head.groupField.split(',')
  92. groupFields.forEach(groupField => {
  93. dataSouce[i][groupField + type] = item[groupField]
  94. })
  95. }
  96. })
  97. }
  98. },
  99. setAliases(items, groupField, key) {
  100. items.forEach(data => {
  101. if (data.fieldName === groupField) {
  102. this.aliases.push({
  103. field: groupField + key,
  104. alias: data.fieldTxt
  105. })
  106. }
  107. })
  108. },
  109. handleLineClick(msg) {
  110. if (this.head.extendJs) {
  111. this.chartClick('line', msg)
  112. }
  113. },
  114. chartClick(type, msg) {
  115. var onClick = {}
  116. eval(this.head.extendJs)
  117. if (onClick && onClick[type]) {
  118. onClick[type].call(this, msg)
  119. }
  120. },
  121. handleMenuClick(code) {
  122. this.$router.push({ path: '/online/cggraphreport/chart/' + code })
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. </style>