transactions.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-form
  5. :model="filter"
  6. v-bind:inline="true"
  7. label-position="left"
  8. label-width="0px"
  9. style="width: 100%;">
  10. <div class="filter-view">
  11. <el-select
  12. class="filter-view-item"
  13. v-model="filter.pageVo.userType"
  14. placeholder="User Type"
  15. @change="changeUserType"
  16. clearable>
  17. <el-option
  18. v-for="item in userTypeOptions"
  19. :key="item"
  20. :label="item"
  21. :value="item" />
  22. </el-select>
  23. <el-select
  24. class="filter-view-item group-select"
  25. :class="{hide: groupOptions.length == 0}"
  26. v-model="filter.pageVo.groupPk"
  27. placeholder="Group Name"
  28. @change="handleFilter"
  29. clearable>
  30. <el-option
  31. v-for="(item,index) in groupOptions"
  32. :key="index"
  33. :label="item.name"
  34. :value="item.value"/>
  35. </el-select>
  36. <el-select
  37. class="filter-view-item"
  38. v-model="filter.pageVo.filter"
  39. placeholder="Charging Status"
  40. @change="handleFilter"
  41. clearable>
  42. <el-option
  43. v-for="(item, index) in filterOptions"
  44. :key="index"
  45. :label="item.name"
  46. :value="item.value"/>
  47. </el-select>
  48. <div>
  49. <el-date-picker
  50. v-model="filter.pageVo.dateRange"
  51. type="daterange"
  52. range-separator="-"
  53. start-placeholder="Start Date"
  54. end-placeholder="End Date"
  55. value-format="yyyy-MM-dd"
  56. @change="handleFilter"/>
  57. </div>
  58. <div style="flex: 1; max-width: 500px;">
  59. <el-input
  60. class="filter-view-item"
  61. v-model="filter.pageVo.criteria"
  62. prefix-icon="el-icon-search"
  63. placeholder="Search by Station ID, Vehicle, Transaction ID, Email, Carpark Code"
  64. @keyup.enter.native="handleFilter"
  65. @change="handleFilter"
  66. clearable/>
  67. </div>
  68. <!-- <div>
  69. <el-button
  70. type="primary"
  71. icon="el-icon-search"
  72. @click="handleFilter">
  73. Search
  74. </el-button>
  75. </div> -->
  76. </div>
  77. </el-form>
  78. </div>
  79. <el-table
  80. v-loading="listLoading"
  81. :data="tableList"
  82. class="no-border"
  83. style="width: 100%;min-height: 65vh;">
  84. <el-table-column
  85. min-width="120"
  86. label="Transaction ID"
  87. align="center">
  88. <template slot-scope="{row}">
  89. <span
  90. class="link-type"
  91. @click="viewTransiction(row)">
  92. {{ row.transactionPk }}
  93. </span>
  94. </template>
  95. </el-table-column>
  96. <!--el-table-column
  97. label="User ID"
  98. align="center"
  99. width="80">
  100. <template slot-scope="{row}">
  101. <span>{{ row.userPk }}</span>
  102. </template>
  103. </el-table-column-->
  104. <el-table-column
  105. label="Email"
  106. align="center"
  107. min-width="100">
  108. <template slot-scope="{row}">
  109. <span :title="row.email">{{ row.email }}</span>
  110. </template>
  111. </el-table-column>
  112. <!--el-table-column
  113. label="Phone No."
  114. align="center">
  115. <template slot-scope="{row}">
  116. <span :title="row.phoneNo">{{ row.phoneNo }}</span>
  117. </template>
  118. </el-table-column-->
  119. <el-table-column
  120. label="User Type"
  121. align="center"
  122. min-width="120">
  123. <template slot-scope="{row}">
  124. <span :title="row.userType">{{ row.userType }}</span>
  125. </template>
  126. </el-table-column>
  127. <el-table-column
  128. label="Vehicle"
  129. align="center"
  130. prop="vehicle"
  131. min-width="120">
  132. <template slot-scope="{row}" v-if="row.vehicles">
  133. <span
  134. v-for="(item, idx) in row.vehicles"
  135. :key="idx"
  136. style="display: block;"
  137. :title="item">
  138. {{item}}
  139. </span>
  140. </template>
  141. </el-table-column>
  142. <el-table-column
  143. label="Station ID"
  144. align="center"
  145. min-width="120">
  146. <template slot-scope="{row}">
  147. <div
  148. class="link-detail"
  149. @click="viewTransiction(row)"
  150. :title="row.chargeBoxId">
  151. {{ row.chargeBoxId }}
  152. </div>
  153. </template>
  154. </el-table-column>
  155. <el-table-column
  156. label="Carpark Code"
  157. prop="carParkCode"
  158. align="center"
  159. min-width="120"/>
  160. <el-table-column
  161. min-width="90"
  162. label="Connector"
  163. align="center">
  164. <template slot-scope="{row}">
  165. <span>{{ row.connectorId }}</span>
  166. </template>
  167. </el-table-column>
  168. <el-table-column
  169. label="Start Date/Time"
  170. align="center"
  171. min-width="140">
  172. <template slot-scope="{row}">
  173. <span :title="row.startDateTime">{{ row.startDateTime }}</span>
  174. </template>
  175. </el-table-column>
  176. <el-table-column
  177. label="End Date/Time"
  178. align="center"
  179. min-width="140">
  180. <template slot-scope="{row}">
  181. <span :title="row.endDateTime">{{ row.endDateTime }}</span>
  182. </template>
  183. </el-table-column>
  184. <el-table-column
  185. label="Power"
  186. align="center"
  187. min-width="120">
  188. <template slot-scope="{row}">
  189. <span :title="row.power">{{ row.power }}</span>
  190. </template>
  191. </el-table-column>
  192. <el-table-column
  193. label="Rate"
  194. align="center"
  195. min-width="150">
  196. <template slot-scope="{row}" v-if="row.rates">
  197. <span
  198. v-for="(item, idx) in row.rates"
  199. :key="idx"
  200. style="display: block;"
  201. :title="item">
  202. {{item}}
  203. </span>
  204. </template>
  205. </el-table-column>
  206. <el-table-column
  207. label="Duration"
  208. align="center"
  209. min-width="100">
  210. <template slot-scope="{row}">
  211. <span :title="row.totalHour">{{ row.totalHour }}</span>
  212. </template>
  213. </el-table-column>
  214. <el-table-column
  215. label="Total Min"
  216. align="center"
  217. min-width="100">
  218. <template slot-scope="{row}">
  219. <span :title="row.totalMin">{{ row.totalMin }}</span>
  220. </template>
  221. </el-table-column>
  222. <el-table-column
  223. label="Charges"
  224. align="center"
  225. min-width="100">
  226. <template slot-scope="{row}">
  227. <span :title="row.charges">{{ row.charges }}</span>
  228. </template>
  229. </el-table-column>
  230. <!-- <el-table-column
  231. label="Invoice"
  232. align="center"
  233. min-width="80">
  234. <template slot-scope="{row}">
  235. <i
  236. class="download-invoice el-icon-download"
  237. title="Download"
  238. @click="downloadPdf(row.transactionPk)"></i>
  239. </template>
  240. </el-table-column> -->
  241. </el-table>
  242. <div class="right">
  243. <pagination
  244. v-show="total > 0"
  245. :total="total"
  246. :page.sync="filter.pageNo"
  247. :limit.sync="filter.pageSize"
  248. @pagination="getList" />
  249. </div>
  250. </div>
  251. </template>
  252. <script>
  253. import Pagination from '@/components/Pagination'
  254. import api from '../../http/api/transaction'
  255. import apiUser from '../../http/api/apiUser.js'
  256. export default {
  257. components: { Pagination },
  258. data() {
  259. return {
  260. filter: {
  261. pageNo: 1,
  262. pageSize: 10,
  263. pageVo: {
  264. filter: "",
  265. groupPk: "",
  266. criteria: "",
  267. userType: "",
  268. dateRange: [],
  269. }
  270. },
  271. groupOptions: [],
  272. filterOptions: [],
  273. userTypeOptions: [],
  274. listLoading: true,
  275. tableList: [],
  276. total: 0,
  277. listQuery: {
  278. page: 1,
  279. limit: 10,
  280. }
  281. }
  282. },
  283. created() {
  284. this.getFilters();
  285. this.getUserTypeOption();
  286. this.handleFilter();
  287. },
  288. methods: {
  289. handleFilter() {
  290. this.filter.pageNo = 1;
  291. this.getList();
  292. },
  293. getFilters() {
  294. api.getTransactionFilters().then(res => {
  295. if (res.data) {
  296. this.filterOptions = res.data
  297. this.filter.pageVo.filter = res.data[0].value
  298. this.getList()
  299. } else {
  300. this.$message({
  301. message: error,
  302. type: 'error'
  303. })
  304. }
  305. })
  306. },
  307. changeUserType() {
  308. this.filter.pageVo.groupPk = "";
  309. this.getGroupOptions();
  310. },
  311. getGroupOptions() {
  312. if (this.filter.pageVo.userType == "") {
  313. this.groupOptions = [];
  314. return;
  315. }
  316. this.listLoading = true;
  317. apiUser.getGroupByType(this.filter.pageVo.userType).then(res => {
  318. if (res.data) {
  319. this.groupOptions = res.data
  320. } else {
  321. this.groupOptions = []
  322. }
  323. }).catch(err => {
  324. this.$message({
  325. message: err,
  326. type: 'error'
  327. })
  328. this.groupOptions = []
  329. }).finally(() => {
  330. setTimeout(() => {
  331. this.getList();
  332. }, 100)
  333. })
  334. },
  335. getUserTypeOption() {
  336. apiUser.getUserTypeOptions().then(res => {
  337. if (res.data) {
  338. this.userTypeOptions = res.data
  339. }
  340. }).catch(err => {
  341. this.$message({
  342. message: error,
  343. type: 'error'
  344. })
  345. })
  346. },
  347. async getList() {
  348. this.listLoading = true;
  349. api.getTransactionPages(this.filter).then(res => {
  350. if (res.data && res.total) {
  351. this.tableList = res.data
  352. this.total = res.total
  353. } else {
  354. this.tableList = []
  355. this.total = 0
  356. }
  357. }).catch(err => {
  358. this.$message({
  359. type: "error",
  360. message: err
  361. })
  362. this.tableList = []
  363. this.total = 0
  364. }).finally(() => {
  365. this.listLoading = false
  366. })
  367. },
  368. async downloadPdf(id) {
  369. try {
  370. this.listLoading = true;
  371. const res = await api.downloadInvoice(id);
  372. if (res && res.size > 0) {
  373. const name = 'T' + id + '-' + new Date().getTime() + '.pdf'
  374. this.downloadFile(res, name);
  375. } else {
  376. this.$message.error('Empty files');
  377. }
  378. } catch (err) {
  379. } finally {
  380. this.listLoading = false;
  381. }
  382. },
  383. downloadFile(res, fileName) {
  384. const blob = new Blob([res], {
  385. type: 'application/pdf;charset=utf-8'
  386. })
  387. // let href = window.URL.createObjectURL(blob)
  388. if ('download' in document.createElement('a')) {
  389. // 非IE下载
  390. const elink = document.createElement('a')
  391. elink.download = fileName
  392. elink.style.display = 'none'
  393. elink.href = URL.createObjectURL(blob)
  394. document.body.appendChild(elink)
  395. elink.click()
  396. URL.revokeObjectURL(elink.href) // 释放URL 对象
  397. document.body.removeChild(elink)
  398. } else {
  399. // IE10+下载
  400. navigator.msSaveBlob(blob, fileName)
  401. }
  402. },
  403. viewTransiction(row) {
  404. this.$router.push({
  405. path: "/station-activities/transactions/" + row.transactionPk
  406. })
  407. }
  408. }
  409. }
  410. </script>
  411. <style scoped="scoped">
  412. .table-link {
  413. color: #333;
  414. display: inline-block;
  415. cursor: pointer;
  416. white-space: nowrap;
  417. text-decoration: underline;
  418. }
  419. .table-link:hover {
  420. color: #1290BF;
  421. text-decoration: none;
  422. }
  423. .el-table >>> tr div {
  424. word-break: break-word;
  425. }
  426. .download-invoice {
  427. color: #0000FF;
  428. cursor: pointer;
  429. }
  430. .group-select {
  431. overflow: hidden;
  432. transition: all .3s;
  433. }
  434. .group-select.hide {
  435. margin: 0;
  436. min-width: 0;
  437. max-width: 0;
  438. }
  439. </style>