UserManagement.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-form
  5. ref="filter-form"
  6. v-bind:inline="true"
  7. label-position="left"
  8. label-width="70px"
  9. style="width: 100%;">
  10. <div class="filter-view">
  11. <div>
  12. <el-input
  13. v-model="criteria"
  14. placeholder="Search by User ID, Email, Phone or Licence Plate"
  15. style="width: 400px;" />
  16. </div>
  17. <div>
  18. <el-button
  19. v-waves
  20. type="primary"
  21. icon="el-icon-search"
  22. @click="handleFilter">
  23. Search
  24. </el-button>
  25. </div>
  26. <div class="filter-flex-button" v-if="!$route.meta.onlyView">
  27. <el-button
  28. type="primary"
  29. icon="el-icon-plus"
  30. @click="handleClickAddUserButton">
  31. Add User
  32. </el-button>
  33. </div>
  34. </div>
  35. </el-form>
  36. </div>
  37. <el-table
  38. :key="tableKey"
  39. v-loading="listLoading"
  40. :data="list"
  41. style="width: 100%;">
  42. <el-table-column
  43. label="Name"
  44. prop="userId"
  45. align="center">
  46. <template slot-scope="{row}">
  47. <div
  48. class="link-type"
  49. v-if="!$route.meta.onlyView"
  50. @click="handleUpdateUser(row)">
  51. {{row.nickName}}
  52. </div>
  53. <div v-else>{{row.nickName}}</div>
  54. </template>
  55. </el-table-column>
  56. <!-- <el-table-column
  57. label="Name"
  58. prop="nickName"
  59. align="center"/> -->
  60. <el-table-column
  61. label="Credit"
  62. prop="credit"
  63. align="center"/>
  64. <el-table-column
  65. label="Email"
  66. prop="email"
  67. align="center"/>
  68. <el-table-column
  69. width="200"
  70. label="Phone"
  71. prop="phone"
  72. align="center"/>
  73. <el-table-column
  74. width="150"
  75. label="Status"
  76. prop="status"
  77. align="center"/>
  78. <el-table-column
  79. label="Action"
  80. align="center"
  81. width="210"
  82. v-if="!$route.meta.onlyView">
  83. <template slot-scope="{row, $index}">
  84. <TableAction
  85. @edit="handleUpdateUser(row, $index)"
  86. @delete="handleDeleteUser(row, $index)"/>
  87. <!-- <el-button
  88. type="primary"
  89. size="mini"
  90. @click="handleUpdateUser(row, $index)">
  91. Edit
  92. </el-button>
  93. <el-button
  94. size="mini"
  95. type="danger"
  96. @click="handleDeleteUser(row, $index)">
  97. Delete
  98. </el-button> -->
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <div class="right">
  103. <pagination
  104. v-show="total > 0"
  105. :total="total"
  106. :page.sync="listQuery.page"
  107. :limit.sync="listQuery.limit"
  108. @pagination="handlePageChange" />
  109. </div>
  110. </div>
  111. </template>
  112. <script>
  113. import waves from '@/directive/waves' // waves directive
  114. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  115. import TableAction from '@/components/TableAction'
  116. import {
  117. fetchList,
  118. deleteUser,
  119. addUser,
  120. } from '../../http/api/userManagement'
  121. export default {
  122. name: 'UserManagement',
  123. components: { Pagination, TableAction },
  124. directives: { waves },
  125. data() {
  126. return {
  127. tableKey: 0,
  128. list: null,
  129. total: 0,
  130. listLoading: true,
  131. criteria: '',
  132. listQuery: {
  133. page: 1,
  134. limit: 10,
  135. },
  136. }
  137. },
  138. created() {
  139. this.getList()
  140. },
  141. methods: {
  142. getList() {
  143. this.listLoading = true
  144. fetchList({
  145. limit: this.listQuery.limit,
  146. page: this.listQuery.page,
  147. criteria: this.criteria,
  148. })
  149. .then(response => {
  150. this.list = response.data
  151. this.total = response.total
  152. })
  153. .finally(() => {
  154. this.listLoading = false
  155. })
  156. },
  157. handlePageChange(value) {
  158. const {limit, page} = value;
  159. this.listQuery.limit = limit;
  160. this.listQuery.page = page;
  161. this.getList();
  162. },
  163. handleFilter() {
  164. this.listQuery.page = 1
  165. this.getList()
  166. },
  167. handleClickAddUserButton() {
  168. this.$router.push({ path: '/user-management/add-user' })
  169. },
  170. handleUpdateUser(user, index) {
  171. //this.$store.commit('userManagement/SET_SELECTED_USER', user)
  172. this.$router.push({ path: '/user-management/update-user/' + user.userId })
  173. },
  174. handleDeleteUser(row, index) {
  175. this.$confirm('Are you sure you want to delete this user?', 'Delete', {
  176. confirmButtonText: 'Confirm',
  177. cancelButtonText: 'Cancel',
  178. type: 'warning'
  179. }).then(res => {
  180. deleteUser(row.userId).then(() => {
  181. this.$notify({
  182. title: 'Success',
  183. message: `Delete user succese ${row.nickName}`,
  184. type: 'success',
  185. duration: 2000
  186. })
  187. this.list.splice(index, 1)
  188. }).catch(error => {
  189. this.$notify({
  190. title: 'Failed',
  191. message: `Delete User Error: ${error}`,
  192. type: 'error',
  193. duration: 5000
  194. });
  195. });
  196. });
  197. },
  198. }
  199. }
  200. </script>