OverwriteOCPI.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <el-dialog
  3. :visible="visible"
  4. :before-close="e => hideDialog()"
  5. title="Manual Overwrite"
  6. custom-class="overwrite-ocpi-dialog">
  7. <el-form
  8. ref="form"
  9. :model="form"
  10. :rules="rules"
  11. label-position="right"
  12. label-width="240px">
  13. <el-form-item
  14. label="Charge Box ID:">
  15. <el-input
  16. v-model="item.chargeBoxId"
  17. class="flex-item"
  18. readonly
  19. style="max-width: 320px;"/>
  20. </el-form-item>
  21. <el-form-item
  22. label="Connector ID:">
  23. <el-input
  24. v-model="item.connectorId"
  25. class="flex-item"
  26. readonly
  27. style="max-width: 320px;"/>
  28. </el-form-item>
  29. <el-form-item
  30. label="Current OCPP Status:"
  31. prop="transactionId">
  32. <el-input
  33. v-model="form.currentOcppStatus"
  34. class="flex-item"
  35. readonly
  36. style="max-width: 320px;"/>
  37. </el-form-item>
  38. <el-form-item
  39. label="Current OCPI Status:"
  40. prop="transactionId">
  41. <el-input
  42. v-model="form.currentOcpiStatus"
  43. class="flex-item"
  44. readonly
  45. style="max-width: 320px;"/>
  46. </el-form-item>
  47. <el-form-item
  48. label="Target OCPI Status:"
  49. prop="latestOcpiStatus">
  50. <el-select
  51. v-model="form.latestOcpiStatus"
  52. class="flex-item"
  53. style="max-width: 320px;">
  54. <el-option
  55. v-for="(item, index) in options.status"
  56. :key="index"
  57. :label="item"
  58. :value="item"/>
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item
  62. label="TTL / Expected Recovery Time:"
  63. prop="latestOcpiStatusExpireTime">
  64. <el-date-picker
  65. v-model="form.latestOcpiStatusExpireTime"
  66. class="flex-item"
  67. type="datetime"
  68. format="yyyy-MM-dd HH:mm"
  69. value-format="yyyy-MM-dd HH:mm"
  70. style="width: 100%; max-width: 320px;"
  71. :picker-options="pickerOptions"/>
  72. </el-form-item>
  73. <el-form-item
  74. label="Action Reason:"
  75. prop="actionReason">
  76. <el-input
  77. v-model="form.actionReason"
  78. class="flex-item"
  79. :autosize="autosize"
  80. maxlength="5000"
  81. type="textarea"
  82. style="max-width: 320px;"/>
  83. </el-form-item>
  84. <div class="center buttons">
  85. <el-button
  86. type="primary"
  87. class="cancel-button"
  88. @click="hideDialog()">
  89. Back
  90. </el-button>
  91. <el-button
  92. @click="onClickSave"
  93. type="primary"
  94. :loading="loading.save">
  95. &nbsp;Save&nbsp;
  96. </el-button>
  97. </div>
  98. </el-form>
  99. </el-dialog>
  100. </template>
  101. <script>
  102. import api from '../../../http/api/charge'
  103. export default {
  104. name: "DialogOverwriteOCPI",
  105. props: {
  106. visible: {
  107. type: Boolean,
  108. default: false
  109. },
  110. item: {
  111. type: Object,
  112. default: () => ({})
  113. }
  114. },
  115. data() {
  116. return {
  117. loading: {
  118. save: false
  119. },
  120. form: {
  121. connectorPk: "",
  122. currentOcppStatus: "",
  123. currentOcpiStatus: "",
  124. latestOcpiStatus: "",
  125. latestOcpiStatusExpireTime: "",
  126. actionReason: ""
  127. },
  128. rules: {
  129. latestOcpiStatus: {
  130. required: true,
  131. trigger: 'change',
  132. message: 'Please select status'
  133. },
  134. latestOcpiStatusExpireTime: {
  135. required: true,
  136. trigger: 'change',
  137. message: 'Please select date time'
  138. },
  139. actionReason: {
  140. required: true,
  141. trigger: 'blur',
  142. message: 'Please input action reason'
  143. }
  144. },
  145. options: {
  146. status: []
  147. },
  148. autosize: {
  149. minRows: 3,
  150. maxRows: 10,
  151. },
  152. pickerOptions: {
  153. disabledDate: time => {
  154. return time.getTime() < new Date().setHours(0, 0, 0, 0);
  155. }
  156. }
  157. };
  158. },
  159. mounted() {
  160. this.getStatusOptions();
  161. },
  162. watch: {
  163. item: {
  164. immediate: true,
  165. handler(value) {
  166. if (value) {
  167. this.form.connectorPk = this.item.connectorPk;
  168. this.form.currentOcpiStatus = this.item.ocpiStatus;
  169. this.form.currentOcppStatus = this.item.status;
  170. }
  171. }
  172. },
  173. },
  174. methods: {
  175. hideDialog(success) {
  176. this.$emit("hide", success || false);
  177. this.form.latestOcpiStatus = "";
  178. this.form.latestOcpiStatusExpireTime = "";
  179. this.form.actionReason = "";
  180. this.$nextTick(() => {
  181. this.$refs['form'].clearValidate();
  182. })
  183. },
  184. getStatusOptions() {
  185. api.getOCPIStatusOptions().then(res => {
  186. if (res.data) {
  187. this.options.status = res.data
  188. }
  189. }).catch(err => {
  190. })
  191. },
  192. onClickSave() {
  193. this.$refs['form'].validate(result => {
  194. if (result) {
  195. this.manualOverwrite()
  196. }
  197. })
  198. },
  199. manualOverwrite() {
  200. this.loading.save = true;
  201. api.overwriteOCPIStatus(this.form).then(res => {
  202. this.loading.save = false;
  203. this.$message({
  204. message: 'Overwrite successfully',
  205. type: 'success'
  206. })
  207. this.hideDialog(true);
  208. }).catch(err => {
  209. this.loading.save = false;
  210. this.$message({
  211. type: 'error',
  212. message: err
  213. })
  214. });
  215. }
  216. },
  217. }
  218. </script>
  219. <style scoped>
  220. >>> .overwrite-ocpi-dialog {
  221. max-width: 620px;
  222. }
  223. </style>