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 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. maxlength="255" :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, getAiCenterList } from '~/apis/modules/resources';
  104. import { SPECIFICATION_STATUS, CLUSTERS } 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. editOr: { type: Boolean, defalut: false },
  113. data: { type: Object, default: () => ({}) },
  114. },
  115. components: {
  116. BaseDialog
  117. },
  118. data() {
  119. return {
  120. dialogShow: false,
  121. dataInfo: {},
  122. queueList: [],
  123. statusList: [...SPECIFICATION_STATUS],
  124. clusterList: [...CLUSTERS],
  125. aiCenterList: [],
  126. };
  127. },
  128. watch: {
  129. visible: function (val) {
  130. this.dialogShow = val;
  131. },
  132. },
  133. methods: {
  134. resetDataInfo() {
  135. this.dataInfo = {
  136. QueueId: '',
  137. AccCardsNum: '',
  138. CpuCores: '',
  139. MemGiB: '',
  140. ShareMemGiB: '',
  141. GPUMemGiB: '',
  142. UnitPrice: '',
  143. Status: '1',
  144. }
  145. },
  146. getAiCenterList() {
  147. getAiCenterList().then(res => {
  148. res = res.data;
  149. if (res.Code === 0) {
  150. const list = res.Data;
  151. const data = list.map(item => {
  152. return {
  153. k: item.AiCenterCode,
  154. v: item.AiCenterName
  155. };
  156. });
  157. this.aiCenterList.splice(0, Infinity, ...data);
  158. }
  159. }).catch(err => {
  160. console.log(err);
  161. });
  162. },
  163. getQueueList() {
  164. getResQueueCode({ cluster: this.type === 'add' ? 'OpenI' : undefined }).then(res => {
  165. res = res.data;
  166. if (res.Code === 0) {
  167. const data = res.Data;
  168. const list = [];
  169. for (let i = 0, iLen = data.length; i < iLen; i++) {
  170. const item = data[i];
  171. list.push({
  172. k: item.ID,
  173. v: `${item.QueueCode}(${getListValueWithKey(this.clusterList, item.Cluster)} - ${item.AiCenterName})`,
  174. });
  175. }
  176. this.queueList.splice(0, Infinity, ...list);
  177. }
  178. }).catch(err => {
  179. console.log(err);
  180. });
  181. },
  182. open() {
  183. this.resetDataInfo();
  184. this.getQueueList();
  185. this.getAiCenterList();
  186. if (this.type === 'add') {
  187. //
  188. } else if (this.type === 'edit') {
  189. this.dataInfo = Object.assign(this.dataInfo, { ...this.data, Status: '2' });
  190. }
  191. this.$emit("open");
  192. },
  193. opened() {
  194. this.$emit("opened");
  195. },
  196. close() {
  197. this.$emit("close");
  198. },
  199. closed() {
  200. this.$emit("closed");
  201. this.$emit("update:visible", false);
  202. },
  203. confirm() {
  204. if (this.dataInfo.AccCardsNum === '' || this.dataInfo.CpuCores === '' || this.dataInfo.MemGiB === '' || this.dataInfo.ShareMemGiB === '' || this.dataInfo.GPUMemGiB === ''
  205. || this.dataInfo.UnitPrice === '' || !this.dataInfo.Status
  206. ) {
  207. this.$message({
  208. type: 'info',
  209. message: this.$t('pleaseCompleteTheInformationFirst')
  210. });
  211. return;
  212. }
  213. if (parseInt(this.dataInfo.AccCardsNum) != Number(this.dataInfo.AccCardsNum)) {
  214. this.$message({
  215. type: 'info',
  216. message: this.$t('pleaseEnterPositiveIntegerCardsTotalNum')
  217. });
  218. return;
  219. }
  220. const setApi = this.type === 'add' ? addResSpecification : updateResSpecification;
  221. const action = this.editOr ? 'edit' : this.type === 'edit' ? 'on-shelf' : undefined;
  222. setApi({
  223. ...this.dataInfo,
  224. action: action,
  225. AccCardsNum: Number(this.dataInfo.AccCardsNum),
  226. CpuCores: Number(this.dataInfo.CpuCores),
  227. MemGiB: Number(this.dataInfo.MemGiB),
  228. ShareMemGiB: Number(this.dataInfo.ShareMemGiB),
  229. GPUMemGiB: Number(this.dataInfo.GPUMemGiB),
  230. UnitPrice: Number(this.dataInfo.UnitPrice),
  231. Status: Number(this.dataInfo.Status),
  232. }).then(res => {
  233. res = res.data;
  234. if (res.Code === 0) {
  235. this.$message({
  236. type: 'success',
  237. message: this.$t('submittedSuccessfully')
  238. });
  239. this.$emit("confirm");
  240. } else {
  241. if (action === 'on-shelf' && res.Code === 1001) {
  242. this.$message({
  243. type: 'info',
  244. message: this.$t('resourcesManagement.onShelfCode1001')
  245. });
  246. } else if (action === 'on-shelf' && res.Code === 1003) {
  247. this.$message({
  248. type: 'info',
  249. message: this.$t('resourcesManagement.onShelfCode1003')
  250. });
  251. } else {
  252. this.$message({
  253. type: 'error',
  254. message: this.$t('submittedFailed')
  255. });
  256. }
  257. }
  258. }).catch(err => {
  259. console.log(err);
  260. this.$message({
  261. type: 'error',
  262. message: this.$t('submittedFailed')
  263. });
  264. })
  265. },
  266. cancel() {
  267. this.dialogShow = false;
  268. this.$emit("update:visible", false);
  269. }
  270. },
  271. mounted() {
  272. this.resetDataInfo();
  273. },
  274. };
  275. </script>
  276. <style scoped lang="less">
  277. .dlg-content {
  278. margin: 20px 0 25px 0;
  279. display: flex;
  280. justify-content: center;
  281. .form {
  282. width: 600px;
  283. .form-row {
  284. display: flex;
  285. min-height: 42px;
  286. margin-bottom: 4px;
  287. .title {
  288. width: 160px;
  289. display: flex;
  290. justify-content: flex-end;
  291. align-items: center;
  292. margin-right: 20px;
  293. color: rgb(136, 136, 136);
  294. font-size: 14px;
  295. &.required {
  296. span {
  297. position: relative;
  298. }
  299. span::after {
  300. position: absolute;
  301. right: -10px;
  302. top: -2px;
  303. vertical-align: top;
  304. content: '*';
  305. color: #db2828;
  306. }
  307. }
  308. }
  309. .content {
  310. width: 300px;
  311. display: flex;
  312. align-items: center;
  313. /deep/ .el-select {
  314. width: 100%;
  315. }
  316. }
  317. }
  318. }
  319. .btn {
  320. color: rgb(2, 0, 4);
  321. background-color: rgb(194, 199, 204);
  322. border-color: rgb(194, 199, 204);
  323. &.confirm-btn {
  324. color: #fff;
  325. background-color: rgb(56, 158, 13);
  326. border-color: rgb(56, 158, 13);
  327. }
  328. }
  329. }
  330. </style>