AdjustLabel.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_540')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="params.name || $t('dictionary.host')" :count="params.data.length" :action="$t('compute.text_540')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 2)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('compute.text_541')" v-bind="formItemLayout">
  10. <a-select v-decorator="decorators.schedTags" :placeholder="$t('compute.text_123')" mode="multiple">
  11. <a-select-option v-for="item in schedTags" :key="item.id" :value="item.id">
  12. {{item.name}}
  13. </a-select-option>
  14. </a-select>
  15. </a-form-item>
  16. </a-form>
  17. </div>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import * as R from 'ramda'
  26. import DialogMixin from '@/mixins/dialog'
  27. import WindowsMixin from '@/mixins/windows'
  28. export default {
  29. name: 'HostsAdjustLabelDialog',
  30. mixins: [DialogMixin, WindowsMixin],
  31. data () {
  32. return {
  33. loading: false,
  34. scope: this.$store.getters.scope,
  35. form: {
  36. fc: this.$form.createForm(this),
  37. },
  38. decorators: {
  39. schedTags: [
  40. 'schedTags',
  41. ],
  42. },
  43. formItemLayout: {
  44. wrapperCol: {
  45. span: 20,
  46. },
  47. labelCol: {
  48. span: 4,
  49. },
  50. },
  51. schedTags: [],
  52. useSchedTags: [],
  53. }
  54. },
  55. created () {
  56. this.loadSchedTags()
  57. },
  58. methods: {
  59. loadSchedTags (query) {
  60. const manager = new this.$Manager('schedtags')
  61. const params = { 'filter.0': 'resource_type.equals(hosts)', scope: this.scope }
  62. if (query && query.length > 0) {
  63. params['filter.1'] = 'name.contains(' + query + ')'
  64. }
  65. manager.list({ params })
  66. .then((res) => {
  67. this.schedTags = R.uniqBy(obj => obj.id, R.concat(res.data.data.map(item => ({
  68. id: item.id,
  69. name: item.name,
  70. })), this.useSchedTags))
  71. const allUseSchedTags = R.uniqBy(obj => obj.id, R.flatten(this.params.data.map(item => item.schedtags || [])))
  72. if (allUseSchedTags) {
  73. this.useSchedTags = allUseSchedTags.map(item => ({ id: item.id, name: item.name }))
  74. this.form.fc.setFieldsValue({ schedTags: allUseSchedTags.map(item => item.id) })
  75. }
  76. })
  77. },
  78. doBindSchedTags (data) {
  79. return this.params.onManager('batchPerformAction', {
  80. id: this.params.data.map(item => item.id),
  81. managerArgs: {
  82. action: 'set-schedtag',
  83. data,
  84. },
  85. })
  86. },
  87. async handleConfirm () {
  88. this.loading = true
  89. try {
  90. const values = await this.form.fc.validateFields()
  91. values.schedTags.forEach((item, idx) => {
  92. values[`schedtag.${idx}`] = item
  93. })
  94. Reflect.deleteProperty(values, 'schedTags')
  95. this.loading = true
  96. await this.doBindSchedTags(values)
  97. this.loading = false
  98. this.cancelDialog()
  99. } catch (error) {
  100. this.loading = false
  101. }
  102. },
  103. },
  104. }
  105. </script>