view_transaction.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div class="card-container">
  3. <div class="card-content">
  4. <el-form
  5. v-loading="loading"
  6. label-width="130px"
  7. label-position="left">
  8. <div class="section-title">Transaction Overview</div>
  9. <el-row :gutter="20">
  10. <el-col :xs="24" :md="12">
  11. <el-form-item
  12. label="Transaction ID:">
  13. <el-input
  14. class="add-text"
  15. v-model="details.transactionPk"
  16. readonly/>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :xs="24" :md="12">
  20. <el-form-item
  21. label="Start Date/Time:">
  22. <el-input
  23. class="add-text"
  24. v-model="details.startDateTime"
  25. readonly/>
  26. </el-form-item>
  27. </el-col>
  28. </el-row>
  29. <el-row :gutter="20">
  30. <el-col :xs="24" :md="12">
  31. <el-form-item
  32. label="User Id:">
  33. <el-input
  34. class="add-text"
  35. v-model="details.userPk"
  36. readonly/>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :xs="24" :md="12">
  40. <el-form-item
  41. label="End Date/Time:">
  42. <el-input
  43. class="add-text"
  44. v-model="details.endDateTime"
  45. readonly/>
  46. </el-form-item>
  47. </el-col>
  48. </el-row>
  49. <el-row :gutter="20">
  50. <el-col :xs="24" :md="12">
  51. <el-form-item
  52. label="Station ID:">
  53. <el-input
  54. class="add-text"
  55. v-model="details.stationId"
  56. readonly/>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :xs="24" :md="12">
  60. <el-form-item
  61. label="Stop Reason:">
  62. <el-input
  63. class="add-text"
  64. v-model="details.stopReason"
  65. readonly/>
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. <el-row :gutter="20">
  70. <el-col :xs="24" :md="12">
  71. <el-form-item
  72. label="Connector ID:">
  73. <el-input
  74. class="add-text"
  75. v-model="details.connectorId"
  76. readonly/>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :xs="24" :md="12">
  80. <el-form-item
  81. label="Stop Event Actor:">
  82. <el-input
  83. class="add-text"
  84. v-model="details.stopEventActor"
  85. readonly/>
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. <div class="section-title">Charges</div>
  90. <el-row :gutter="20">
  91. <el-col :xs="24" :md="12">
  92. <el-form-item
  93. label="Duration:"
  94. class="form-unit">
  95. <span class="item-unit">(minute)</span>
  96. <el-input
  97. class="add-text"
  98. v-model="details.duration"
  99. readonly/>
  100. </el-form-item>
  101. </el-col>
  102. <el-col :xs="24" :md="12">
  103. <el-form-item
  104. label="Rate:">
  105. <el-input
  106. class="add-text"
  107. v-model="details.rate"
  108. readonly/>
  109. </el-form-item>
  110. </el-col>
  111. </el-row>
  112. <el-row :gutter="20">
  113. <el-col :xs="24" :md="12">
  114. <el-form-item
  115. label="Total Power:"
  116. class="form-unit">
  117. <span class="item-unit">(kWh)</span>
  118. <el-input
  119. class="add-text"
  120. v-model="details.totalPower"
  121. readonly/>
  122. </el-form-item>
  123. </el-col>
  124. <el-col :xs="24" :md="12">
  125. <el-form-item
  126. label="Charges:">
  127. <el-input
  128. class="add-text"
  129. v-model="details.charges"
  130. readonly/>
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <div class="flexcr" style="margin: 10px 0;">
  135. <div class="section-title" style="margin: 20px 0;">Intermediate Meter Values</div>
  136. <el-button
  137. type="primary"
  138. style="margin: 0 10px;"
  139. v-if="!details.endDateTime"
  140. @click="onClickEnd"
  141. :loading="endLoading">
  142. End Transaction
  143. </el-button>
  144. <el-button
  145. v-else
  146. type="primary"
  147. style="margin: 0 10px;"
  148. icon="el-icon-download"
  149. @click="downloadInvoice"
  150. :loading="endLoading">
  151. Download Invoice
  152. </el-button>
  153. <div class="flex1"></div>
  154. <el-select v-model="measurand" @change="getDeatil">
  155. <el-option
  156. value=""
  157. label="All"/>
  158. <el-option
  159. v-for="(item, index) in optionsMeasurand"
  160. :key="index"
  161. :value="item"
  162. :label="item"/>
  163. </el-select>
  164. </div>
  165. <el-table :data="listData">
  166. <el-table-column
  167. label="Timestamp"
  168. align="center"
  169. class-name="fixed-width"
  170. min-width="130">
  171. <template slot-scope="{row}">
  172. <span>{{ row.timestamp }}</span>
  173. </template>
  174. </el-table-column>
  175. <el-table-column
  176. label="Value"
  177. align="center"
  178. min-width="80">
  179. <template slot-scope="{row}">
  180. <span>{{ row.value }}</span>
  181. </template>
  182. </el-table-column>
  183. <el-table-column
  184. label="Reading Context"
  185. align="center"
  186. class-name="fixed-width"
  187. min-width="130">
  188. <template slot-scope="{row}">
  189. <span>{{ row.readingContext }}</span>
  190. </template>
  191. </el-table-column>
  192. <el-table-column
  193. label="Format"
  194. align="center"
  195. min-width="100">
  196. <template slot-scope="{row}">
  197. <span>{{ row.format }}</span>
  198. </template>
  199. </el-table-column>
  200. <el-table-column
  201. label="Measureand"
  202. align="center"
  203. class-name="fixed-width"
  204. min-width="250">
  205. <template slot-scope="{row}">
  206. <span>{{ row.measureand }}</span>
  207. </template>
  208. </el-table-column>
  209. <el-table-column
  210. label="Location"
  211. align="center"
  212. min-width="100">
  213. <template slot-scope="{row}">
  214. <span>{{ row.location }}</span>
  215. </template>
  216. </el-table-column>
  217. <el-table-column
  218. label="Unit"
  219. align="center"
  220. min-width="80">
  221. <template slot-scope="{row}">
  222. <span>{{ row.unit }}</span>
  223. </template>
  224. </el-table-column>
  225. <el-table-column
  226. label="Phase"
  227. align="center"
  228. min-width="80">
  229. <template slot-scope="{row}">
  230. <span>{{ row.phase }}</span>
  231. </template>
  232. </el-table-column>
  233. </el-table>
  234. <div class="pagination" v-if="details.transactionMeters">
  235. <Pagination
  236. v-show="details.transactionMeters.length > 0"
  237. :total="details.transactionMeters.length"
  238. :page.sync="page"
  239. :limit.sync="pageSize"
  240. :autoScroll="false"
  241. @pagination="handlePageChange" />
  242. </div>
  243. </el-form>
  244. </div>
  245. </div>
  246. </template>
  247. <script>
  248. import Pagination from '@/components/Pagination'
  249. import api from '../../http/api/transaction'
  250. export default {
  251. components: { Pagination },
  252. data() {
  253. return {
  254. page: 1,
  255. pageSize: 10,
  256. details: {},
  257. listData: [],
  258. loading: false,
  259. measurand: "",
  260. endLoading: false,
  261. optionsMeasurand: []
  262. }
  263. },
  264. created() {
  265. this.getMeasuOptions()
  266. this.getDeatil()
  267. },
  268. methods: {
  269. getMeasuOptions() {
  270. api.getMeasurandOptions().then(res => {
  271. if (res.data) {
  272. this.optionsMeasurand = res.data
  273. }
  274. }).catch(err => {
  275. })
  276. },
  277. getDeatil() {
  278. this.loading = true;
  279. api.getTransactionDetail({
  280. transactionPk: this.$route.params.id,
  281. measurand: this.measurand
  282. }).then(res => {
  283. if (res.data) {
  284. this.details = res.data
  285. if (this.details.duration) {
  286. this.details.duration = Number((this.details.duration * 60).toFixed(2))
  287. }
  288. if (this.details.transactionMeters && this.details.transactionMeters.length) {
  289. this.handlePageChange()
  290. } else {
  291. this.listData = []
  292. }
  293. }
  294. }).catch(err => {
  295. this.$message({
  296. type: 'error',
  297. message: err
  298. })
  299. }).finally(() => {
  300. this.loading = false
  301. })
  302. },
  303. onClickEnd() {
  304. this.$confirm('This operation only for settling abnormal transactions and will not end charging. Select Confirm to proceed.', 'Warning', {
  305. confirmButtonText: 'Confirm',
  306. cancelButtonText: 'Cancel',
  307. type: 'warning'
  308. }).then(res => {
  309. this.endTransaction();
  310. })
  311. },
  312. endTransaction() {
  313. this.endLoading = true;
  314. api.endTransaction({
  315. transactionPk: this.$route.params.id
  316. }).then(res => {
  317. this.$message({
  318. type: 'success',
  319. message: 'Operation Successfully!'
  320. })
  321. this.getDeatil()
  322. }).catch(err => {
  323. this.$message({
  324. type: 'error',
  325. message: err
  326. })
  327. }).finally(() => {
  328. this.endLoading = false
  329. })
  330. },
  331. downloadInvoice() {
  332. this.endLoading = true;
  333. api.downloadInvoice(this.$route.params.id).then(res => {
  334. if (res && res.size > 0) {
  335. const name = 'T' + this.$route.params.id + '-' + new Date().getTime() + '.pdf'
  336. this.downloadFile(res, name);
  337. } else {
  338. this.$message.error('Empty files');
  339. }
  340. }).catch(err => {
  341. this.$message({
  342. type: 'error',
  343. message: err
  344. })
  345. }).finally(() => {
  346. this.endLoading = false
  347. })
  348. },
  349. downloadFile(res, fileName) {
  350. const blob = new Blob([res], {
  351. type: 'application/pdf;charset=utf-8'
  352. })
  353. // let href = window.URL.createObjectURL(blob)
  354. if ('download' in document.createElement('a')) {
  355. // 非IE下载
  356. const elink = document.createElement('a')
  357. elink.download = fileName
  358. elink.style.display = 'none'
  359. elink.href = URL.createObjectURL(blob)
  360. document.body.appendChild(elink)
  361. elink.click()
  362. URL.revokeObjectURL(elink.href) // 释放URL 对象
  363. document.body.removeChild(elink)
  364. } else {
  365. // IE10+下载
  366. navigator.msSaveBlob(blob, fileName)
  367. }
  368. },
  369. handlePageChange() {
  370. this.listData = []
  371. var i = (this.page - 1) * this.pageSize
  372. var max = this.page * this.pageSize
  373. if (max > this.details.transactionMeters.length)
  374. max = this.details.transactionMeters.length
  375. for (i; i < max; i++) {
  376. this.listData.push(this.details.transactionMeters[i])
  377. }
  378. }
  379. }
  380. }
  381. </script>
  382. <style scoped="scoped" lang='scss'>
  383. @import '../../styles/variables.scss';
  384. .card-container {
  385. width: 100%;
  386. padding: 20px 60px;
  387. min-height: $mainAppMinHeight;
  388. background-color: #F0F5FC;
  389. }
  390. .card-content {
  391. padding: 15px 80px;
  392. border-radius: 6px;
  393. background-color: white;
  394. }
  395. .section-title {
  396. color: #333;
  397. margin-top: 20px;
  398. margin-bottom: 30px;
  399. font-size: 16px;
  400. user-select: none;
  401. line-height: 24px;
  402. font-weight: 500;
  403. font-family: sans-serif;
  404. text-transform: uppercase;
  405. }
  406. .add-text {
  407. width: 100%;
  408. max-width: 300px;
  409. }
  410. .add-text ::v-deep .el-textarea__inner {
  411. font-family: sans-serif;
  412. }
  413. .hr {
  414. height: 2px;
  415. margin: 10px -40px;
  416. background-color: #F0F5FC;
  417. }
  418. .hr-full {
  419. height: 2px;
  420. margin: 20px -80px;
  421. background-color: #F0F5FC;
  422. }
  423. .rate-list-view {
  424. display: flex;
  425. flex-wrap: wrap;
  426. align-items: center;
  427. }
  428. .rate-text {
  429. max-width: 150px;
  430. padding-right: 14px;
  431. }
  432. .list-item-icon {
  433. width: 30px;
  434. height: 30px;
  435. cursor: pointer;
  436. margin: 0 10px 22px;
  437. }
  438. .buttons {
  439. padding-top: 15px;
  440. padding-bottom: 30px;
  441. }
  442. @media screen and (max-width: 500px) {
  443. .card-container {
  444. padding: 0px;
  445. }
  446. .card-content {
  447. padding: 15px 40px;
  448. }
  449. }
  450. .form-unit ::v-deep .el-form-item__label {
  451. line-height: 30px;
  452. }
  453. .item-unit {
  454. top: 12px;
  455. left: -130px;
  456. font-size: 12px;
  457. position: absolute;
  458. }
  459. .el-table ::v-deep tr div {
  460. font-size: 12px;
  461. white-space: nowrap;
  462. }
  463. .pagination {
  464. width: 100%;
  465. text-align: right;
  466. overflow-x: auto;
  467. }
  468. </style>