<template>
  <div>
    <el-dialog title="新增磁盘" append-to-body :visible.sync="config.visible" width="750px">
      <disk ref="disk" :item-data="itemData"></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/AddDiskCT.vue'
import { modifyResourceEFC } from 'services/services/product'

export default {
  components: { disk },
  props: {
    config: {
      type: Object
    }
  },
  data() {
    return {
      loading: false
    }
  },
  computed: {
    itemData() {
      const { service, categoryId, uuid: instance, name: instanceName, expiredTime, params, preview } = this.config.data
      return {
        preview,
        params,
        service,
        instance,
        instanceName,
        expiredTime
      }
    }
  },
  created() {},
  methods: {
    ok() {
      const obj = this.$refs.disk.ok()
      if (!obj) return this.$message.error('磁盘信息填写不完整')
      this.loading = true
      modifyResourceEFC(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>
