You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpecificationDialog.vue 9.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="base-dlg">
  3. <BaseDialog :visible.sync="dialogShow" :width="`700px`"
  4. :title="type === 'add' ? $t('resourcesManagement.addResSpecificationAndPriceInfo') : $t('resourcesManagement.editResSpecificationAndPriceInfo')"
  5. @open="open" @opened="opened" @close="close" @closed="closed">
  6. <div class="dlg-content">
  7. <div class="form">
  8. <div class="form-row">
  9. <div class="title required">
  10. <span>{{ $t('resourcesManagement.resQueue') }}</span>
  11. </div>
  12. <div class="content">
  13. <el-select v-model="dataInfo.QueueId" :disabled="type === 'edit'">
  14. <el-option v-for="item in this.queueList" :key="item.k" :label="item.v" :value="item.k" />
  15. </el-select>
  16. </div>
  17. </div>
  18. <div class="form-row">
  19. <div class="title">
  20. <span>{{ $t('resourcesManagement.sourceSpecCode') }}</span>
  21. </div>
  22. <div class="content">
  23. <el-input v-model="dataInfo.SourceSpecId" :placeholder="$t('resourcesManagement.sourceSpecCodeTips')"
  24. :disabled="type === 'edit'">
  25. </el-input>
  26. </div>
  27. </div>
  28. <div class="form-row">
  29. <div class="title required">
  30. <span>{{ $t('resourcesManagement.accCardsNum') }}</span>
  31. </div>
  32. <div class="content">
  33. <el-input v-model="dataInfo.AccCardsNum" type="number" placeholder="" :disabled="type === 'edit'">
  34. </el-input>
  35. </div>
  36. </div>
  37. <div class="form-row">
  38. <div class="title required">
  39. <span>{{ $t('resourcesManagement.cpuNum') }}</span>
  40. </div>
  41. <div class="content">
  42. <el-input v-model="dataInfo.CpuCores" type="number" placeholder="" :disabled="type === 'edit'"></el-input>
  43. </div>
  44. </div>
  45. <div class="form-row">
  46. <div class="title required">
  47. <span>{{ $t('resourcesManagement.gpuMem') }}(GB)</span>
  48. </div>
  49. <div class="content">
  50. <el-input v-model="dataInfo.GPUMemGiB" type="number" placeholder="" :disabled="type === 'edit'">
  51. </el-input>
  52. </div>
  53. </div>
  54. <div class="form-row">
  55. <div class="title required">
  56. <span>{{ $t('resourcesManagement.mem') }}(GB)</span>
  57. </div>
  58. <div class="content">
  59. <el-input v-model="dataInfo.MemGiB" type="number" placeholder="" :disabled="type === 'edit'"></el-input>
  60. </div>
  61. </div>
  62. <div class="form-row">
  63. <div class="title required">
  64. <span>{{ $t('resourcesManagement.shareMem') }}(GB)</span>
  65. </div>
  66. <div class="content">
  67. <el-input v-model="dataInfo.ShareMemGiB" type="number" placeholder="" :disabled="type === 'edit'">
  68. </el-input>
  69. </div>
  70. </div>
  71. <div class="form-row">
  72. <div class="title required">
  73. <span>{{ $t('resourcesManagement.unitPrice') }}({{ $t('resourcesManagement.point_hr') }})</span>
  74. </div>
  75. <div class="content">
  76. <el-input v-model="dataInfo.UnitPrice" type="number" placeholder=""></el-input>
  77. </div>
  78. </div>
  79. <div class="form-row">
  80. <div class="title required">
  81. <span>{{ $t('status') }}</span>
  82. </div>
  83. <div class="content">
  84. <el-select v-model="dataInfo.Status" :disabled="type === 'edit'">
  85. <el-option v-for="item in this.statusList" :key="item.k" :label="item.v" :value="item.k" />
  86. </el-select>
  87. </div>
  88. </div>
  89. <div class="form-row" style="margin-top: 20px">
  90. <div class="title"></div>
  91. <div class="content">
  92. <el-button type="primary" class="btn confirm-btn" @click="confirm">{{ $t('confirm') }}</el-button>
  93. <el-button class="btn" @click="cancel">{{ $t('cancel') }}</el-button>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </BaseDialog>
  99. </div>
  100. </template>
  101. <script>
  102. import BaseDialog from '~/components/BaseDialog.vue';
  103. import { getResQueueCode, addResSpecification, updateResSpecification } from '~/apis/modules/resources';
  104. import { SPECIFICATION_STATUS, CLUSTERS, AI_CENTER } from '~/const';
  105. import { getListValueWithKey } from '~/utils';
  106. export default {
  107. name: "SpecificationDialog",
  108. props: {
  109. visible: { type: Boolean, default: false },
  110. title: { type: String, default: '' },
  111. type: { type: String, defalut: 'add' },
  112. data: { type: Object, default: () => ({}) },
  113. },
  114. components: {
  115. BaseDialog
  116. },
  117. data() {
  118. return {
  119. dialogShow: false,
  120. dataInfo: {},
  121. queueList: [],
  122. statusList: [...SPECIFICATION_STATUS],
  123. clusterList: [...CLUSTERS],
  124. aiCenterList: [...AI_CENTER],
  125. };
  126. },
  127. watch: {
  128. visible: function (val) {
  129. this.dialogShow = val;
  130. },
  131. },
  132. methods: {
  133. resetDataInfo() {
  134. this.dataInfo = {
  135. QueueId: '',
  136. AccCardsNum: '',
  137. CpuCores: '',
  138. MemGiB: '',
  139. ShareMemGiB: '',
  140. GPUMemGiB: '',
  141. UnitPrice: '',
  142. Status: '1',
  143. }
  144. },
  145. getQueueList() {
  146. getResQueueCode().then(res => {
  147. res = res.data;
  148. if (res.Code === 0) {
  149. const data = res.Data;
  150. const list = [];
  151. for (let i = 0, iLen = data.length; i < iLen; i++) {
  152. const item = data[i];
  153. list.push({
  154. k: item.ID,
  155. v: `${item.QueueCode}(${getListValueWithKey(this.clusterList, item.Cluster)} - ${getListValueWithKey(this.aiCenterList, item.AiCenterCode)})`,
  156. });
  157. }
  158. this.queueList.splice(0, Infinity, ...list);
  159. }
  160. }).catch(err => {
  161. console.log(err);
  162. });
  163. },
  164. open() {
  165. this.resetDataInfo();
  166. this.getQueueList();
  167. if (this.type === 'add') {
  168. //
  169. } else if (this.type === 'edit') {
  170. this.dataInfo = Object.assign(this.dataInfo, { ...this.data, Status: '2' });
  171. }
  172. this.$emit("open");
  173. },
  174. opened() {
  175. this.$emit("opened");
  176. },
  177. close() {
  178. this.$emit("close");
  179. },
  180. closed() {
  181. this.$emit("closed");
  182. this.$emit("update:visible", false);
  183. },
  184. confirm() {
  185. if (!this.dataInfo.QueueId || !this.dataInfo.AccCardsNum || !this.dataInfo.CpuCores || !this.dataInfo.MemGiB || !this.dataInfo.ShareMemGiB || !this.dataInfo.GPUMemGiB
  186. || !this.dataInfo.UnitPrice || !this.dataInfo.Status
  187. ) {
  188. this.$message({
  189. type: 'info',
  190. message: this.$t('pleaseCompleteTheInformationFirst')
  191. });
  192. return;
  193. }
  194. if (parseInt(this.dataInfo.AccCardsNum) != Number(this.dataInfo.AccCardsNum)) {
  195. this.$message({
  196. type: 'info',
  197. message: this.$t('pleaseEnterPositiveIntegerCardsTotalNum')
  198. });
  199. return;
  200. }
  201. const setApi = this.type === 'add' ? addResSpecification : updateResSpecification;
  202. setApi({
  203. ...this.dataInfo,
  204. action: this.type === 'edit' ? 'on-shelf' : undefined,
  205. AccCardsNum: Number(this.dataInfo.AccCardsNum),
  206. CpuCores: Number(this.dataInfo.CpuCores),
  207. MemGiB: Number(this.dataInfo.MemGiB),
  208. ShareMemGiB: Number(this.dataInfo.ShareMemGiB),
  209. GPUMemGiB: Number(this.dataInfo.GPUMemGiB),
  210. UnitPrice: Number(this.dataInfo.UnitPrice),
  211. Status: Number(this.dataInfo.Status),
  212. }).then(res => {
  213. res = res.data;
  214. if (res.Code === 0) {
  215. this.$message({
  216. type: 'success',
  217. message: this.$t('submittedSuccessfully')
  218. });
  219. this.$emit("confirm");
  220. } else {
  221. this.$message({
  222. type: 'error',
  223. message: this.$t('submittedFailed')
  224. });
  225. }
  226. }).catch(err => {
  227. console.log(err);
  228. this.$message({
  229. type: 'error',
  230. message: this.$t('submittedFailed')
  231. });
  232. })
  233. },
  234. cancel() {
  235. this.dialogShow = false;
  236. this.$emit("update:visible", false);
  237. }
  238. },
  239. mounted() {
  240. this.resetDataInfo();
  241. },
  242. };
  243. </script>
  244. <style scoped lang="less">
  245. .dlg-content {
  246. margin: 20px 0 25px 0;
  247. display: flex;
  248. justify-content: center;
  249. .form {
  250. width: 600px;
  251. .form-row {
  252. display: flex;
  253. min-height: 42px;
  254. margin-bottom: 4px;
  255. .title {
  256. width: 160px;
  257. display: flex;
  258. justify-content: flex-end;
  259. align-items: center;
  260. margin-right: 20px;
  261. color: rgb(136, 136, 136);
  262. font-size: 14px;
  263. &.required {
  264. span {
  265. position: relative;
  266. }
  267. span::after {
  268. position: absolute;
  269. right: -10px;
  270. top: -2px;
  271. vertical-align: top;
  272. content: '*';
  273. color: #db2828;
  274. }
  275. }
  276. }
  277. .content {
  278. width: 300px;
  279. display: flex;
  280. align-items: center;
  281. /deep/ .el-select {
  282. width: 100%;
  283. }
  284. }
  285. }
  286. }
  287. .btn {
  288. color: rgb(2, 0, 4);
  289. background-color: rgb(194, 199, 204);
  290. border-color: rgb(194, 199, 204);
  291. &.confirm-btn {
  292. color: #fff;
  293. background-color: rgb(56, 158, 13);
  294. border-color: rgb(56, 158, 13);
  295. }
  296. }
  297. }
  298. </style>