<template>
  <div class="base-dlg">
    <BaseDialog :visible.sync="dialogShow" :width="`700px`" :title="`新增资源规格和单价信息`" @open="open" @opened="opened"
      @close="close" @closed="closed">
      <div class="dlg-content">
        <div class="form">
          <div class="form-row">
            <div class="title required">
              <span>资源池（队列）</span>
            </div>
            <div class="content">
              <el-select v-model="dataInfo.queue"></el-select>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>XPU数</span>
            </div>
            <div class="content">
              <el-input v-model="dataInfo.xpu" type="number" placeholder=""></el-input>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>CPU数</span>
            </div>
            <div class="content">
              <el-input v-model="dataInfo.cpu" type="number" placeholder=""></el-input>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>内存(GB)</span>
            </div>
            <div class="content">
              <el-input v-model="dataInfo.mem" type="number" placeholder=""></el-input>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>共享内存(GB)</span>
            </div>
            <div class="content">
              <el-input v-model="dataInfo.shareMem" type="number" placeholder=""></el-input>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>单价</span>
            </div>
            <div class="content">
              <el-input v-model="dataInfo.price" type="number" placeholder=""></el-input>
            </div>
          </div>
          <div class="form-row">
            <div class="title required">
              <span>状态</span>
            </div>
            <div class="content">
              <el-select v-model="dataInfo.status"></el-select>
            </div>
          </div>
          <div class="form-row" style="margin-top: 20px">
            <div class="title"></div>
            <div class="content">
              <el-button type="primary" class="btn confirm-btn" @click="confirm">确定</el-button>
              <el-button class="btn" @click="cancel">取消</el-button>
            </div>
          </div>
        </div>
      </div>
    </BaseDialog>
  </div>
</template>
<script>
import BaseDialog from '~/components/BaseDialog.vue';
import { getQueueList } from '~/apis/modules/resources';

export default {
  name: "SpecificationDialog",
  props: {
    visible: { type: Boolean, default: false },
    title: { type: String, default: '' },
    type: { type: String, defalut: 'add' },
    data: { type: Object, default: () => ({}) },
  },
  components: {
    BaseDialog
  },
  data() {
    return {
      dialogShow: false,
      dataInfo: {

      },
    };
  },
  watch: {
    visible: function (val) {
      this.dialogShow = val;
    },
  },
  methods: {
    resetDataInfo() {
      this.dataInfo = {
        queue: '',
        queueList: [],
        xpu: '',
        cpu: '',
        mem: '',
        shareMem: '',
        price: '',
        status: '',
        statusList: [],
      }
    },
    open() {
      this.resetDataInfo();
      if (this.type === 'add') {
        //
      } else if (this.type === 'edit') {
        this.dataInfo = Object.assign(this.dataInfo, { ...this.data });
      }
      console.log('open', this.type, this.data);
      this.$emit("open");
    },
    opened() {
      this.$emit("opened");
    },
    close() {
      this.$emit("close");
    },
    closed() {
      this.$emit("closed");
      this.$emit("update:visible", false);
    },
    confirm() {

    },
    cancel() {
      this.dialogShow = false;
      this.$emit("update:visible", false);
    }
  },
  mounted() {
    this.resetDataInfo();
  },
};
</script>
<style scoped lang="less">
.dlg-content {
  margin: 20px 0 25px 0;
  display: flex;
  justify-content: center;

  .form {
    width: 600px;

    .form-row {
      display: flex;
      min-height: 42px;
      margin-bottom: 4px;

      .title {
        width: 160px;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        margin-right: 20px;
        color: rgb(136, 136, 136);
        font-size: 14px;

        &.required {
          span {
            position: relative;
          }

          span::after {
            position: absolute;
            right: -10px;
            top: -2px;
            vertical-align: top;
            content: '*';
            color: #db2828;
          }
        }
      }

      .content {
        width: 300px;
        display: flex;
        align-items: center;

        /deep/ .el-select {
          width: 100%;
        }
      }
    }
  }

  .btn {
    color: rgb(2, 0, 4);
    background-color: rgb(194, 199, 204);
    border-color: rgb(194, 199, 204);

    &.confirm-btn {
      color: #fff;
      background-color: rgb(56, 158, 13);
      border-color: rgb(56, 158, 13);
    }
  }
}
</style>
