<template>
  <div>
    <el-dialog title="配置变更" append-to-body :visible.sync="addData.dialog" width="30%">
      <span>
        <basic-form ref="modifyData" :model="addData.data" :status-icon="true" label-width="80px">
          <basic-form-item label="cpu大小" prop="cpu">
            <el-input type="number" v-model="addData.data.cpu" :disabled="addData.cpuHotFlag">
              <template slot="append">核</template>
            </el-input>
          </basic-form-item>
          <basic-form-item label="内存大小" prop="memory">
            <el-input type="number" v-model="addData.data.memory" :disabled="addData.memHotFlag">
              <template slot="append">GB</template>
            </el-input>
          </basic-form-item>
        </basic-form>
      </span>
      <span slot="footer" class="dialog-footer">
         <el-button type="ghost" @click="addData.dialog = false">取 消</el-button>
         <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/* global $ */
import { modifyVm, detailVm } from 'services/platform/index'
export default {
  props: {
    addData: {
      type: Object,
      default: function () {
        return {
          data: {
            id: '',
            name: ''
          },
          dialog: false
        }
      }
    }
  },
  data () {
    return {
    }
  },
  methods: {
    submit () {
      this.$refs.modifyData.validate((valid) => {
        if (valid) {
          modifyVm(this.addData.data).then(data => {
            if (data.success) {
              this.$message.success(data.message);
              this.addData.dialog = false;
              this.$emit('back')
            }
          })
        }
      })
    },
    getDetail () {
      detailVm(this.addData.data.id).then(data => {
        if (data.success) {
          this.addData.data.name = data.data.name;
        }
      })
    }
  },
  created () {
    this.getDetail();
  }
}
</script>

<style>

</style>
