|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <template>
- <div class="base-dlg">
- <BaseDialog :visible.sync="dialogShow" :width="`700px`"
- :title="type === 'add' ? $t('resourcesManagement.addResSpecificationAndPriceInfo') : $t('resourcesManagement.editResSpecificationAndPriceInfo')"
- @open="open" @opened="opened" @close="close" @closed="closed">
- <div class="dlg-content">
- <div class="form">
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.resQueue') }}</span>
- </div>
- <div class="content">
- <el-select v-model="dataInfo.QueueId" :disabled="type === 'edit'">
- <el-option v-for="item in this.queueList" :key="item.k" :label="item.v" :value="item.k" />
- </el-select>
- </div>
- </div>
- <div class="form-row">
- <div class="title">
- <span>{{ $t('resourcesManagement.sourceSpecCode') }}</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.SourceSpecId" :placeholder="$t('resourcesManagement.sourceSpecCodeTips')"
- maxlength="255" :disabled="type === 'edit'">
- </el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.accCardsNum') }}</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.AccCardsNum" type="number" placeholder="" :disabled="type === 'edit'">
- </el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.cpuNum') }}</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.CpuCores" type="number" placeholder="" :disabled="type === 'edit'"></el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.gpuMem') }}(GB)</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.GPUMemGiB" type="number" placeholder="" :disabled="type === 'edit'">
- </el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.mem') }}(GB)</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.MemGiB" type="number" placeholder="" :disabled="type === 'edit'"></el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.shareMem') }}(GB)</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.ShareMemGiB" type="number" placeholder="" :disabled="type === 'edit'">
- </el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('resourcesManagement.unitPrice') }}({{ $t('resourcesManagement.point_hr') }})</span>
- </div>
- <div class="content">
- <el-input v-model="dataInfo.UnitPrice" type="number" placeholder=""></el-input>
- </div>
- </div>
- <div class="form-row">
- <div class="title required">
- <span>{{ $t('status') }}</span>
- </div>
- <div class="content">
- <el-select v-model="dataInfo.Status" :disabled="type === 'edit'">
- <el-option v-for="item in this.statusList" :key="item.k" :label="item.v" :value="item.k" />
- </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">{{ $t('confirm') }}</el-button>
- <el-button class="btn" @click="cancel">{{ $t('cancel') }}</el-button>
- </div>
- </div>
- </div>
- </div>
- </BaseDialog>
- </div>
- </template>
- <script>
- import BaseDialog from '~/components/BaseDialog.vue';
- import { getResQueueCode, addResSpecification, updateResSpecification, getAiCenterList } from '~/apis/modules/resources';
- import { SPECIFICATION_STATUS, CLUSTERS } from '~/const';
- import { getListValueWithKey } from '~/utils';
-
- export default {
- name: "SpecificationDialog",
- props: {
- visible: { type: Boolean, default: false },
- title: { type: String, default: '' },
- type: { type: String, defalut: 'add' },
- editOr: { type: Boolean, defalut: false },
- data: { type: Object, default: () => ({}) },
- },
- components: {
- BaseDialog
- },
- data() {
- return {
- dialogShow: false,
- dataInfo: {},
- queueList: [],
- statusList: [...SPECIFICATION_STATUS],
- clusterList: [...CLUSTERS],
- aiCenterList: [],
- };
- },
- watch: {
- visible: function (val) {
- this.dialogShow = val;
- },
- },
- methods: {
- resetDataInfo() {
- this.dataInfo = {
- QueueId: '',
- AccCardsNum: '',
- CpuCores: '',
- MemGiB: '',
- ShareMemGiB: '',
- GPUMemGiB: '',
- UnitPrice: '',
- Status: '1',
- }
- },
- getAiCenterList() {
- getAiCenterList().then(res => {
- res = res.data;
- if (res.Code === 0) {
- const list = res.Data;
- const data = list.map(item => {
- return {
- k: item.AiCenterCode,
- v: item.AiCenterName
- };
- });
- this.aiCenterList.splice(0, Infinity, ...data);
- }
- }).catch(err => {
- console.log(err);
- });
- },
- getQueueList() {
- getResQueueCode({ cluster: this.type === 'add' ? 'OpenI' : undefined }).then(res => {
- res = res.data;
- if (res.Code === 0) {
- const data = res.Data;
- const list = [];
- for (let i = 0, iLen = data.length; i < iLen; i++) {
- const item = data[i];
- list.push({
- k: item.ID,
- v: `${item.QueueCode}(${getListValueWithKey(this.clusterList, item.Cluster)} - ${item.AiCenterName})`,
- });
- }
- this.queueList.splice(0, Infinity, ...list);
- }
- }).catch(err => {
- console.log(err);
- });
- },
-
- open() {
- this.resetDataInfo();
- this.getQueueList();
- this.getAiCenterList();
- if (this.type === 'add') {
- //
- } else if (this.type === 'edit') {
- this.dataInfo = Object.assign(this.dataInfo, { ...this.data, Status: '2' });
- }
- this.$emit("open");
- },
- opened() {
- this.$emit("opened");
- },
- close() {
- this.$emit("close");
- },
- closed() {
- this.$emit("closed");
- this.$emit("update:visible", false);
- },
- confirm() {
- if (this.dataInfo.AccCardsNum === '' || this.dataInfo.CpuCores === '' || this.dataInfo.MemGiB === '' || this.dataInfo.ShareMemGiB === '' || this.dataInfo.GPUMemGiB === ''
- || this.dataInfo.UnitPrice === '' || !this.dataInfo.Status
- ) {
- this.$message({
- type: 'info',
- message: this.$t('pleaseCompleteTheInformationFirst')
- });
- return;
- }
- if (parseInt(this.dataInfo.AccCardsNum) != Number(this.dataInfo.AccCardsNum)) {
- this.$message({
- type: 'info',
- message: this.$t('pleaseEnterPositiveIntegerCardsTotalNum')
- });
- return;
- }
- const setApi = this.type === 'add' ? addResSpecification : updateResSpecification;
- const action = this.editOr ? 'edit' : this.type === 'edit' ? 'on-shelf' : undefined;
- setApi({
- ...this.dataInfo,
- action: action,
- AccCardsNum: Number(this.dataInfo.AccCardsNum),
- CpuCores: Number(this.dataInfo.CpuCores),
- MemGiB: Number(this.dataInfo.MemGiB),
- ShareMemGiB: Number(this.dataInfo.ShareMemGiB),
- GPUMemGiB: Number(this.dataInfo.GPUMemGiB),
- UnitPrice: Number(this.dataInfo.UnitPrice),
- Status: Number(this.dataInfo.Status),
- }).then(res => {
- res = res.data;
- if (res.Code === 0) {
- this.$message({
- type: 'success',
- message: this.$t('submittedSuccessfully')
- });
- this.$emit("confirm");
- } else {
- if (action === 'on-shelf' && res.Code === 1001) {
- this.$message({
- type: 'info',
- message: this.$t('resourcesManagement.onShelfCode1001')
- });
- } else if (action === 'on-shelf' && res.Code === 1003) {
- this.$message({
- type: 'info',
- message: this.$t('resourcesManagement.onShelfCode1003')
- });
- } else {
- this.$message({
- type: 'error',
- message: this.$t('submittedFailed')
- });
- }
- }
- }).catch(err => {
- console.log(err);
- this.$message({
- type: 'error',
- message: this.$t('submittedFailed')
- });
- })
- },
- 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>
|