changeMinxin.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { getInitialValue } from '@/utils/common/ant'
  2. import { SKU_PARAMS, CAPABILIT_PARAMS, DECORATORS } from '../constants'
  3. export default {
  4. computed: {
  5. form () {
  6. const fc = this.$form.createForm(this, { onValuesChange: this.handleValuesChange })
  7. const initFd = getInitialValue(DECORATORS)
  8. const { getFieldDecorator, getFieldValue, getFieldsValue, setFieldsValue } = fc
  9. return {
  10. fc,
  11. fd: initFd,
  12. getFieldDecorator,
  13. getFieldValue,
  14. getFieldsValue,
  15. setFieldsValue,
  16. }
  17. },
  18. },
  19. provide () {
  20. return {
  21. form: this.form,
  22. scopeParams: this.scopeParams,
  23. formItemLayout: this.formItemLayout,
  24. tailFormItemLayout: this.tailFormItemLayout,
  25. }
  26. },
  27. async created () {
  28. // 当前选中的sku内部的 cloudregion_id
  29. this.form.fc.getFieldDecorator('cloudregion_id', { preserve: true })
  30. this.keysChange = {
  31. area: CAPABILIT_PARAMS,
  32. sku_params: SKU_PARAMS,
  33. }
  34. await this.$nextTick()
  35. this.skuRef = this.$refs.REF_SKU
  36. this.networkRef = this.$refs.REF_NETWORK
  37. },
  38. methods: {
  39. domain_change () {
  40. if (this.$store.getters.isAdminMode) {
  41. const { domain } = this.form.fd
  42. this.scopeParams.project_domain = domain || this.form.getFieldValue('domain')
  43. delete this.scopeParams.scope
  44. } else {
  45. delete this.scopeParams.project_domain
  46. }
  47. },
  48. billing_type_change () {
  49. this.skuRef.fetchSkus()
  50. },
  51. area_change () {
  52. this.skuRef.fetchSkus()
  53. },
  54. // 获取sku
  55. sku_params_change () {
  56. this.skuRef.fetchSkus()
  57. },
  58. sku_change () {
  59. const { fd } = this.form
  60. const { sku } = fd
  61. if (sku && (fd.cloudregion_id !== sku.cloudregion_id)) {
  62. this.form.fc.setFieldsValue({
  63. cloudregion_id: sku.cloudregion_id,
  64. })
  65. }
  66. },
  67. cloudregion_id_change () {
  68. if (this.networkRef && this.networkRef.fetchVpc) {
  69. this.fetchVpc()
  70. }
  71. },
  72. async handleValuesChange (fc, changedFields) {
  73. this.form.fd = {
  74. ...this.form.fd,
  75. ...changedFields,
  76. }
  77. await this.$nextTick()
  78. const changedFieldsKey = Object.keys(changedFields)
  79. changedFieldsKey.forEach(field => {
  80. // if (changedFields[field] === undefined) return false
  81. const handleChange = this[`${field}_change`]
  82. if (this[`${field}_change`]) {
  83. return handleChange()
  84. }
  85. for (const k in this.keysChange) {
  86. if (this.keysChange[k].indexOf(field) > -1 && this[`${k}_change`]) {
  87. this[`${k}_change`]()
  88. }
  89. }
  90. })
  91. },
  92. },
  93. }