view_transaction_v2.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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.chargingStartTime"
  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.chargingStopTime"
  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.chargeBoxId"
  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. <el-input
  95. class="add-text"
  96. v-model="details.duration"
  97. readonly/>
  98. </el-form-item>
  99. </el-col>
  100. <el-col :xs="24" :md="12" v-if="details.rate">
  101. <el-form-item
  102. label="Rate:">
  103. <div
  104. v-if="details.rate.rateItems"
  105. class="link-detail"
  106. @click="showRatesDrawer">View {{details.rate.rateItems.length}} Rates</div>
  107. </el-form-item>
  108. </el-col>
  109. </el-row>
  110. <el-row :gutter="20">
  111. <el-col :xs="24" :md="12">
  112. <el-form-item
  113. label="Total Power:">
  114. <el-input
  115. class="add-text"
  116. v-model="details.totalPowerStr"
  117. readonly/>
  118. </el-form-item>
  119. </el-col>
  120. <el-col :xs="24" :md="12">
  121. <el-form-item
  122. label="Charges:">
  123. <el-input
  124. class="add-text"
  125. v-model="details.charge"
  126. readonly/>
  127. </el-form-item>
  128. </el-col>
  129. </el-row>
  130. <div class="flexcr" style="margin: 10px 0;">
  131. <div class="section-title" style="margin: 20px 0;">Intermediate Meter Values</div>
  132. <el-button
  133. type="primary"
  134. style="margin: 0 10px;"
  135. v-if="!details.chargingStopTime || !details.totalPower"
  136. @click="onClickEnd"
  137. icon="el-icon-switch-button"
  138. :loading="endLoading">
  139. End Transaction
  140. </el-button>
  141. <el-button
  142. v-else-if="false"
  143. type="primary"
  144. style="margin: 0 10px;"
  145. icon="el-icon-download"
  146. @click="downloadInvoice"
  147. :loading="endLoading">
  148. Download Invoice
  149. </el-button>
  150. <div class="flex1"></div>
  151. <el-select v-model="measurand" @change="getDeatil">
  152. <el-option
  153. value=""
  154. label="All"/>
  155. <el-option
  156. v-for="(item, index) in optionsMeasurand"
  157. :key="index"
  158. :value="item"
  159. :label="item"/>
  160. </el-select>
  161. </div>
  162. <el-table :data="listData">
  163. <el-table-column
  164. label="Timestamp"
  165. align="center"
  166. class-name="fixed-width"
  167. min-width="130">
  168. <template slot-scope="{row}">
  169. <span>{{ row.timestamp }}</span>
  170. </template>
  171. </el-table-column>
  172. <el-table-column
  173. label="Value"
  174. align="center"
  175. min-width="80">
  176. <template slot-scope="{row}">
  177. <span>{{ row.value }}</span>
  178. </template>
  179. </el-table-column>
  180. <el-table-column
  181. label="Reading Context"
  182. align="center"
  183. class-name="fixed-width"
  184. min-width="130">
  185. <template slot-scope="{row}">
  186. <span>{{ row.readingContext }}</span>
  187. </template>
  188. </el-table-column>
  189. <el-table-column
  190. label="Format"
  191. align="center"
  192. min-width="100">
  193. <template slot-scope="{row}">
  194. <span>{{ row.format }}</span>
  195. </template>
  196. </el-table-column>
  197. <el-table-column
  198. label="Measureand"
  199. align="center"
  200. class-name="fixed-width"
  201. min-width="250">
  202. <template slot-scope="{row}">
  203. <span>{{ row.measureand }}</span>
  204. </template>
  205. </el-table-column>
  206. <el-table-column
  207. label="Location"
  208. align="center"
  209. min-width="100">
  210. <template slot-scope="{row}">
  211. <span>{{ row.location }}</span>
  212. </template>
  213. </el-table-column>
  214. <el-table-column
  215. label="Unit"
  216. align="center"
  217. min-width="80">
  218. <template slot-scope="{row}">
  219. <span>{{ row.unit }}</span>
  220. </template>
  221. </el-table-column>
  222. <el-table-column
  223. label="Phase"
  224. align="center"
  225. min-width="80">
  226. <template slot-scope="{row}">
  227. <span>{{ row.phase }}</span>
  228. </template>
  229. </el-table-column>
  230. </el-table>
  231. <div class="pagination" v-if="listData">
  232. <Pagination
  233. v-show="details.meters.length > 0"
  234. :total="details.meters.length"
  235. :page.sync="page"
  236. :limit.sync="pageSize"
  237. :autoScroll="false"
  238. @pagination="handlePageChange" />
  239. </div>
  240. </el-form>
  241. </div>
  242. <el-drawer
  243. :visible.sync="drawerRate"
  244. direction="rtl">
  245. <el-timeline>
  246. <el-timeline-item
  247. v-for="(item, index) in details.rate.rateItems"
  248. size="large"
  249. :key="index"
  250. hide-timestamp>
  251. <div>
  252. <div
  253. class="rate-unit-text"
  254. v-if="details.rate.hasDiscount">
  255. <span>Rate: {{item.discountRate}}</span>
  256. <span class="rate-unit-discount">{{item.withoutDiscountRate}}</span>
  257. </div>
  258. <div
  259. class="rate-unit-text"
  260. v-else>Rate: {{item.discountRate}}</div>
  261. <div class="rate-date-text">Start: {{item.startTime}}</div>
  262. <div class="rate-date-text">&nbsp;End: {{item.endTime}}</div>
  263. </div>
  264. </el-timeline-item>
  265. </el-timeline>
  266. </el-drawer>
  267. </div>
  268. </template>
  269. <script>
  270. import Pagination from '@/components/Pagination'
  271. import api from '../../http/api/transaction'
  272. export default {
  273. components: { Pagination },
  274. data() {
  275. return {
  276. page: 1,
  277. pageSize: 10,
  278. details: {},
  279. listData: [],
  280. loading: false,
  281. measurand: "",
  282. endLoading: false,
  283. drawerRate: false,
  284. optionsMeasurand: []
  285. }
  286. },
  287. created() {
  288. this.getMeasuOptions()
  289. this.getDeatil()
  290. },
  291. methods: {
  292. getMeasuOptions() {
  293. api.getMeasurandOptions().then(res => {
  294. if (res.data) {
  295. this.optionsMeasurand = res.data
  296. }
  297. }).catch(err => {
  298. })
  299. },
  300. getDeatil() {
  301. this.loading = true;
  302. api.getTransactionDetailV2({
  303. chargingPk: this.$route.params.id,
  304. measurand: this.measurand
  305. }).then(res => {
  306. if (res.data) {
  307. this.details = res.data
  308. /*if (this.details.duration) {
  309. this.details.duration = Number((this.details.duration * 60).toFixed(2))
  310. }*/
  311. if (this.details.meters && this.details.meters.length) {
  312. this.handlePageChange()
  313. } else {
  314. this.listData = []
  315. }
  316. }
  317. }).catch(err => {
  318. this.$message({
  319. type: 'error',
  320. message: err
  321. })
  322. }).finally(() => {
  323. this.loading = false
  324. })
  325. },
  326. onClickEnd() {
  327. this.$confirm('This operation only for settling abnormal transactions and will not end charging. Select Confirm to proceed.', 'Warning', {
  328. confirmButtonText: 'Confirm',
  329. cancelButtonText: 'Cancel',
  330. type: 'warning'
  331. }).then(res => {
  332. this.endTransaction();
  333. })
  334. },
  335. endTransaction() {
  336. this.endLoading = true;
  337. api.endTransactionV2({
  338. transactionPk: this.details.transactionPk
  339. }).then(res => {
  340. this.$message({
  341. type: 'success',
  342. message: 'Operation Successfully!'
  343. })
  344. this.getDeatil()
  345. }).catch(err => {
  346. this.$message({
  347. type: 'error',
  348. message: err
  349. })
  350. }).finally(() => {
  351. this.endLoading = false
  352. })
  353. },
  354. downloadInvoice() {
  355. this.endLoading = true;
  356. api.downloadInvoice(this.$route.params.id).then(res => {
  357. if (res && res.size > 0) {
  358. const name = 'T' + this.$route.params.id + '-' + new Date().getTime() + '.pdf'
  359. this.downloadFile(res, name);
  360. } else {
  361. this.$message.error('Empty files');
  362. }
  363. }).catch(err => {
  364. this.$message({
  365. type: 'error',
  366. message: err
  367. })
  368. }).finally(() => {
  369. this.endLoading = false
  370. })
  371. },
  372. downloadFile(res, fileName) {
  373. const blob = new Blob([res], {
  374. type: 'application/pdf;charset=utf-8'
  375. })
  376. // let href = window.URL.createObjectURL(blob)
  377. if ('download' in document.createElement('a')) {
  378. // 非IE下载
  379. const elink = document.createElement('a')
  380. elink.download = fileName
  381. elink.style.display = 'none'
  382. elink.href = URL.createObjectURL(blob)
  383. document.body.appendChild(elink)
  384. elink.click()
  385. URL.revokeObjectURL(elink.href) // 释放URL 对象
  386. document.body.removeChild(elink)
  387. } else {
  388. // IE10+下载
  389. navigator.msSaveBlob(blob, fileName)
  390. }
  391. },
  392. handlePageChange() {
  393. this.listData = []
  394. var i = (this.page - 1) * this.pageSize
  395. var max = this.page * this.pageSize
  396. if (max > this.details.meters.length)
  397. max = this.details.meters.length
  398. for (i; i < max; i++) {
  399. this.listData.push(this.details.meters[i])
  400. }
  401. },
  402. showRatesDrawer() {
  403. this.drawerRate = true;
  404. }
  405. }
  406. }
  407. </script>
  408. <style scoped="scoped" lang='scss'>
  409. @import '../../styles/variables.scss';
  410. .card-container {
  411. width: 100%;
  412. padding: 20px 60px;
  413. min-height: $mainAppMinHeight;
  414. background-color: #F0F5FC;
  415. }
  416. .card-content {
  417. padding: 15px 80px;
  418. border-radius: 6px;
  419. background-color: white;
  420. }
  421. .section-title {
  422. color: #333;
  423. margin-top: 20px;
  424. margin-bottom: 30px;
  425. font-size: 16px;
  426. user-select: none;
  427. line-height: 24px;
  428. font-weight: 500;
  429. font-family: sans-serif;
  430. text-transform: uppercase;
  431. }
  432. .add-text {
  433. width: 100%;
  434. max-width: 300px;
  435. }
  436. .add-text ::v-deep .el-textarea__inner {
  437. font-family: sans-serif;
  438. }
  439. .hr {
  440. height: 2px;
  441. margin: 10px -40px;
  442. background-color: #F0F5FC;
  443. }
  444. .hr-full {
  445. height: 2px;
  446. margin: 20px -80px;
  447. background-color: #F0F5FC;
  448. }
  449. .rate-list-view {
  450. display: flex;
  451. flex-wrap: wrap;
  452. align-items: center;
  453. }
  454. .rate-text {
  455. max-width: 150px;
  456. padding-right: 14px;
  457. }
  458. .list-item-icon {
  459. width: 30px;
  460. height: 30px;
  461. cursor: pointer;
  462. margin: 0 10px 22px;
  463. }
  464. .buttons {
  465. padding-top: 15px;
  466. padding-bottom: 30px;
  467. }
  468. @media screen and (max-width: 500px) {
  469. .card-container {
  470. padding: 0px;
  471. }
  472. .card-content {
  473. padding: 15px 40px;
  474. }
  475. }
  476. .form-unit ::v-deep .el-form-item__label {
  477. line-height: 30px;
  478. }
  479. .item-unit {
  480. top: 12px;
  481. left: -130px;
  482. font-size: 12px;
  483. position: absolute;
  484. }
  485. .el-table ::v-deep tr div {
  486. font-size: 12px;
  487. white-space: nowrap;
  488. }
  489. .pagination {
  490. width: 100%;
  491. text-align: right;
  492. overflow-x: auto;
  493. }
  494. .rate-date-text {
  495. color: #666;
  496. font-size: 12px;
  497. padding-top: 2px;
  498. }
  499. .rate-unit-text {
  500. color: #000;
  501. font-size: 15px;
  502. font-weight: 600;
  503. padding-top: 2px;
  504. padding-bottom: 5px;
  505. }
  506. .rate-unit-discount {
  507. color: #666;
  508. font-size: 14px;
  509. padding-left: 8px;
  510. font-weight: normal;
  511. text-decoration: line-through;
  512. }
  513. </style>