SetProjectmapping.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.set_project_mapping')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('cloudenv.text_318')" :count="params.data.length" :action="$t('cloudenv.set_project_mapping')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form-model
  8. ref="form"
  9. :model="fd"
  10. :rules="rules"
  11. v-bind="formItemLayout">
  12. <a-form-model-item :label="$t('cloudenv.text_580')" prop="project_mapping_id">
  13. <base-select
  14. v-model="fd.project_mapping_id"
  15. resource="project_mappings"
  16. :select-props="{ placeholder: $t('common.tips.select', [$t('cloudenv.text_580')]), allowClear: true }"
  17. :params="projectMappingParams" />
  18. </a-form-model-item>
  19. <a-form-model-item :label="$t('cloudenv.effective_scope')" prop="effective_scope" :extra="effectiveScopeExtra">
  20. <a-radio-group v-model="fd.effective_scope">
  21. <a-radio-button value="resource">{{$t('cloudenv.resource_tag')}}</a-radio-button>
  22. <a-radio-button value="project">{{$t('cloudenv.project_tag')}}</a-radio-button>
  23. </a-radio-group>
  24. </a-form-model-item>
  25. </a-form-model>
  26. </div>
  27. <div slot="footer">
  28. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  29. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  30. </div>
  31. </base-dialog>
  32. </template>
  33. <script>
  34. import DialogMixin from '@/mixins/dialog'
  35. import WindowsMixin from '@/mixins/windows'
  36. export default {
  37. name: 'CloudproviderSetPojectmappingDialog',
  38. mixins: [DialogMixin, WindowsMixin],
  39. data () {
  40. let initProjectMappingId = ''
  41. let initEffectiveScope = ''
  42. this.params.data.map(item => {
  43. if (!initProjectMappingId && item.project_mapping_id) {
  44. initProjectMappingId = item.project_mapping_id
  45. }
  46. if (item.enable_resource_sync && !initEffectiveScope) {
  47. initEffectiveScope = 'resource'
  48. } else if (item.enable_project_sync && !initEffectiveScope) {
  49. initEffectiveScope = 'project'
  50. }
  51. })
  52. return {
  53. loading: false,
  54. discountLoaded: false,
  55. fd: {
  56. project_mapping_id: initProjectMappingId,
  57. effective_scope: initEffectiveScope || 'resource',
  58. },
  59. rules: {
  60. project_mapping_id: [
  61. { required: false, message: this.$t('common.tips.select', [this.$t('cloudenv.text_580')]) },
  62. ],
  63. },
  64. formItemLayout: {
  65. wrapperCol: {
  66. span: 21,
  67. },
  68. labelCol: {
  69. span: 3,
  70. },
  71. },
  72. }
  73. },
  74. computed: {
  75. effectiveScopeExtra () {
  76. if (this.fd.effective_scope === 'resource') {
  77. return this.$t('cloudenv.resource_tag_tip')
  78. } else if (this.fd.effective_scope === 'project') {
  79. return this.$t('cloudenv.project_tag_tip')
  80. }
  81. return ''
  82. },
  83. projectMappingParams () {
  84. const ret = {
  85. scope: this.$store.getters.scope,
  86. }
  87. if (this.params.data.length === 1) {
  88. return {
  89. project_domain: this.params.data[0].domain_id,
  90. }
  91. }
  92. return ret
  93. },
  94. },
  95. created () {
  96. },
  97. methods: {
  98. genParams () {
  99. const ret = { project_mapping_id: this.fd.project_mapping_id }
  100. if (this.fd.effective_scope === 'resource') {
  101. ret.enable_resource_sync = true
  102. ret.enable_project_sync = false
  103. }
  104. if (this.fd.effective_scope === 'project') {
  105. ret.enable_project_sync = true
  106. ret.enable_resource_sync = false
  107. }
  108. return ret
  109. },
  110. async handleConfirm () {
  111. this.loading = true
  112. try {
  113. await this.$refs.form.validate()
  114. const data = this.genParams()
  115. const bindedIds = []
  116. this.params.data.map(item => {
  117. if (item.project_mapping_id) {
  118. bindedIds.push(item.id)
  119. }
  120. })
  121. if (bindedIds.length) {
  122. await this.params.onManager('batchPerformAction', {
  123. id: bindedIds,
  124. managerArgs: {
  125. action: 'project-mapping',
  126. data: {},
  127. },
  128. })
  129. }
  130. await this.params.onManager('batchPerformAction', {
  131. id: this.params.data.map(item => {
  132. return item.id
  133. }),
  134. managerArgs: {
  135. action: 'project-mapping',
  136. data,
  137. },
  138. })
  139. this.cancelDialog()
  140. } finally {
  141. this.loading = false
  142. }
  143. },
  144. },
  145. }
  146. </script>