index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <template>
  2. <div>
  3. <a-form-item :label="$t('dashboard.text_98')">
  4. <a-row :gutter="8">
  5. <a-col :span="12">
  6. <a-form-item :wrapperCol="{ span: 24 }" class="mb-0">
  7. <a-select
  8. allowClear
  9. class="w-100"
  10. :labelInValue="labelInValue"
  11. v-decorator="decorators.cloud_env"
  12. :placeholder="$t('dashboard.text_99')"
  13. @change="cloudEnvChange"
  14. :filterOption="filterOption">
  15. <a-select-option v-for="item of cloudEnvs" :value="item.key" :key="item.key">{{ item.label }}</a-select-option>
  16. </a-select>
  17. </a-form-item>
  18. </a-col>
  19. <a-col :span="12">
  20. <a-form-item :wrapperCol="{ span: 24 }" class="mb-0">
  21. <a-select
  22. allowClear
  23. class="w-100"
  24. :labelInValue="labelInValue"
  25. v-decorator="decorators.brand"
  26. :placeholder="$t('dashboard.text_99')"
  27. @change="brandChange"
  28. :filterOption="filterOption">
  29. <a-select-option v-for="item of brands" :value="item.key" :key="item.key">{{ item.label }}</a-select-option>
  30. </a-select>
  31. </a-form-item>
  32. </a-col>
  33. </a-row>
  34. </a-form-item>
  35. <a-form-item :label="$t('dashboard.text_100')" class="mb-0">
  36. <a-radio-group v-decorator="decorators.regionAccountType" @change="regionAccountTypeChange">
  37. <a-radio-button value="region">{{$t('dashboard.text_101')}}</a-radio-button>
  38. <a-radio-button value="account">{{$t('dashboard.text_102')}}</a-radio-button>
  39. <a-radio-button v-if="showTag" value="schedtag">{{ $t('dictionary.schedtag') }}</a-radio-button>
  40. </a-radio-group>
  41. <a-form-item :wrapperCol="{ span: 24 }" v-if="regionAccountType === 'region'">
  42. <a-select
  43. allowClear
  44. class="w-100"
  45. :labelInValue="labelInValue"
  46. v-decorator="decorators.region"
  47. :placeholder="$t('dashboard.text_99')"
  48. @change="regionChange"
  49. :filterOption="filterOption"
  50. :loading="regionLoading">
  51. <a-select-option v-for="item of regions" :value="item.key" :key="item.key">{{ item.label }}</a-select-option>
  52. </a-select>
  53. </a-form-item>
  54. <a-form-item :wrapperCol="{ span: 24 }" v-if="regionAccountType === 'account'">
  55. <a-select
  56. allowClear
  57. class="w-100"
  58. :labelInValue="labelInValue"
  59. v-decorator="decorators.account"
  60. :placeholder="$t('dashboard.text_99')"
  61. @change="accountChange"
  62. :filterOption="filterOption"
  63. :loading="accountLoading">
  64. <a-select-option v-for="item of accounts" :value="item.key" :key="item.key">{{ item.label }}</a-select-option>
  65. </a-select>
  66. </a-form-item>
  67. <a-form-item :wrapperCol="{ span: 24 }" v-if="showTag && regionAccountType === 'schedtag'">
  68. <a-select
  69. allowClear
  70. class="w-100"
  71. :labelInValue="labelInValue"
  72. v-decorator="decorators.schedtag"
  73. :placeholder="$t('dashboard.text_99')"
  74. @change="schedtagChange"
  75. :filterOption="filterOption"
  76. :loading="schedtagLoading">
  77. <a-select-option v-for="item of schedtags" :value="item.key" :key="item.key">{{ item.label }}</a-select-option>
  78. </a-select>
  79. </a-form-item>
  80. </a-form-item>
  81. <!--a-form-item :label="$t('dashboard.host_type')" v-if="showHostType && isOneCloud">
  82. <a-radio-group v-decorator="decorators.host_type">
  83. <a-radio-button value="all">{{ $t('dashboard.text_99') }}</a-radio-button>
  84. <a-radio-button value="hypervisor">{{ $t('dashboard.hypervisor') }}</a-radio-button>
  85. <a-radio-button value="baremetal">{{ $t('dashboard.baremetal') }}</a-radio-button>
  86. </a-radio-group>
  87. </a-form-item-->
  88. <a-form-model-item :label="$t('iam.project_tag')" prop="__meta__" v-if="showTag">
  89. <pairs-tag v-decorator="decorators.tags" />
  90. </a-form-model-item>
  91. <a-form-item :label="$t('dashboard.text_96')" class="mb-0" v-if="decorators.all_usage_key">
  92. <a-form-item :wrapperCol="{ span: 24 }">
  93. <usage-select
  94. class="w-100"
  95. v-decorator="decorators.all_usage_key"
  96. :usages="totalUsageOptions"
  97. @change="allUsageChange" />
  98. <div slot="extra" v-if="showDocsLink()">
  99. <i18n path="metricConfig.create_form.all_usage_extra">
  100. <template #link>
  101. <help-link :href="metricDoc">{{$t('metricConfig.create_form.all_usage_link')}}</help-link>
  102. </template>
  103. </i18n>
  104. </div>
  105. </a-form-item>
  106. </a-form-item>
  107. <a-form-item :label="usageLabel || $t('dashboard.text_97')" class="mb-0" v-if="decorators.usage_key">
  108. <a-form-item :wrapperCol="{ span: 24 }">
  109. <usage-select
  110. class="w-100"
  111. v-decorator="decorators.usage_key"
  112. :usages="partUsageOptions"
  113. @change="usageChange" />
  114. <div slot="extra">
  115. <i18n :path="usageLabel?'metricConfig.create_form.metric_extra':'metricConfig.create_form.usage_extra'">
  116. <template #link>
  117. <help-link :href="metricDoc">{{$t('metricConfig.create_form.usage_link')}}</help-link>
  118. </template>
  119. </i18n>
  120. </div>
  121. </a-form-item>
  122. </a-form-item>
  123. <a-form-item :label="$t('dashboard.usage_metric_name')" class="mb-0" v-if="decorators.usage_label">
  124. <a-form-item :wrapperCol="{ span: 24 }">
  125. <a-input class="w-100" v-decorator="decorators.usage_label" />
  126. </a-form-item>
  127. </a-form-item>
  128. <a-form-item :label="$t('dashboard.remaining_usage_metric_name')" class="mb-0" v-if="decorators.un_usage_label">
  129. <a-form-item :wrapperCol="{ span: 24 }">
  130. <a-input class="w-100" v-decorator="decorators.un_usage_label" />
  131. </a-form-item>
  132. </a-form-item>
  133. </div>
  134. </template>
  135. <script>
  136. import * as R from 'ramda'
  137. import _ from 'lodash'
  138. import { mapGetters } from 'vuex'
  139. import { USAGE_CONFIG, getMetricDocs } from '@Dashboard/constants'
  140. import { typeClouds } from '@/utils/common/hypervisor'
  141. import { usageMap } from '@/constants/generalUsage'
  142. import PairsTag from '@/sections/PairsTag'
  143. import { showDocsLink } from '@/constants/docs'
  144. import UsageSelect from './UsageSelect'
  145. export default {
  146. name: 'QuotaConfig',
  147. components: {
  148. UsageSelect,
  149. PairsTag,
  150. },
  151. props: {
  152. labelInValue: {
  153. type: Boolean,
  154. },
  155. decorators: {
  156. type: Object,
  157. },
  158. fc: {
  159. type: Object,
  160. required: true,
  161. },
  162. fd: {
  163. type: Object,
  164. required: false,
  165. },
  166. usageLabel: {
  167. type: String,
  168. },
  169. colorLabel: {
  170. type: String,
  171. },
  172. showTag: {
  173. type: Boolean,
  174. default: false,
  175. },
  176. /* showHostType: {
  177. type: Boolean,
  178. default: false,
  179. }, */
  180. },
  181. data () {
  182. return {
  183. showDocsLink,
  184. regionAccountType: _.get(this.decorators, 'regionAccountType[1].initialValue') || 'region',
  185. cloudEnvs: [],
  186. cloudEnvData: {},
  187. brands: [],
  188. brandData: {},
  189. accounts: [],
  190. accountLoading: false,
  191. regions: [],
  192. regionLoading: false,
  193. translateUsage: this.$t('usage'),
  194. totalUsageOptions: [],
  195. partUsageOptions: [],
  196. metricDoc: getMetricDocs(this.$store.getters.scope),
  197. schedtags: [],
  198. schedtagLoading: false,
  199. }
  200. },
  201. computed: {
  202. ...mapGetters(['scope', 'capability']),
  203. cloudEnv () {
  204. return R.is(Object, this.cloudEnvData) ? this.cloudEnvData.key : this.cloudEnvData
  205. },
  206. brand () {
  207. return R.is(Object, this.brandData) ? this.brandData.key : this.brandData
  208. },
  209. isRing () {
  210. if (this.usageLabel) {
  211. return false
  212. } else {
  213. return true
  214. }
  215. },
  216. isOneCloud () {
  217. return this.brand === typeClouds.brandMap.OneCloud.key
  218. },
  219. },
  220. destroyed () {
  221. this.am = null
  222. this.rm = null
  223. },
  224. mounted () {
  225. this.fc.setFieldsValue({
  226. regionAccountType: this.regionAccountType,
  227. })
  228. this.am = new this.$Manager('cloudaccounts')
  229. this.rm = new this.$Manager('cloudregions')
  230. this.sm = new this.$Manager('schedtags')
  231. this.fetchCloudEnvs()
  232. this.$watch('regionAccountType', {
  233. handler (val) {
  234. this.fc.setFieldsValue({
  235. region: undefined,
  236. account: undefined,
  237. })
  238. if (val === 'region') {
  239. this.fetchRegions()
  240. }
  241. if (val === 'account') {
  242. this.fetchAccounts()
  243. }
  244. if (val === 'schedtag') {
  245. this.fetchSchedtags()
  246. }
  247. },
  248. immediate: true,
  249. })
  250. this.totalUsageOptions = this.totalUsages()
  251. let key = ''
  252. if (this.fd && this.fd.all_usage_key) {
  253. key = this.fd.all_usage_key
  254. }
  255. this.partUsageOptions = this.partUsages(key)
  256. },
  257. methods: {
  258. filterOption (input, option) {
  259. return (
  260. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  261. )
  262. },
  263. /*
  264. * @params {Object} cloudEnv { key: <cloudEnvId> }
  265. */
  266. _setInitCloudEnv (cloudEnv) {
  267. if (!R.isNil(cloudEnv) && !R.isEmpty(cloudEnv)) {
  268. if (this.labelInValue) {
  269. this.fc.setFieldsValue({
  270. cloud_env: { key: cloudEnv.key, label: cloudEnv.label },
  271. })
  272. } else {
  273. this.fc.setFieldsValue({
  274. cloud_env: cloudEnv.key,
  275. })
  276. }
  277. }
  278. },
  279. /*
  280. * @params {Object} brand { key: <brandId> }
  281. */
  282. _setInitBrand (brand) {
  283. if (!R.isNil(brand) && !R.isEmpty(brand)) {
  284. if (this.labelInValue) {
  285. this.fc.setFieldsValue({
  286. brand: { key: brand.key, label: brand.label },
  287. })
  288. } else {
  289. this.fc.setFieldsValue({
  290. brand: brand.key,
  291. })
  292. }
  293. }
  294. },
  295. /*
  296. * @params {Object} region { key: <regionId> }
  297. */
  298. _setInitRegion (region) {
  299. if (!R.isNil(region) && !R.isEmpty(region)) {
  300. if (this.labelInValue) {
  301. this.fc.setFieldsValue({
  302. region: { key: region.key, label: region.label },
  303. })
  304. } else {
  305. this.fc.setFieldsValue({
  306. region: region.key,
  307. })
  308. }
  309. }
  310. },
  311. /*
  312. * @params {Object} account { key: <accountId> }
  313. */
  314. _setInitAccount (account) {
  315. if (!R.isNil(account) && !R.isEmpty(account)) {
  316. if (this.labelInValue) {
  317. this.fc.setFieldsValue({
  318. account: { key: account.key, label: account.label },
  319. })
  320. } else {
  321. this.fc.setFieldsValue({
  322. account: account.key,
  323. })
  324. }
  325. }
  326. },
  327. fetchCloudEnvs () {
  328. const cloudEnvs = []
  329. let brands = this.capability.brands
  330. brands = R.concat(brands, this.capability.disabled_brands)
  331. brands = R.uniq(brands)
  332. for (let i = 0, len = brands.length; i < len; i++) {
  333. const data = R.find(R.propEq('key', typeClouds.brandMap[brands[i]].cloud_env))(cloudEnvs)
  334. if (!data) {
  335. cloudEnvs.push({ key: typeClouds.brandMap[brands[i]].cloud_env, label: this.$t(`cloud_env.${typeClouds.brandMap[brands[i]].cloud_env}`) })
  336. }
  337. }
  338. this.cloudEnvs = cloudEnvs.map(val => ({ ...val, key: val.key, label: val.label }))
  339. let defaultData
  340. const initialValue = _.get(this.decorators, 'cloud_env[1].initialValue')
  341. if (initialValue) {
  342. const findInitValue = this.cloudEnvs.find(val => val.key === (initialValue.key || initialValue))
  343. if (findInitValue) {
  344. defaultData = { key: findInitValue.key, label: findInitValue.label }
  345. }
  346. }
  347. this._setInitCloudEnv(defaultData)
  348. this.cloudEnvChange(defaultData || {})
  349. },
  350. fetchBrands () {
  351. let brands = []
  352. R.forEachObjIndexed((value, key) => {
  353. if (value.cloud_env === this.cloudEnv) {
  354. brands.push(value)
  355. }
  356. }, typeClouds.brandMap)
  357. brands = brands.filter(item => this.capability.brands.includes(item.brand) || this.capability.disabled_brands.includes(item.brand))
  358. this.brands = brands.map(val => ({ ...val, key: val.key, label: val.label }))
  359. let defaultData
  360. const initialValue = _.get(this.decorators, 'brand[1].initialValue')
  361. if (initialValue) {
  362. const findInitValue = this.brands.find(val => val.key === (initialValue.key || initialValue))
  363. if (findInitValue) {
  364. defaultData = { key: findInitValue.key, label: findInitValue.label }
  365. }
  366. }
  367. this._setInitBrand(defaultData)
  368. this.brandChange(defaultData || {})
  369. },
  370. async fetchRegions () {
  371. this.regionLoading = true
  372. try {
  373. const params = {
  374. scope: this.scope,
  375. }
  376. if (this.cloudEnv) params.cloud_env = this.cloudEnv
  377. if (this.brand) params.brand = this.brand
  378. const response = await this.rm.list({ params })
  379. const data = response.data.data
  380. this.regions = data.map(val => ({ ...val, key: val.id, label: val._i18n && val._i18n.name ? val._i18n.name : val.name })) || []
  381. let defaultData
  382. const initialValue = _.get(this.decorators, 'region[1].initialValue')
  383. if (initialValue) {
  384. const findInitValue = this.regions.find(val => val.key === (initialValue.key || initialValue))
  385. if (findInitValue) {
  386. defaultData = { key: findInitValue.key, label: findInitValue.label }
  387. }
  388. }
  389. this.regionChange(defaultData || {})
  390. this._setInitRegion(defaultData || {})
  391. } catch (error) {
  392. throw error
  393. } finally {
  394. this.regionLoading = false
  395. }
  396. },
  397. async fetchAccounts () {
  398. this.accountLoading = true
  399. try {
  400. const params = {
  401. scope: this.scope,
  402. }
  403. if (this.cloudEnv) params.cloud_env = this.cloudEnv
  404. if (this.brand) params.brand = this.brand
  405. const response = await this.am.list({ params })
  406. const data = response.data.data
  407. this.accounts = data.map(val => ({ ...val, key: val.id, label: val.name })) || []
  408. let defaultData
  409. const initialValue = _.get(this.decorators, 'account[1].initialValue')
  410. if (initialValue) {
  411. const findInitValue = this.accounts.find(val => val.key === (initialValue.key || initialValue))
  412. if (findInitValue) {
  413. defaultData = { key: findInitValue.key, label: findInitValue.label }
  414. }
  415. }
  416. this.accountChange(defaultData || {})
  417. this._setInitAccount(defaultData || {})
  418. } catch (error) {
  419. throw error
  420. } finally {
  421. this.accountLoading = false
  422. }
  423. },
  424. cloudEnvChange (cloudEnv) {
  425. const cloudEnvId = R.is(Object, cloudEnv) ? cloudEnv.key : cloudEnv
  426. this.cloudEnvData = cloudEnv
  427. if (cloudEnvId) {
  428. this.fc.setFieldsValue({
  429. brand: undefined,
  430. region: undefined,
  431. account: undefined,
  432. })
  433. this.fetchBrands()
  434. if (this.regionAccountType === 'region') {
  435. this.fetchRegions()
  436. }
  437. if (this.regionAccountType === 'account') {
  438. this.fetchAccounts()
  439. }
  440. if (this.regionAccountType === 'schedtag') {
  441. this.fetchSchedtags()
  442. }
  443. this.$emit('update:env', cloudEnvId)
  444. } else {
  445. this.fc.setFieldsValue({
  446. cloud_env: undefined,
  447. brand: undefined,
  448. region: undefined,
  449. account: undefined,
  450. })
  451. }
  452. this.updateUsages()
  453. },
  454. brandChange (brand) {
  455. const brandId = R.is(Object, brand) ? brand.key : brand
  456. this.brandData = brand
  457. if (brandId) {
  458. this.fc.setFieldsValue({
  459. region: undefined,
  460. account: undefined,
  461. })
  462. if (this.regionAccountType === 'region') {
  463. this.fetchRegions()
  464. }
  465. if (this.regionAccountType === 'account') {
  466. this.fetchAccounts()
  467. }
  468. this.$emit('update:brand', brandId)
  469. this.fc.getFieldDecorator('brand', { preserve: true, initialValue: brand })
  470. } else {
  471. this.fc.setFieldsValue({
  472. brand: undefined,
  473. region: undefined,
  474. account: undefined,
  475. })
  476. }
  477. this.updateUsages()
  478. },
  479. regionChange (region) {
  480. const regionId = R.is(Object, region) ? region.key : region
  481. this.$emit('update:region', regionId)
  482. },
  483. accountChange (account) {
  484. const accountId = R.is(Object, account) ? account.key : account
  485. this.$emit('update:account', accountId)
  486. },
  487. allUsageChange (allUsage) {
  488. this.partUsageOptions = this.partUsages(allUsage)
  489. this.fc.setFieldsValue({ usage_key: undefined })
  490. this.$emit('update:all_usage_key', allUsage)
  491. },
  492. usageChange (usage) {
  493. this.$emit('update:usage_key', usage)
  494. },
  495. colorChange (color) {
  496. this.$emit('update:color', color)
  497. },
  498. regionAccountTypeChange (e) {
  499. this.regionAccountType = e.target.value
  500. },
  501. totalKeys () {
  502. const keys = []
  503. for (const res in usageMap) {
  504. if (usageMap[res].field && usageMap[res].field.total && usageMap[res].field.total[this.scope]) {
  505. if (R.is(Array, usageMap[res].field.total[this.scope])) {
  506. usageMap[res].field.total[this.scope].map(key => {
  507. keys.push(key)
  508. })
  509. } else {
  510. keys.push(usageMap[res].field.total[this.scope])
  511. }
  512. }
  513. }
  514. return keys
  515. },
  516. partKeys (totalKey) {
  517. const keys = []
  518. for (const res in usageMap) {
  519. if (usageMap[res].field) {
  520. if (totalKey) {
  521. if (!usageMap[res].field.total) {
  522. continue
  523. }
  524. if (!usageMap[res].field.total[this.scope]) {
  525. continue
  526. }
  527. if (R.is(String, usageMap[res].field.total[this.scope]) && usageMap[res].field.total[this.scope] !== totalKey) {
  528. continue
  529. }
  530. if (R.is(Array, usageMap[res].field.total[this.scope]) && !usageMap[res].field.total[this.scope].includes(totalKey)) {
  531. continue
  532. }
  533. }
  534. for (const part in usageMap[res].field) {
  535. if (part !== 'total') {
  536. if (usageMap[res].field[part][this.scope]) {
  537. if (R.is(Array, usageMap[res].field[part][this.scope])) {
  538. usageMap[res].field[part][this.scope].map(key => {
  539. keys.push(key)
  540. })
  541. } else {
  542. keys.push(usageMap[res].field[part][this.scope])
  543. }
  544. }
  545. }
  546. }
  547. }
  548. }
  549. return keys
  550. },
  551. updateUsages () {
  552. console.log('update')
  553. this.totalUsageOptions = this.totalUsages()
  554. let key = ''
  555. if (this.fd && this.fd.all_usage_key) {
  556. key = this.fd.all_usage_key
  557. }
  558. this.partUsageOptions = this.partUsages(key)
  559. },
  560. usages () {
  561. const ret = []
  562. for (const key in USAGE_CONFIG) {
  563. if (USAGE_CONFIG[key].scope && USAGE_CONFIG[key].scope !== this.$store.getters.scope) {
  564. continue
  565. }
  566. if (USAGE_CONFIG[key].clouds && USAGE_CONFIG[key].clouds.length > 0 && this.cloudEnv && !USAGE_CONFIG[key].clouds.includes(this.cloudEnv)) {
  567. if (!USAGE_CONFIG[key].brands) {
  568. continue
  569. }
  570. if (USAGE_CONFIG[key].brands && this.brand && !USAGE_CONFIG[key].brands.includes(this.brand)) {
  571. continue
  572. }
  573. }
  574. const k = USAGE_CONFIG[key].origin_key || key
  575. ret.push({
  576. key: k,
  577. scope: USAGE_CONFIG[key].scope,
  578. label: this.translateUsage[k] ? this.translateUsage[k] : k,
  579. })
  580. }
  581. return ret
  582. },
  583. totalUsages () {
  584. const usages = this.usages()
  585. if (!this.isRing) {
  586. return usages
  587. }
  588. const totalKeys = this.totalKeys()
  589. const ret = []
  590. for (var i = 0; i < usages.length; i++) {
  591. if (totalKeys.includes(usages[i].key)) {
  592. ret.push(usages[i])
  593. }
  594. }
  595. return ret
  596. },
  597. partUsages (val) {
  598. const usages = this.usages()
  599. if (!this.isRing) {
  600. return usages
  601. }
  602. const partKeys = this.partKeys(val)
  603. const ret = []
  604. for (var i = 0; i < usages.length; i++) {
  605. if (partKeys.includes(usages[i].key)) {
  606. ret.push(usages[i])
  607. }
  608. }
  609. return ret
  610. },
  611. async fetchSchedtags () {
  612. this.schedtagLoading = true
  613. try {
  614. const params = {
  615. scope: this.scope,
  616. }
  617. if (this.cloudEnv) params.cloud_env = this.cloudEnv
  618. if (this.brand) params.brand = this.brand
  619. const response = await this.sm.list({ params })
  620. const data = response.data.data
  621. this.schedtags = data.map(val => ({ ...val, key: val.id, label: val.name })) || []
  622. let defaultData
  623. const initialValue = _.get(this.decorators, 'account[1].initialValue')
  624. if (initialValue) {
  625. const findInitValue = this.schedtags.find(val => val.key === (initialValue.key || initialValue))
  626. if (findInitValue) {
  627. defaultData = { key: findInitValue.key, label: findInitValue.label }
  628. }
  629. }
  630. this.schedtagChange(defaultData || {})
  631. this._setInitSchedtag()
  632. } catch (error) {
  633. throw error
  634. } finally {
  635. this.schedtagLoading = false
  636. }
  637. },
  638. schedtagChange (schedtag) {
  639. const schedtagId = R.is(Object, schedtag) ? schedtag.key : schedtag
  640. this.$emit('update:schedtag', schedtagId)
  641. },
  642. _setInitSchedtag (schedtag) {
  643. if (!R.isNil(schedtag) && !R.isEmpty(schedtag)) {
  644. if (this.labelInValue) {
  645. this.fc.setFieldsValue({
  646. schedtag: { key: schedtag.key, label: schedtag.label },
  647. })
  648. } else {
  649. this.fc.setFieldsValue({
  650. schedtag: schedtag.key,
  651. })
  652. }
  653. }
  654. },
  655. },
  656. }
  657. </script>