DialogOperators.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <el-dialog
  3. class="dialog-ocpi"
  4. :visible="visible"
  5. :before-close="e => hideDialog(false)"
  6. :close-on-click-modal="false"
  7. title="CREATE OCPI CONNECTION">
  8. <el-form
  9. ref="ocpiForm"
  10. :model="form"
  11. :rules="rules"
  12. label-width="120px"
  13. label-position="right"
  14. v-loading="initial">
  15. <el-form-item
  16. prop="url"
  17. class="form-item"
  18. label="Party URL:">
  19. <el-input
  20. v-model="form.url"
  21. class="flex-item"
  22. maxlength="100"/>
  23. </el-form-item>
  24. <el-form-item
  25. prop="token"
  26. class="form-item"
  27. label="Party Token:">
  28. <el-input
  29. class="flex-item"
  30. type="textarea"
  31. maxlength="300"
  32. :autosize="autosize"
  33. v-model="form.token"/>
  34. </el-form-item>
  35. <div class="flexcc" style="padding-top: 20px;">
  36. <el-button
  37. class="button"
  38. @click="hideDialog(false)">
  39. CANCEL
  40. </el-button>
  41. <el-button
  42. class="button"
  43. type="primary"
  44. :loading="loading"
  45. @click="onFormSave">
  46. INITIALIZE
  47. </el-button>
  48. </div>
  49. </el-form>
  50. </el-dialog>
  51. </template>
  52. <script>
  53. import ocpi from '../../../http/api/ocpi.js';
  54. export default {
  55. name: "DialogOperators",
  56. props: {
  57. visible: {
  58. type: Boolean,
  59. default: false
  60. }
  61. },
  62. data() {
  63. return {
  64. initial: false,
  65. loading: false,
  66. form: {
  67. url: "",
  68. token: ""
  69. },
  70. rules: {
  71. url: {
  72. required: true,
  73. message: "Url is required",
  74. trigger: "blur"
  75. },
  76. token: {
  77. required: true,
  78. message: "Token is required",
  79. trigger: "blur"
  80. }
  81. },
  82. autosize: {
  83. minRows: 3,
  84. maxRows: 6
  85. }
  86. };
  87. },
  88. mounted() {
  89. },
  90. methods: {
  91. hideDialog(success) {
  92. this.init();
  93. this.$emit("hide", success || false);
  94. },
  95. init() {
  96. this.form = {
  97. url: "",
  98. token: ""
  99. }
  100. this.loading = false;
  101. this.$nextTick(() => {
  102. if (this.$refs['ocpiForm']) {
  103. this.$refs['ocpiForm'].clearValidate();
  104. }
  105. })
  106. },
  107. onFormSave() {
  108. this.$refs['ocpiForm'].validate((valid) => {
  109. if (valid) {
  110. this.onReceive();
  111. }
  112. })
  113. },
  114. onReceive() {
  115. this.loading = true;
  116. ocpi.initRoamingOperators(this.form).then(res => {
  117. this.$message({
  118. type: 'success',
  119. message: "Initialize successfully"
  120. });
  121. this.hideDialog(true);
  122. }).catch(err => {
  123. this.loading = false;
  124. this.$message({
  125. type: 'error',
  126. message: err
  127. })
  128. });
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. .dialog-ocpi {
  135. display: flex;
  136. align-items: center;
  137. flex-direction: column;
  138. justify-content: center;
  139. }
  140. .dialog-ocpi >>> .el-dialog {
  141. width: 100%;
  142. max-width: 550px;
  143. margin-top: 0 !important;
  144. }
  145. .dialog-ocpi >>> .el-dialog__body {
  146. padding: 10px 20px 30px;
  147. }
  148. .dialog-ocpi >>> .el-form {
  149. padding-right: 10px;
  150. }
  151. .form-row {
  152. display: flex;
  153. flex-wrap: wrap;
  154. padding-bottom: 5px;
  155. }
  156. .form-item {
  157. flex: 1;
  158. margin-left: 10px;
  159. /*margin-bottom: 10px; TOP*/
  160. }
  161. .form-item >>> label {
  162. /*padding: 0; TOP*/
  163. }
  164. .flex-item {
  165. width: 100%;
  166. min-width: 200px;
  167. max-width: 420px;
  168. }
  169. .flex-item ::v-deep .el-textarea__inner {
  170. font-family: sans-serif;
  171. }
  172. @media screen and (max-width: 500px) {
  173. .flex-item {
  174. width: 100%;
  175. max-width: none;
  176. }
  177. }
  178. </style>