| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <area-selects
- ref="areaSelects"
- :decorators="decorators"
- v-bind="formItemLayout"
- :names="names"
- :isRequired="isRequired"
- :defaultActiveFirstOption="defaultActiveFirstOption"
- :zoneParams="zoneParams"
- :providerParams="providerParams"
- :cloudregionParams="cloudregionParams"
- :filterBrandResource="filterBrandResource"
- @providerFetchSuccess="providerFetchSuccess"
- @cloudregionFetchSuccess="cloudregionFetchSuccess" />
- </template>
- <script>
- import AreaSelects from '@/sections/AreaSelects'
- const PROVIDERS = {
- postpaid: ['Aliyun', 'Huawei', 'Google', 'Qcloud', 'HCSO', 'HCS', 'Aws'],
- prepaid: ['Aliyun', 'Huawei', 'Qcloud'],
- }
- export default {
- name: 'ItemArea',
- components: {
- // 区域
- AreaSelects,
- },
- props: {
- names: {
- type: Array,
- },
- defaultActiveFirstOption: {
- type: Array,
- },
- isRequired: {
- type: Boolean,
- },
- billingType: {
- type: String,
- },
- filterBrandResource: String,
- },
- data () {
- return {
- providerList: [],
- }
- },
- computed: {
- isRds () {
- return this.$route.path.indexOf('rds') > -1
- },
- service () {
- return this.isRds ? 'dbinstances' : 'elasticcaches'
- },
- decorators () {
- return {
- provider: ['provider', {
- validateFirst: true,
- rules: [
- {
- required: this.isRequired, message: this.$t('db.text_30'),
- },
- {
- validator: (rule, value, _callback) => {
- if (!this.providerList || this.providerList.length === 0) {
- return _callback(new Error(this.$t('db.text_31')))
- }
- _callback()
- },
- }],
- }],
- }
- },
- providerParams () {
- const params = {
- service: this.service,
- // cloud_env: 'public',
- ...this.scopeParams,
- }
- if (this.service === 'elasticcaches') {
- params.brands = ['Huawei', 'Aliyun', 'Qcloud', 'HCS', 'Aws']
- }
- return params
- },
- zoneParams () {
- return {
- service: this.service,
- ...this.scopeParams,
- }
- },
- cloudregionParams () {
- return {
- service: this.service,
- ...this.scopeParams,
- }
- },
- },
- inject: ['form', 'formItemLayout', 'scopeParams'],
- watch: {
- billingType (type) {
- this.doFetchs(type)
- },
- },
- created () {
- if (this.isRds) {
- this.providers = PROVIDERS.postpaid
- }
- },
- methods: {
- doFetchs (billingType) {
- this.providers = PROVIDERS[billingType]
- this.$refs.areaSelects.fetchs(['provider', 'cloudregion'])
- },
- providerFetchSuccess (list = []) {
- const _list = list.filter(({ name }) => {
- if (this.providers) {
- return this.providers.indexOf(name) > -1
- }
- return true
- })
- this.providerList = _list
- this.form.fc.validateFields(['provider'])
- if (this.providerList.length === 0) {
- this.form.setFieldsValue({
- sku: undefined,
- })
- }
- return _list
- },
- cloudregionFetchSuccess (list = []) {
- if (this.providerList.length === 0) {
- return []
- }
- return list.filter(({ provider }) => {
- if (this.providers) {
- return this.providers.indexOf(provider) > -1
- }
- return true
- })
- },
- },
- }
- </script>
|