ItemArea.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <area-selects
  3. ref="areaSelects"
  4. :decorators="decorators"
  5. v-bind="formItemLayout"
  6. :names="names"
  7. :isRequired="isRequired"
  8. :defaultActiveFirstOption="defaultActiveFirstOption"
  9. :zoneParams="zoneParams"
  10. :providerParams="providerParams"
  11. :cloudregionParams="cloudregionParams"
  12. :filterBrandResource="filterBrandResource"
  13. @providerFetchSuccess="providerFetchSuccess"
  14. @cloudregionFetchSuccess="cloudregionFetchSuccess" />
  15. </template>
  16. <script>
  17. import AreaSelects from '@/sections/AreaSelects'
  18. const PROVIDERS = {
  19. postpaid: ['Aliyun', 'Huawei', 'Google', 'Qcloud', 'HCSO', 'HCS', 'Aws'],
  20. prepaid: ['Aliyun', 'Huawei', 'Qcloud'],
  21. }
  22. export default {
  23. name: 'ItemArea',
  24. components: {
  25. // 区域
  26. AreaSelects,
  27. },
  28. props: {
  29. names: {
  30. type: Array,
  31. },
  32. defaultActiveFirstOption: {
  33. type: Array,
  34. },
  35. isRequired: {
  36. type: Boolean,
  37. },
  38. billingType: {
  39. type: String,
  40. },
  41. filterBrandResource: String,
  42. },
  43. data () {
  44. return {
  45. providerList: [],
  46. }
  47. },
  48. computed: {
  49. isRds () {
  50. return this.$route.path.indexOf('rds') > -1
  51. },
  52. service () {
  53. return this.isRds ? 'dbinstances' : 'elasticcaches'
  54. },
  55. decorators () {
  56. return {
  57. provider: ['provider', {
  58. validateFirst: true,
  59. rules: [
  60. {
  61. required: this.isRequired, message: this.$t('db.text_30'),
  62. },
  63. {
  64. validator: (rule, value, _callback) => {
  65. if (!this.providerList || this.providerList.length === 0) {
  66. return _callback(new Error(this.$t('db.text_31')))
  67. }
  68. _callback()
  69. },
  70. }],
  71. }],
  72. }
  73. },
  74. providerParams () {
  75. const params = {
  76. service: this.service,
  77. // cloud_env: 'public',
  78. ...this.scopeParams,
  79. }
  80. if (this.service === 'elasticcaches') {
  81. params.brands = ['Huawei', 'Aliyun', 'Qcloud', 'HCS', 'Aws']
  82. }
  83. return params
  84. },
  85. zoneParams () {
  86. return {
  87. service: this.service,
  88. ...this.scopeParams,
  89. }
  90. },
  91. cloudregionParams () {
  92. return {
  93. service: this.service,
  94. ...this.scopeParams,
  95. }
  96. },
  97. },
  98. inject: ['form', 'formItemLayout', 'scopeParams'],
  99. watch: {
  100. billingType (type) {
  101. this.doFetchs(type)
  102. },
  103. },
  104. created () {
  105. if (this.isRds) {
  106. this.providers = PROVIDERS.postpaid
  107. }
  108. },
  109. methods: {
  110. doFetchs (billingType) {
  111. this.providers = PROVIDERS[billingType]
  112. this.$refs.areaSelects.fetchs(['provider', 'cloudregion'])
  113. },
  114. providerFetchSuccess (list = []) {
  115. const _list = list.filter(({ name }) => {
  116. if (this.providers) {
  117. return this.providers.indexOf(name) > -1
  118. }
  119. return true
  120. })
  121. this.providerList = _list
  122. this.form.fc.validateFields(['provider'])
  123. if (this.providerList.length === 0) {
  124. this.form.setFieldsValue({
  125. sku: undefined,
  126. })
  127. }
  128. return _list
  129. },
  130. cloudregionFetchSuccess (list = []) {
  131. if (this.providerList.length === 0) {
  132. return []
  133. }
  134. return list.filter(({ provider }) => {
  135. if (this.providers) {
  136. return this.providers.indexOf(provider) > -1
  137. }
  138. return true
  139. })
  140. },
  141. },
  142. }
  143. </script>