<!--
 * @Author: ssl 710450920@qq.com
 * @Date: 2022-12-14 16:26:27
 * @LastEditors: ssl 710450920@qq.com
 * @LastEditTime: 2023-09-11 10:49:40
 * @FilePath: \csc\src\views\resource\vm\details\sf\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="1250px">
      <disk ref="disk" :item-data="itemData" :add-btn="false" service-code="sangfor.standard.volume">
        <div slot="other">
          <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 { modifyResource } from 'services/services/product'

export default {
  components: { disk },
  props: {
    config: {
      type: Object
    }
  },
  data () {
    return {
      loading: false,
      preallocate: 'metadata'
    }
  },
  computed: {
    itemData() {
      const { service, uuid: instance, name: instanceName, expiredTime, params, preview } = this.config.data
      return {
        preview,
        params,
        service,
        instance,
        instanceName,
        expiredTime,
        configs: {
          projectLeaderId: ''
        },
        location: {
          remark: '',
          groupId: ''
        }
      }
    }
  },
  created () {
  },
  methods: {
    ok () {
      const obj = this.$refs.disk.ok()
      if (!obj) return this.$message.error('磁盘信息填写不完整')
      const { datastoreId: dataStoreId, datastore: dataStoreUuid } = this.config.data
      obj.addDataDisks[0] = {
        ...obj.addDataDisks[0],
        preallocate: this.preallocate,
        dataStoreId,
        dataStoreUuid
      }
      this.loading = true;
      console.log(this.config.data)
      modifyResource(obj).then(data => {
        if (data.success) {
          this.$message.success(data.message)
          this.config.visible = false;
          // if (data.data) this.$router.push({ path: `/order/${data.data}` })
        }
      }).finally(() => {
        this.loading = false;
      })
    }
  }
}
</script>

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