<!--
 * @Author: a710450920@163.com sun970611.
 * @Date: 2022-09-19 21:55:21
 * @LastEditors: ssl 710450920@qq.com
 * @LastEditTime: 2023-08-06 18:15:09
 * @FilePath: /csc-web/src/views/resource/vm/details/vmware/dialog/addDisk.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-dialog title="新增磁盘" append-to-body :visible.sync="config.visible" width="750px">
      <disk ref="disk" :item-data="itemData"  :service-code="serviceCode">
        <div slot="other" v-if="serviceCode === 'sangfor.standard.volume'">
          <basic-form-item label="分配方式：" label-width="100px">
            <el-radio-group v-model="preallocate">
              <el-radio label="metadata">动态分配</el-radio>
              <el-radio label="off">精简分配</el-radio>
              <el-radio label="full">预分配</el-radio>
            </el-radio-group>
          </basic-form-item>
        </div>
      </disk>
      <span slot="footer" class="dialog-footer">
        <el-button type="ghost" @click="config.visible = false">取 消</el-button>
        <el-button type="primary" @click="ok" :loading="loading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import disk from '@/views/personal/apply/components/AddDisk.vue'
import { detailHost, modifyVm, patchDisk, detailCloudVendor, createVmTemplate, detailVm, vmVmtools, getVcConsole, getVmTickets, vmHotConfigEnable, getRes, getVolume, getVmConsole, removeFloatIpPorts, patchVmId, patchVmResize, conditionVoleme } from 'services/platform/index';

export default {
  components: { disk },
  props: {
    config: {
      type: Object
    },
    serviceCode: {
      type: String
    },
    addData: {
      type: Object
    }
  },
  data () {
    return {
      loading: false,
      preallocate: 'metadata'
    }
  },
  computed: {
    itemData() {
      const { service, uuid: instance, name: instanceName, expiredTime, params = { osCategory: this.config.data.osCategory, type: this.config.data.vendorType }, preview } = this.config.data
      return {
        preview,
        params,
        service,
        instance,
        instanceName,
        expiredTime
      }
    }
  },
  created () {
  },
  methods: {
    async ok () {
      const obj = this.$refs.disk.ok()
      if (this.serviceCode === 'sangfor.standard.volume') {
        this.loading = true
        const { data: { datastoreId: dataStoreId, datastore: dataStoreUuid } } = await detailVm(this.config.data.id)
        obj.addDataDisks[0] = {
          ...obj.addDataDisks[0],
          preallocate: this.preallocate,
          dataStoreId,
          dataStoreUuid,
          fileSystem: ''
        }
        this.loading = false
      }
      if (!obj) return this.$message.error('磁盘信息填写不完整')
      this.$emit('update:addData', {
        ...this.addData,
        ...obj,
        addDataDisks: [
          ...this.addData.addDataDisks,
          ...obj.addDataDisks
        ],
        upgrade: [
          ...this.addData.upgrade,
          ...obj.upgrade
        ]
      })
      this.config.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.w {
  width: 100px !important;
}
.add-border{
  padding: 2px;
  cursor: pointer;
  border: 1px dashed black;
  text-align: center;
}
</style>
