Reports.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div class="view-container">
  3. <div
  4. class="view-content"
  5. v-loading="loading">
  6. <div class="section-title">Report</div>
  7. <el-form
  8. label-width="130px"
  9. :model="reportFilter">
  10. <div class="row">
  11. <el-form-item
  12. label="Report Type:"
  13. class="row-item">
  14. <el-select v-model="reportFilter.reportType">
  15. <el-option
  16. v-for="reportType in reportTypeOptions"
  17. :label="reportType.name"
  18. :value="reportType.value"
  19. :key="reportType.value"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="Service Provider:" v-if="reportFilter.reportType !== 'MTU'">
  24. <el-select v-model="reportFilter.providerPk">
  25. <el-option
  26. v-for="serviceProvider in serviceProviderOptions"
  27. :label="serviceProvider.name"
  28. :value="serviceProvider.value"
  29. :key="serviceProvider.value"
  30. ></el-option>
  31. </el-select>
  32. </el-form-item>
  33. </div>
  34. <div class="row">
  35. <el-form-item
  36. label="Month:"
  37. class="row-item">
  38. <el-select v-model="reportFilter.month">
  39. <el-option
  40. v-for="month in monthOptions"
  41. :label="month.name"
  42. :value="month.value"
  43. :key="month.value"
  44. ></el-option>
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item
  48. label="Year:"
  49. class="row-item">
  50. <el-date-picker
  51. v-model="reportFilter.year"
  52. format="yyyy"
  53. value-format="yyyy"
  54. type="year"
  55. :clearable="false"
  56. />
  57. </el-form-item>
  58. <el-button
  59. class="filter-item generate-button"
  60. v-waves
  61. type="primary"
  62. @click="handleGenerateReport">
  63. Search
  64. </el-button>
  65. <el-button
  66. class="filter-item generate-button"
  67. v-waves
  68. type="primary"
  69. :disabled="regenbtn"
  70. @click="reGenerateReport">
  71. Generate
  72. </el-button>
  73. </div>
  74. </el-form>
  75. <el-table
  76. :data="reports"
  77. fit
  78. style="width: 100%;">
  79. <el-table-column
  80. label="File Name"
  81. prop="fileName"
  82. align="center"
  83. min-width="400"
  84. >
  85. <template slot-scope="{row}">
  86. <span>{{ row.fileName }}</span>
  87. </template>
  88. </el-table-column>
  89. <el-table-column
  90. label="Month"
  91. prop="monthStr"
  92. align="center"
  93. min-width="90"
  94. >
  95. <template slot-scope="{row}">
  96. <span>{{ row.monthStr }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column
  100. label="Service Provider"
  101. prop="providerName"
  102. align="center"
  103. min-width="170"
  104. >
  105. <template slot-scope="{row}">
  106. <span>{{ row.providerName }}</span>
  107. </template>
  108. </el-table-column>
  109. <el-table-column
  110. label="Creation Date/Time"
  111. prop="createDateTime"
  112. align="center"
  113. min-width="180"
  114. >
  115. <template slot-scope="{row}">
  116. <span>{{ row.createDateTime }}</span>
  117. </template>
  118. </el-table-column>
  119. <el-table-column
  120. v-if="!$route.meta.onlyView"
  121. label="Action"
  122. align="center"
  123. min-width="160"
  124. >
  125. <template slot-scope="{row}">
  126. <el-button
  127. :loading="row.loading"
  128. icon="el-icon-download"
  129. class="export-button"
  130. @click="handleExportExcel(row)"
  131. >
  132. Export
  133. </el-button>
  134. </template>
  135. </el-table-column>
  136. </el-table>
  137. <div class="right">
  138. <pagination
  139. v-show="total > 0"
  140. :total="total"
  141. :page.sync="pagination.page"
  142. :limit.sync="pagination.limit"
  143. @pagination="handlePageChange" />
  144. </div>
  145. </div>
  146. </div>
  147. </template>
  148. <script>
  149. import api from '@/http/api/dashboard'
  150. import reports from '@/http/api/reports'
  151. // waves directive
  152. import waves from '@/directive/waves'
  153. // secondary package based on el-pagination
  154. import Pagination from '@/components/Pagination'
  155. import TableAction from '@/components/TableAction.vue'
  156. const { getProviderList } = api
  157. const {
  158. getReportTypeList,
  159. getMonthList,
  160. getReportsPages,
  161. downloadFile,
  162. generateMonthlyExcel
  163. } = reports
  164. export default {
  165. name: 'Reports',
  166. components: { Pagination, TableAction },
  167. directives: { waves },
  168. setup() {
  169. },
  170. created() {
  171. this.getData()
  172. this.getReportsPages()
  173. },
  174. data() {
  175. return {
  176. loading: false,
  177. regenbtn: false,
  178. reportTypeOptions: [],
  179. serviceProviderOptions: [],
  180. monthOptions: [],
  181. yearOptions: [],
  182. reportFilter: {
  183. reportType: '',
  184. providerPk: '',
  185. year: ''+new Date().getFullYear(),
  186. month: '',
  187. },
  188. reports: [],
  189. total: 0,
  190. pagination: {
  191. limit: 10,
  192. page: 1,
  193. }
  194. }
  195. },
  196. methods: {
  197. getData() {
  198. this.loading = true
  199. Promise.all([
  200. this.getServiceProviderTypeOptions(),
  201. this.getMonthOptions(),
  202. this.getReportTypeOptions(),
  203. ]).then(() => {
  204. this.loading = false
  205. })
  206. },
  207. handleGenerateReport() {
  208. this.loading = true
  209. this.getReportsPages()
  210. },
  211. async reGenerateReport() {
  212. this.regenbtn = true;
  213. this.loading = true;
  214. generateMonthlyExcel(this.reportFilter).then(res => {
  215. this.loading = false;
  216. this.$message({
  217. type: res.success?'success':'error',
  218. message: res.msg
  219. })
  220. }).catch(err => {
  221. this.loading = false;
  222. this.$message({
  223. type: 'error',
  224. message: err
  225. })
  226. })
  227. setTimeout(() => {
  228. this.regenbtn = false;
  229. }, 5000);
  230. },
  231. getServiceProviderTypeOptions() {
  232. return getProviderList().then(({ data }) => {
  233. this.serviceProviderOptions = data
  234. this.reportFilter.providerPk = data[0].value
  235. })
  236. },
  237. getMonthOptions() {
  238. return getMonthList().then(({ success, data }) => {
  239. if (success) {
  240. this.monthOptions = data
  241. this.reportFilter.month = data[0].value
  242. }
  243. })
  244. },
  245. getReportTypeOptions() {
  246. return getReportTypeList()
  247. .then(({ success, data }) => {
  248. if (success) {
  249. this.reportTypeOptions = data
  250. this.reportFilter.reportType = data[0].value
  251. }
  252. })
  253. },
  254. handlePageChange(value) {
  255. this.loading = true
  256. const { limit, page } = value
  257. this.pagination.limit = limit
  258. this.pagination.page = page
  259. this.getReportsPages()
  260. },
  261. getReportsPages() {
  262. const {
  263. limit,
  264. page,
  265. } = this.pagination
  266. const params = {
  267. pageSize: limit,
  268. pageNo: page,
  269. pageVo: this.reportFilter,
  270. }
  271. return getReportsPages(params)
  272. .then(({ success, data, total }) => {
  273. if (success) {
  274. this.reports = data.map((report) => {
  275. report.loading = false
  276. return report
  277. })
  278. this.total = total
  279. }
  280. }).finally(() => {
  281. this.loading = false
  282. })
  283. },
  284. handleExportExcel(row) {
  285. row.loading = true
  286. downloadFile({ filePk: row.filePk }).then((res) => {
  287. this.downloadExcel(res, row.fileName)
  288. }).finally(() => {
  289. row.loading = false
  290. })
  291. },
  292. downloadExcel(res, fileName) {
  293. const blob = new Blob([res], {
  294. type: 'application/vnd.ms-excel;charset=utf-8'
  295. })
  296. // let href = window.URL.createObjectURL(blob)
  297. if ('download' in document.createElement('a')) {
  298. // 非IE下载
  299. const elink = document.createElement('a')
  300. elink.download = fileName
  301. elink.style.display = 'none'
  302. elink.href = URL.createObjectURL(blob)
  303. document.body.appendChild(elink)
  304. elink.click()
  305. URL.revokeObjectURL(elink.href) // 释放URL 对象
  306. document.body.removeChild(elink)
  307. } else {
  308. // IE10+下载
  309. navigator.msSaveBlob(blob, fileName)
  310. }
  311. this.excelLoad = false
  312. }
  313. },
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. @import '../styles/variables.scss';
  318. .view-container {
  319. width: 100%;
  320. padding: 20px 60px;
  321. background-color: #F0F5FC;
  322. }
  323. .view-content {
  324. padding: 15px 45px;
  325. border-radius: 6px;
  326. min-height: calc(#{$mainAppMinHeight} - (2 * 20px));
  327. background-color: white;
  328. }
  329. .section-title {
  330. color: #333;
  331. margin-top: 20px;
  332. margin-bottom: 30px;
  333. font-size: 16px;
  334. user-select: none;
  335. line-height: 24px;
  336. font-weight: 500;
  337. font-family: sans-serif;
  338. text-transform: uppercase;
  339. }
  340. .row {
  341. display: flex;
  342. }
  343. .row-item {
  344. margin-right: 66px;
  345. }
  346. .generate-button {
  347. width: 107.9px;
  348. height: 40px;
  349. }
  350. .export-button {
  351. background-color: #fff;
  352. }
  353. </style>