| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <template>
- <page-footer>
- <template v-slot:right>
- <div class="d-flex align-items-center" v-if="hasMeterService()">
- <div class="mr-4 d-flex align-items-center">
- <div class="text-truncate">{{$t('compute.text_286')}}</div>
- <div class="ml-2 prices">
- <div class="hour d-flex">
- <template v-if="price">
- <m-animated-number :value="price" :formatValue="priceFormat" />
- <discount-price class="ml-2 mini-text" :discount="discount" :origin="originPrice" />
- </template>
- </div>
- <div class="tips text-truncate">
- <span v-html="priceTips" />
- </div>
- </div>
- </div>
- </div>
- <div class="btns-wrapper d-flex align-items-center">
- <a-button
- class="ml-3"
- type="primary"
- native-type="submit"
- html-type="submit"
- @click="handleConfirm"
- :loading="loading">{{ $t('common_258') }}</a-button>
- <a-button class="ml-3" @click="() => $router.back()">{{$t('common.cancel')}}</a-button>
- </div>
- </template>
- </page-footer>
- </template>
- <script>
- import _ from 'lodash'
- import { mapGetters } from 'vuex'
- import { PROVIDER_MAP } from '@/constants'
- import DiscountPrice from '@/sections/DiscountPrice'
- import { hasMeterService } from '@/utils/auth'
- import { PriceFetcherByPriceKey } from '@/utils/common/price'
- import { currencyUnitMap } from '@/constants/currency'
- export default {
- name: 'BottomBar',
- components: {
- DiscountPrice,
- },
- inject: ['form'],
- props: {
- currentCloudregion: {
- type: Object,
- },
- currentStorage: {
- type: Object,
- },
- storageTypes: {
- type: Array,
- },
- size: {
- type: Number,
- },
- currentCloudzone: {
- type: Object,
- },
- provider: {
- type: [Array, String],
- },
- },
- data () {
- this._getPrice = _.debounce(this._getPrice, 500)
- return {
- loading: false,
- priceObj: null,
- currency: currencyUnitMap.CNY.sign,
- discount: 0,
- price: null,
- priceFormat: null,
- originPrice: null,
- priceTips: '--',
- key: '',
- hasMeterService,
- }
- },
- computed: {
- ...mapGetters(['userInfo']),
- },
- watch: {
- currentStorage: {
- deep: true,
- handler (options) {
- this._getPrice()
- },
- },
- currentCloudregion (value) {
- if (value && value.provider) {
- this._getPrice()
- return
- }
- if (value && value.external_id) {
- this._getPrice()
- }
- },
- 'currentCloudzone.external_id' () {
- this._getPrice()
- },
- key () {
- this._getPrice()
- },
- size () {
- this._getPrice()
- },
- },
- created () {
- this._getPrice()
- },
- methods: {
- async _getPrice () {
- if (!hasMeterService()) return
- try {
- if (!this.currentStorage.value || !this.currentCloudregion) {
- this.key = ''
- return
- }
- // let _storageTypes = this.storageTypes.map(item => {
- // return item.split('/')
- // })
- // _storageTypes = Object.fromEntries(_storageTypes)
- let key = ''
- let region = ''
- let zone = ''
- const { type, backend } = this.getType(this.currentStorage.value)
- let external_id = this.currentCloudregion.external_id
- if (!external_id) {
- external_id = '/'
- }
- let pv = this.currentCloudregion.provider
- if (this.currentCloudregion.external_id && this.currentCloudregion.external_id.includes('/')) {
- const cloudregionExternalArr = external_id.split('/')
- if (this.currentCloudregion.cloud_env === 'public') {
- if (!this.currentCloudzone) return
- key = type
- region = cloudregionExternalArr[1]
- zone = this.currentCloudzone.external_id.split('/')[2]
- } else {
- key = `${backend}.${type}`
- }
- pv = cloudregionExternalArr[0]
- } else {
- key = `${backend}.${type}`
- }
- this.key = key
- const price_key = `${pv}::${region}::${zone}::disk::${key}`
- const pf = new PriceFetcherByPriceKey({
- scope: this.$store.getters.scope,
- priceKey: price_key,
- amount: this.size,
- })
- const p = await pf.getPriceObj()
- p.setOptions({ priceFmt: '0,0.000' })
- this.currency = p.currency
- this.discount = p.discount
- this.price = p.price
- this.priceFormat = p.priceFormat
- this.originPrice = p.originPrice
- this.priceTips = p.priceTips
- } catch (err) {
- throw err
- }
- },
- doCreate (data) {
- return new this.$Manager('disks').create({ data })
- },
- async handleConfirm () {
- this.loading = true
- try {
- let values = await this.form.fc.validateFields()
- const { project, domain, cloudregion, zone, manager_id, backend, encryptEnable, encrypt_key_id, encrypt_key_alg, storage, iops, throughput, ...rest } = values
- const oProvider = PROVIDER_MAP[this.currentCloudregion.provider]
- const provider = Array.isArray(this.provider) ? this.provider[0] : this.provider
- values = {
- ...rest,
- backend: backend.split('__')[0],
- medium: backend.split('__')[1],
- hypervisor: oProvider ? oProvider.hypervisor : provider,
- size: values.size * 1024,
- project_domain: (domain && domain.key) || this.userInfo.projectDomainId,
- project_id: (project && project.key) || this.userInfo.projectId,
- prefer_region_id: cloudregion,
- prefer_zone: zone,
- prefer_manager_id: manager_id,
- }
- if (encryptEnable === 'existing' && encrypt_key_id) {
- values.encrypt_key_id = encrypt_key_id
- } else if (encryptEnable === 'new') {
- values.encrypt_key_new = true
- values.encrypt_key_alg = encrypt_key_alg
- values.encrypt_key_user_id = this.userInfo.id
- }
- if (storage) {
- values.storage_id = storage
- }
- if (iops) {
- values.iops = iops
- }
- if (throughput) {
- values.throughput = throughput
- }
- Reflect.deleteProperty(values, 'cloudregion')
- Reflect.deleteProperty(values, 'zone')
- await this.doCreate(values)
- const successBack = () => {
- this.$message.success(this.$t('k8s.text_184'))
- this.$router.push('/disk')
- }
- successBack()
- } catch (error) {
- this.loading = false
- throw error
- }
- },
- getType (curVal) {
- const curIndex = curVal.lastIndexOf('__')
- const type = curVal.substring(0, curIndex)
- const backend = curVal.substr(curIndex + 2)
- return { type, backend }
- },
- },
- }
- </script>
- <style lang="less" scoped>
- @import '../../../../../../src/styles/less/theme';
- .prices {
- .hour {
- color: @error-color;
- font-size: 24px;
- }
- .tips {
- color: #999;
- font-size: 12px;
- }
- }
- </style>
|