index.vue 7.4 KB

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