index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-form
  5. ref="form"
  6. :model="form">
  7. <div class="filter-view">
  8. <el-form-item
  9. label=""
  10. class="flex-item flex1"
  11. style="min-width: 200px; max-width: 400px;">
  12. <el-input
  13. v-model="form.criteria"
  14. placeholder="Search by Email, Phone or Fleet Company Name"
  15. clearable/>
  16. </el-form-item>
  17. <el-button
  18. @click="onClickSearch"
  19. icon="el-icon-search"
  20. type="primary">
  21. Search
  22. </el-button>
  23. <div class="flex1"></div>
  24. <my-upload
  25. accept=".xls,.xlsx,.csv"
  26. :limit="1"
  27. :is-blob="true"
  28. :action="action"
  29. :headers="headers"
  30. :file-list="fileList"
  31. :show-file-list="false"
  32. :before-upload="onImportStart"
  33. :on-success="onImportExcel"
  34. :on-error="onImportExcelErr">
  35. <el-button
  36. icon="el-icon-upload2"
  37. type="primary"
  38. :loading="loading.upload">
  39. Import Excel
  40. </el-button>
  41. </my-upload>
  42. <el-button
  43. icon="el-icon-download"
  44. type="primary"
  45. :loading="loading.download"
  46. @click="onDownloadTmp">
  47. Download Template
  48. </el-button>
  49. <el-button
  50. icon="el-icon-plus"
  51. type="primary"
  52. @click="onClickAdd">
  53. Add PH Driver
  54. </el-button>
  55. </div>
  56. </el-form>
  57. </div>
  58. <el-table :data="table.list" v-loading="loading.table">
  59. <el-table-column
  60. align="center"
  61. label="User ID"
  62. prop="userPk"
  63. width="100">
  64. <template slot-scope="{row}" >
  65. <router-link
  66. class="table-link"
  67. :to="{
  68. name: 'DriverDetail',
  69. query: {
  70. id: row.userPk,
  71. dispatch: true,
  72. },
  73. }">
  74. {{ row.userPk }}
  75. </router-link>
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. width="200"
  80. align="center"
  81. label="Name"
  82. prop="nickName"
  83. ></el-table-column>
  84. <el-table-column
  85. align="center"
  86. label="Email"
  87. prop="email"
  88. ></el-table-column>
  89. <el-table-column
  90. width="150"
  91. align="center"
  92. label="Phone"
  93. prop="phone"
  94. ></el-table-column>
  95. <el-table-column
  96. align="center"
  97. label="Fleet Company"
  98. prop="fleetCompanyName"
  99. ></el-table-column>
  100. <el-table-column
  101. align="center"
  102. label="Status"
  103. prop="driverStatus"
  104. width="150"
  105. ></el-table-column>
  106. <el-table-column
  107. align="center"
  108. label="Action"
  109. width="210"
  110. >
  111. <template slot-scope="{ row }">
  112. <TableAction
  113. :showEdit="isDriverOperation(row)"
  114. @edit="onClickEditButton(row)"
  115. @delete="onClickDeleteButton(row)"/>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. <div class="right">
  120. <pagination
  121. v-show="table.total > 0"
  122. :total="table.total"
  123. :page.sync="table.pageNo"
  124. :limit.sync="table.pageSize"
  125. @pagination="handlePageChange" />
  126. </div>
  127. </div>
  128. </template>
  129. <script>
  130. import Pagination from '@/components/Pagination'
  131. import TableAction from '@/components/TableAction'
  132. import api from '@/http/api/driver'
  133. import { baseURL } from '@/http/http'
  134. import { getToken } from '@/utils/auth'
  135. import MyUpload from '@/components/MyUpload'
  136. export default {
  137. name: "FleetCompanyList",
  138. components: { Pagination, TableAction,MyUpload },
  139. data() {
  140. return {
  141. form: {
  142. criteria: ''
  143. },
  144. table: {
  145. list: [],
  146. total: 0,
  147. pageNo: 1,
  148. pageSize: 10,
  149. },
  150. loading: {
  151. table: false,
  152. upload: false,
  153. download: false
  154. },
  155. fileList: []
  156. }
  157. },
  158. computed: {
  159. action() {
  160. return baseURL + process.env.VUE_APP_API_PREFIX + '/driver/batch/create'
  161. },
  162. headers() {
  163. return {
  164. accessToken: getToken()
  165. }
  166. }
  167. },
  168. methods: {
  169. isDriverOperation(driver) {
  170. return driver.driverStatus === 'Pending Review'
  171. },
  172. async getDriverPages() {
  173. const params = {
  174. pageSize: this.table.pageSize,
  175. pageNo: this.table.pageNo,
  176. pageVo: {
  177. criteria: this.form.criteria,
  178. },
  179. }
  180. const { success, data, total } = await api.fetchDriverPages(params)
  181. if (success) {
  182. this.table.list = data
  183. this.table.total = total
  184. }
  185. },
  186. onImportStart() {
  187. this.loading.upload = true;
  188. },
  189. onImportExcel(res, file, fileList) {
  190. fileList = [];
  191. this.fileList = [];
  192. if (res.success == undefined) {
  193. this.downloadExcel(res, "batch_create_result.xls");
  194. this.loading.upload = false;
  195. } else {
  196. this.onImportExcelErr(res.msg, file, fileList);
  197. }
  198. },
  199. onImportExcelErr(err, file, fileList) {
  200. this.$message({
  201. type: 'error',
  202. message: err
  203. })
  204. this.loading.upload = false;
  205. },
  206. onDownloadTmp() {
  207. this.loading.download = true;
  208. api.downloadTemplate().then(res => {
  209. this.downloadExcel(res, "driver-template.xlsx")
  210. }).catch(err => {
  211. this.$message({
  212. type: 'error',
  213. message: err
  214. })
  215. }).finally(() => {
  216. this.loading.download = false;
  217. })
  218. },
  219. downloadExcel(res, fileName) {
  220. const blob = new Blob([res], {
  221. type: 'application/vnd.ms-excel;charset=utf-8'
  222. })
  223. // let href = window.URL.createObjectURL(blob)
  224. if ('download' in document.createElement('a')) {
  225. // 非IE下载
  226. const elink = document.createElement('a')
  227. elink.download = fileName
  228. elink.style.display = 'none'
  229. elink.href = URL.createObjectURL(blob)
  230. document.body.appendChild(elink)
  231. elink.click()
  232. URL.revokeObjectURL(elink.href) // 释放URL 对象
  233. document.body.removeChild(elink)
  234. } else {
  235. // IE10+下载
  236. navigator.msSaveBlob(blob, fileName)
  237. }
  238. },
  239. onClickSearch() {
  240. this.table.pageNo = 1
  241. this.getDriverPages()
  242. },
  243. onClickAdd() {
  244. this.$router.push({ name: 'DriverDetail' })
  245. },
  246. async onClickDeleteButton(driver) {
  247. this.$confirm('Are you sure you want to delete this driver?', 'Delete', {
  248. confirmButtonText: 'OK',
  249. cancelButtonText: 'Cancel',
  250. type: 'warning'
  251. }).then(res => {
  252. this.deleteUser(driver);
  253. })
  254. },
  255. async deleteUser(driver) {
  256. try {
  257. const { success, msg } = await api.deleteDriver({
  258. userPk: driver.userPk
  259. })
  260. if (success) {
  261. this.$notify.success(msg)
  262. this.getDriverPages()
  263. }
  264. } catch (error) {
  265. this.$notify.error(error)
  266. }
  267. },
  268. onClickEditButton(driver) {
  269. this.$router.push({
  270. name : "DriverDetail",
  271. query: { id: driver.userPk },
  272. })
  273. },
  274. handlePageChange() {
  275. this.listLoading = true;
  276. this.getDriverPages()
  277. },
  278. },
  279. created() {
  280. this.getDriverPages()
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. </style>