changeMinxin.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { getInitialValue } from '@/utils/common/ant'
  2. import { SKU_PARAMS, CAPABILIT_PARAMS, SPECS_PARAMS, DECORATORS } from '../constants'
  3. export default {
  4. data () {
  5. return {
  6. provider: '',
  7. }
  8. },
  9. computed: {
  10. form () {
  11. const fc = this.$form.createForm(this, { onValuesChange: this.handleValuesChange })
  12. const initFd = getInitialValue(DECORATORS)
  13. const { getFieldDecorator, getFieldValue, getFieldsValue, setFieldsValue } = fc
  14. return {
  15. fc,
  16. fd: initFd,
  17. getFieldDecorator,
  18. getFieldValue,
  19. getFieldsValue,
  20. setFieldsValue,
  21. }
  22. },
  23. },
  24. provide () {
  25. return {
  26. form: this.form,
  27. scopeParams: this.scopeParams,
  28. formItemLayout: this.formItemLayout,
  29. tailFormItemLayout: this.tailFormItemLayout,
  30. redisItem: this.redisItem,
  31. }
  32. },
  33. async created () {
  34. // 当前选中的sku内部的 cloudregion_id
  35. this.form.fc.getFieldDecorator('cloudregion_id', { preserve: true })
  36. // 当前选中的sku内部的 zone_id
  37. this.form.fc.getFieldDecorator('zone_id', { preserve: true })
  38. this.keysChange = {
  39. area: CAPABILIT_PARAMS,
  40. capability: SPECS_PARAMS,
  41. }
  42. this.keysChange.sku_params = SKU_PARAMS
  43. await this.$nextTick()
  44. this.skuRef = this.$refs.REF_SKU
  45. this.networkRef = this.$refs.REF_NETWORK
  46. },
  47. methods: {
  48. domain_change () {
  49. if (this.$store.getters.isAdminMode) {
  50. const { domain } = this.form.fd
  51. this.scopeParams.project_domain = domain || this.form.getFieldValue('domain')
  52. delete this.scopeParams.scope
  53. } else {
  54. delete this.scopeParams.project_domain
  55. }
  56. },
  57. project_change () {
  58. const { project } = this.form.fd
  59. this.project_id = project
  60. },
  61. // 区域字段发生变化,获取Capability信息
  62. area_change () {
  63. this.skuRef.fetchCapability()
  64. },
  65. // capability中有字段发生变化,获取specs信息
  66. async capability_change () {
  67. await this.skuRef.fetchSpecs()
  68. },
  69. // 获取sku
  70. sku_params_change () {
  71. this.skuRef.fetchSkus()
  72. },
  73. sku_change () {
  74. const { fd } = this.form
  75. const { sku } = fd
  76. let callback
  77. if (sku && (fd.cloudregion_id !== sku.cloudregion_id)) {
  78. this.form.fc.setFieldsValue({
  79. cloudregion_id: sku.cloudregion_id,
  80. })
  81. callback = this.cloudregion_id_change
  82. }
  83. if (sku && (fd.zone_id !== sku.zone_id)) {
  84. this.form.fc.setFieldsValue({
  85. zone_id: sku.zone_id,
  86. })
  87. callback = this.zone_id_change
  88. }
  89. if (callback) {
  90. callback()
  91. }
  92. },
  93. cloudregion_id_change () {
  94. if (this.networkRef && this.networkRef.fetchVpc) {
  95. this.networkRef.fetchVpc()
  96. }
  97. },
  98. zone_id_change () {
  99. if (this.networkRef && this.networkRef.fetchVpc) {
  100. this.networkRef.fetchVpc()
  101. }
  102. },
  103. zone_change () {
  104. if (this.networkRef && this.networkRef.fetchVpc) {
  105. this.networkRef.fetchVpc()
  106. }
  107. },
  108. async handleValuesChange (fc, changedFields) {
  109. const fields = Object.keys(changedFields)
  110. if (changedFields && fields.length > 0) {
  111. fields.forEach(field => {
  112. this.$set(this.form.fd, field, changedFields[field])
  113. if (field === 'vpc') {
  114. this.vpc = changedFields[field]
  115. }
  116. })
  117. }
  118. if (changedFields.hasOwnProperty('provider')) {
  119. this.provider = changedFields.provider
  120. }
  121. await this.$nextTick()
  122. const changedFieldsKey = Object.keys(changedFields)
  123. changedFieldsKey.forEach(field => {
  124. // if (changedFields[field] === undefined) return false
  125. const handleChange = this[`${field}_change`]
  126. if (this[`${field}_change`]) {
  127. return handleChange()
  128. }
  129. for (const k in this.keysChange) {
  130. if (this.keysChange[k].indexOf(field) > -1 && this[`${k}_change`]) {
  131. this[`${k}_change`]()
  132. }
  133. }
  134. })
  135. },
  136. },
  137. }