BillFileIndex.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div>
  3. <page-header :title="$t('cloudenv.text_168')" />
  4. <div style="padding: 7px" />
  5. <a-spin v-if="isUpdate" :spinning="!isRender">
  6. <content-info :params="params" v-if="isRender" />
  7. </a-spin>
  8. <page-body needMarginBottom>
  9. <div>
  10. <div v-if="isGoogle" style="margin-bottom: 8px;">
  11. <span style="width: 190px;margin-right: 45px">{{ $t('cloudenv.bill.data_source') }}</span>
  12. <a-radio-group v-model="billform">
  13. <a-radio-button value="bigquery">
  14. Bigquery
  15. </a-radio-button>
  16. <!-- <a-radio-button value="bucket">
  17. Bucket
  18. </a-radio-button> -->
  19. </a-radio-group>
  20. </div>
  21. <component :account="account" :is="form" ref="BILL_FORM" />
  22. </div>
  23. </page-body>
  24. <page-footer>
  25. <div slot="right">
  26. <a-button class="mr-3" type="primary" @click="handleConfirm" :loading="loading">{{$t('cloudenv.text_169')}}</a-button>
  27. <test-button class="mr-3" :post="testPost" :isSuccessAlert="false" />
  28. <a-button @click="cancel">{{$t('cloudenv.text_170')}}</a-button>
  29. </div>
  30. </page-footer>
  31. </div>
  32. </template>
  33. <script>
  34. import TestButton from '@/sections/TestButton'
  35. import { getRequestT } from '@/utils/utils'
  36. import BillForm from './form/BillForm'
  37. import BigQueryBillForm from './form/BigQueryBillForm'
  38. import ContentInfo from './form/components/ContentInfo'
  39. export default {
  40. name: 'CloudaccountBillFileIndex',
  41. components: {
  42. BillForm,
  43. BigQueryBillForm,
  44. TestButton,
  45. ContentInfo,
  46. },
  47. props: {
  48. account: {
  49. type: Object,
  50. },
  51. },
  52. data () {
  53. return {
  54. params: {
  55. data: [],
  56. },
  57. billform: this.isGoogle ? 'bigquery' : 'bucket',
  58. loading: false,
  59. createAccountInfo: {},
  60. }
  61. },
  62. computed: {
  63. isUpdate () {
  64. return !!this.$route.query.id
  65. },
  66. isRender () {
  67. return this.params.data.length > 0
  68. },
  69. isGoogle () {
  70. return (this.isRender && this.params.data[0].provider === 'Google') || this.createAccountInfo?.provider === 'Google'
  71. },
  72. form () {
  73. if (this.billform === 'bigquery') {
  74. return 'BigQueryBillForm'
  75. } else {
  76. return 'BillForm'
  77. }
  78. },
  79. },
  80. created () {
  81. this.fetchData()
  82. },
  83. methods: {
  84. cancel () {
  85. this.$router.push(this.$route.query.backPath || '/cloudaccount')
  86. },
  87. testPost () {
  88. return this.$refs.BILL_FORM.testPost()
  89. },
  90. doSubmit () {
  91. return this.$refs.BILL_FORM.doSubmit()
  92. },
  93. async handleConfirm () {
  94. this.loading = true
  95. try {
  96. await this.$refs.BILL_FORM.doSubmit()
  97. this.$store.commit('keepAlive/ADD_DELAY_EVENT', { name: 'ResourceListSingleRefresh', params: this.params.data.map(item => item.id) })
  98. this.cancel()
  99. } catch (err) {
  100. throw err
  101. } finally {
  102. this.loading = false
  103. }
  104. },
  105. fetchData () {
  106. const manager = new this.$Manager('cloudaccounts')
  107. let ids = []
  108. if (this.$route.query.id) {
  109. if (Array.isArray(this.$route.query.id)) {
  110. ids = this.$route.query.id
  111. } else {
  112. ids = [this.$route.query.id]
  113. }
  114. } else if (this.account && this.account.provider === 'Google') {
  115. this.params.data.length === 0 && (this.createAccountInfo = this.account)
  116. this.billform = 'bigquery'
  117. return
  118. }
  119. if (!ids.length) return
  120. manager.batchGet({ id: ids, params: { $t: getRequestT() } })
  121. .then((res) => {
  122. this.params.data = res.data.data
  123. if (this.params.data && this.params.data.length > 0) {
  124. const a = this.params.data[0]
  125. if (a.provider === 'Google') {
  126. this.billform = 'bigquery'
  127. } else {
  128. this.billform = 'bucket'
  129. }
  130. }
  131. })
  132. },
  133. },
  134. }
  135. </script>