index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <m-search :items="searchItems" v-model="searchValues" @search="onSearch"></m-search>
  4. <m-card class="mt-3" v-loading="loading">
  5. <AnalysisChart class="mb-3" v-for="item in items" :key="item.key" :option="item.value" :init="drillInit"></AnalysisChart>
  6. <m-empty v-if="items.length === 0"></m-empty>
  7. </m-card>
  8. </div>
  9. </template>
  10. <script>
  11. import { mapGetters } from 'vuex'
  12. import AnalysisChart from './AnalysisChart.vue'
  13. export default {
  14. name: 'AnalysisPage',
  15. props: {
  16. searchApi: {
  17. type: Function,
  18. default: () => ({})
  19. },
  20. drillInit: {
  21. type: Function,
  22. default: () => ({})
  23. }
  24. },
  25. components: {
  26. AnalysisChart
  27. },
  28. data () {
  29. return {
  30. chart: {},
  31. loading: false,
  32. searchValues: {
  33. parentOrganizationNo: null
  34. },
  35. items: []
  36. }
  37. },
  38. computed: {
  39. ...mapGetters(['organizationTree']),
  40. searchItems () {
  41. return [
  42. {
  43. label: '上级机构',
  44. type: 'cascader',
  45. prop: 'parentOrganizationNo',
  46. options: {
  47. filterable: true,
  48. clearable: true,
  49. placeholder: '请选择上级机构',
  50. options: this.organizationTree,
  51. showAllLevels: false,
  52. props: {
  53. emitPath: false,
  54. checkStrictly: true,
  55. value: 'organizationNo',
  56. label: 'organizationName',
  57. children: 'child'
  58. }
  59. }
  60. }
  61. ]
  62. }
  63. },
  64. mounted () {
  65. this.searchValues.parentOrganizationNo = this.organizationTree[0].organizationNo
  66. this.onInit()
  67. },
  68. methods: {
  69. async onInit () {
  70. this.loading = true
  71. try {
  72. const { data } = await this.searchApi({
  73. ...this.searchValues
  74. })
  75. this.items = Object.keys(data).map(key => {
  76. return {
  77. key,
  78. value: data[key]
  79. }
  80. })
  81. } catch (error) {
  82. this.$message.error(error)
  83. } finally {
  84. this.loading = false
  85. }
  86. },
  87. onSearch () {
  88. if (this.searchValues.parentOrganizationNo === null) {
  89. this.searchValues.parentOrganizationNo = this.organizationTree[0].organizationNo
  90. }
  91. this.onInit()
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. </style>