ClientAccountSet.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="client-account-set">
  3. <Button
  4. class="account-add-btn"
  5. type="success"
  6. icon="recode-white icon"
  7. shape="circle"
  8. @click="toAdd"
  9. >添加账号</Button
  10. >
  11. <Table
  12. ref="TableList"
  13. :columns="columns"
  14. :data="users"
  15. :row-class-name="getRowClassName"
  16. disabled-hover
  17. border
  18. ></Table>
  19. <div class="part-page">
  20. <Page
  21. :current="current"
  22. :total="total"
  23. :page-size="size"
  24. show-total
  25. show-elevator
  26. @on-change="toPage"
  27. ></Page>
  28. </div>
  29. <!-- modify-client-user -->
  30. <modify-client-user
  31. :instance="curUser"
  32. @modified="getList"
  33. ref="ModifyClientUser"
  34. ></modify-client-user>
  35. </div>
  36. </template>
  37. <script>
  38. import { clientUserPageList, deleteClientUser, updateClientUser } from "@/api";
  39. import ModifyClientUser from "./components/ModifyClientUser";
  40. import { SYSTEM_ROLE_TYPE } from "@/constants/enumerate";
  41. export default {
  42. name: "client-account-set",
  43. components: { ModifyClientUser },
  44. data() {
  45. return {
  46. workId: this.$route.params.workId,
  47. current: 1,
  48. size: this.GLOBAL.pageSize,
  49. total: 0,
  50. users: [],
  51. curUser: {},
  52. columns: [
  53. {
  54. type: "index",
  55. title: "序号",
  56. width: 100,
  57. align: "center",
  58. indexMethod: row => {
  59. return (this.current - 1) * this.size + row._index + 1;
  60. }
  61. },
  62. {
  63. title: "账号",
  64. key: "loginName"
  65. },
  66. {
  67. title: "密码",
  68. key: "password"
  69. },
  70. {
  71. title: "操作",
  72. key: "action",
  73. width: 240,
  74. align: "center",
  75. className: "table-action",
  76. render: (h, param) => {
  77. let actions = [
  78. {
  79. icon: param.row.enabled ? "enable icon" : "disable icon",
  80. attrs: {
  81. title: param.row.enabled ? "禁用" : "启用"
  82. },
  83. action: () => {
  84. this.toAble(param.row);
  85. }
  86. },
  87. {
  88. icon: "md-create",
  89. classes: [param.row.enabled ? "" : "btn-disabled"],
  90. attrs: {
  91. title: "编辑"
  92. },
  93. action: () => {
  94. this.toEdit(param.row);
  95. }
  96. }
  97. ];
  98. return h("div", this.$tableIconAction(h, actions));
  99. }
  100. }
  101. ]
  102. };
  103. },
  104. mounted() {
  105. this.getList();
  106. },
  107. methods: {
  108. async getList() {
  109. const datas = {
  110. workId: this.workId,
  111. page: this.current - 1,
  112. size: this.size
  113. };
  114. const data = await clientUserPageList(datas);
  115. this.users = data.data.map(item => {
  116. item.roleName = SYSTEM_ROLE_TYPE[item.role];
  117. return item;
  118. });
  119. this.total = data.totalCount;
  120. },
  121. toPage(page) {
  122. this.current = page;
  123. this.getList();
  124. },
  125. getRowClassName(row) {
  126. return row.enabled ? "" : "row-disabled";
  127. },
  128. toAdd() {
  129. this.curUser = {
  130. role: "COLLECTOR",
  131. roleName: "采集员",
  132. workId: this.workId
  133. };
  134. this.$refs.ModifyClientUser.open();
  135. },
  136. toEdit(row) {
  137. if (!row.enabled) return;
  138. this.curUser = row;
  139. this.$refs.ModifyClientUser.open();
  140. },
  141. async toAble(row) {
  142. await updateClientUser({
  143. id: row.id,
  144. loginName: row.loginName,
  145. enabled: !row.enabled
  146. });
  147. this.users[row._index].enabled = !row.enabled;
  148. },
  149. toDelete(row) {
  150. this.$Modal.confirm({
  151. title: "删除警告",
  152. content: "确定要删除当前账号吗?",
  153. onOk: () => {
  154. this.toDel(row.id);
  155. }
  156. });
  157. },
  158. async toDel(id) {
  159. await deleteClientUser(id);
  160. this.$Message.success("删除成功!");
  161. this.deletePageLastItem();
  162. }
  163. }
  164. };
  165. </script>