您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

agentsUserManagementPage.vue 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <!-- eslint-disable max-len -->
  3. <div class="container">
  4. <br />
  5. <br />
  6. <div class="row">
  7. <div class="col-md-12 col-lg-8">
  8. <div class="title-box-d">
  9. <h1 class="title-d" style="text-align:left; font-size: 250%">Agent Management</h1>
  10. </div>
  11. </div>
  12. </div>
  13. <div class="row">
  14. <div class="col-md-2 offset-1">
  15. <button
  16. @click="routerGoTo('/status/userManagementPage')"
  17. type="button"
  18. class="btn btn-b-n"
  19. >Private Users</button>
  20. </div>
  21. <div class="col-md-2 offset-2">
  22. <button type="button" class="btn btn-b-n">Agents</button>
  23. </div>
  24. <div class="col-md-2 offset-2">
  25. <button
  26. type="button"
  27. class="btn btn-b-n"
  28. data-toggle="modal"
  29. :data-target="'#myModal' + i"
  30. >New Agent</button>
  31. <div :id="'myModal' + i" class="modal fade" role="dialog">
  32. <div class="modal-dialog modal-lg">
  33. <div class="modal-content">
  34. <div class="modal-header">
  35. <button type="button" class="close" data-dismiss="modal">&times;</button>
  36. </div>
  37. <Agency name="Agency" :isAddAgent="false" :item="item" />
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <div class="container">
  44. <div class="d-flex justify-content-between">
  45. <div class="p-2">
  46. <input v-model="searchItem" class="form-control" placeholder="Search ..." />
  47. </div>
  48. </div>
  49. <div v-if="Delete === true">
  50. <alert :text="'Private User removed successfully'" :type="'SUCCESS'" />
  51. </div>
  52. <br />
  53. <table class="table table-bordered">
  54. <thead>
  55. <tr>
  56. <td colspan="11">
  57. <div class="myWell">
  58. <h4>Agents</h4>
  59. </div>
  60. </td>
  61. </tr>
  62. <tr>
  63. <th>
  64. <b>ID</b>
  65. </th>
  66. <th>
  67. <b>Name</b>
  68. </th>
  69. <th>
  70. <b>Surname</b>
  71. </th>
  72. <th>
  73. <b>Cell Number</b>
  74. </th>
  75. <th>
  76. <b>Telephone Number</b>
  77. </th>
  78. <th>
  79. <b>Email</b>
  80. </th>
  81. <th>
  82. <b>Role</b>
  83. </th>
  84. <th>
  85. <b>Reset Password</b>
  86. </th>
  87. <th>
  88. <b>Modify</b>
  89. </th>
  90. <th>
  91. <b>Remove</b>
  92. </th>
  93. <th>
  94. <b>Soft Delete</b>
  95. </th>
  96. </tr>
  97. </thead>
  98. <tbody>
  99. <tr v-for="(item, i) in DisplayItems" :key="i">
  100. <td>{{ item.id }}</td>
  101. <td>{{ item.name }}</td>
  102. <td>{{ item.surname }}</td>
  103. <td>{{ item.cellNumber }}</td>
  104. <td>{{ item.telephone }}</td>
  105. <td>{{ item.email }}</td>
  106. <td v-if="item.user">{{ item.user.role }}</td>
  107. <td v-else></td>
  108. <td>
  109. <button type="button" class="btn" style="margin:2px; color: #60CBEB">Reset</button>
  110. </td>
  111. <td>
  112. <button
  113. type="button"
  114. class="btn"
  115. style="margin:2px; color: #60CBEB"
  116. @click="routerGoTo('/user/updateProfileInfo')"
  117. >Edit</button>
  118. </td>
  119. <td>
  120. <button
  121. type="button"
  122. @click="Delete(item.id)"
  123. class="btn"
  124. style="width: 85px; height:40px; color:#60CBEB"
  125. >Delete</button>
  126. </td>
  127. <td>{{ item.isDeleted}}</td>
  128. </tr>
  129. </tbody>
  130. </table>
  131. <div class="d-flex justify-content-between">
  132. <div class="p-1">{{ currentPage + ' / ' + PageCount }}</div>
  133. <div class="p-1">
  134. <BasePagination
  135. :currentPage="currentPage"
  136. :pageCount="PageCount"
  137. @nextPage="pageChangeHandle('next')"
  138. @previousPage="pageChangeHandle('previous')"
  139. @loadPage="pageChangeHandle"
  140. />
  141. </div>
  142. </div>
  143. </div>
  144. <br />
  145. </div>
  146. </template>
  147. <script>
  148. import { mapState, mapActions } from 'vuex';
  149. import axios from 'axios';
  150. import _ from 'lodash';
  151. import ItemsPerPageList from '../../../assets/staticData/itemsPerPage';
  152. import BasePagination from '../../shared/basePagination.vue';
  153. import Agency from '../../user/registerAgencySection.vue';
  154. import alert from '../../shared/alert.vue';
  155. export default {
  156. name: 'agentManagementPage',
  157. components: {
  158. BasePagination,
  159. Agency,
  160. alert,
  161. },
  162. props: {
  163. delete: Boolean,
  164. },
  165. data() {
  166. return {
  167. sortKey: '',
  168. reverse: false,
  169. searchItem: '',
  170. itemsPerPageList: ItemsPerPageList,
  171. visibleItemsPerPageCount: 0,
  172. currentPage: 1,
  173. item: {},
  174. };
  175. },
  176. methods: {
  177. ...mapActions('register', ['getAgents', 'deleteAgent']),
  178. addNewAgent({ commit }) {
  179. axios
  180. .post('/api/agent')
  181. .then(result => commit('saveAgent', result.data))
  182. .catch(console.error);
  183. },
  184. routerGoTo(goTo) {
  185. this.$router.push(goTo);
  186. },
  187. sortBy(sortKey) {
  188. this.reverse = this.sortKey === sortKey ? !this.reverse : false;
  189. this.sortKey = sortKey;
  190. },
  191. async pageChangeHandle(value) {
  192. console.log(value);
  193. switch (value) {
  194. case 'next':
  195. this.currentPage += 1;
  196. break;
  197. case 'previous':
  198. this.currentPage -= 1;
  199. break;
  200. default:
  201. this.currentPage = value;
  202. }
  203. },
  204. onChangeItemsPerPage() {
  205. if (this.currentPage !== 1) {
  206. this.currentPage = 1;
  207. }
  208. },
  209. Delete(id) {
  210. this.deleteAgent(id);
  211. },
  212. },
  213. mounted() {
  214. this.getAgents();
  215. try {
  216. // to assign initial value to itemsPerPage
  217. if (this.itemsPerPageList && this.itemsPerPageList.length > 0) {
  218. const [startItem] = this.itemsPerPageList;
  219. this.visibleItemsPerPageCount = startItem;
  220. }
  221. } catch (error) {
  222. throw error;
  223. }
  224. },
  225. computed: {
  226. ...mapState('register', ['agents', 'removeAgent']),
  227. SortDirection() {
  228. return this.reverse ? 'desc' : 'asc';
  229. },
  230. PageCount() {
  231. return this.visibleItemsPerPageCount !== 0
  232. ? Math.ceil(this.FilteredItems.length / this.visibleItemsPerPageCount)
  233. : 1;
  234. },
  235. FilteredItems() {
  236. const list = _.filter(this.agents, item => Object.values(item).some(
  237. i => JSON.stringify(i)
  238. .toLowerCase()
  239. .indexOf(this.searchItem) > -1,
  240. ),);
  241. return _.orderBy(list, this.sortKey, this.SortDirection);
  242. },
  243. DisplayItems() {
  244. const list = this.FilteredItems;
  245. const startSlice = (this.currentPage - 1) * this.visibleItemsPerPageCount;
  246. let endSlice = this.currentPage * this.visibleItemsPerPageCount;
  247. if (endSlice > list.length) {
  248. endSlice = list.length;
  249. }
  250. return list.slice(startSlice, endSlice);
  251. },
  252. },
  253. };
  254. </script>
  255. <style>
  256. </style>