staffAdmin.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div>
  3. <a-card
  4. :body-style="{padding: '24px 32px'}"
  5. :bordered="false"
  6. :tabList="operationTabList"
  7. :activeTabKey="operationActiveTabKey"
  8. @tabChange="(key) => {this.operationActiveTabKey = key; searchUser()}"
  9. >
  10. <div class="opraiont">
  11. <div class="left">
  12. <span>已选用&nbsp; {{ selectedRowKeys.length }} &nbsp;条数据</span>
  13. <a-button size="small" @click="stopUser">
  14. {{ operationActiveTabKey === '1' ? '停用' : '启用' }}
  15. </a-button>
  16. <a-popconfirm
  17. title="你确定要删除这些角色吗?"
  18. ok-text="Yes"
  19. cancel-text="No"
  20. @confirm="deleteUser"
  21. >
  22. <a-button size="small">
  23. 删除
  24. </a-button>
  25. </a-popconfirm>
  26. <span>
  27. <a-input-search
  28. style="width: 400px"
  29. placeholder="支持手机号或者姓名搜索"
  30. enter-button
  31. @search="onSearch"
  32. />
  33. </span>
  34. </div>
  35. <div class="right">
  36. <a-button type="primary" @click="openModel({id: ''}, {id: '1'}, 'add')">新增员工</a-button>
  37. </div>
  38. </div>
  39. <a-table
  40. :rowKey="record => record.id"
  41. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  42. :columns="columns"
  43. :data-source="staffList"
  44. :loading="loading"
  45. :pagination="pagination"
  46. >
  47. <template slot="dataAuthority" slot-scope="text">
  48. <span>{{ text === 0 ? '全部' : '个人(团队)' }}</span>
  49. </template>
  50. <template slot="action" slot-scope="text, records">
  51. <a @click="openModel(text,records, 'edit')">编辑</a>
  52. </template>
  53. </a-table>
  54. </a-card>
  55. <a-modal v-model="visible" :width="700" style="height: 500px" :title="type === 'add' ? '新增员工' : '编辑员工信息'" @ok="handleOk">
  56. <edit ref="editForm" :type="type"/>
  57. </a-modal>
  58. </div>
  59. </template>
  60. <script>
  61. import edit from './edit'
  62. import { searchUser, postUser, searchUserDetail, stopUser, deleteUser } from '@/api/role'
  63. const columns = [
  64. {
  65. title: '员工编号',
  66. dataIndex: 'id'
  67. },
  68. {
  69. title: '姓名',
  70. dataIndex: 'label'
  71. },
  72. {
  73. title: '部门',
  74. dataIndex: 'departmentLabel'
  75. },
  76. {
  77. title: '手机号',
  78. dataIndex: 'phone'
  79. },
  80. {
  81. title: '邮箱',
  82. dataIndex: 'email'
  83. },
  84. {
  85. title: '微信绑定',
  86. dataIndex: 'wechat'
  87. },
  88. {
  89. title: '角色',
  90. dataIndex: 'roleLabel'
  91. },
  92. {
  93. title: '数据权限',
  94. dataIndex: 'dataAuthority',
  95. scopedSlots: { customRender: 'dataAuthority' }
  96. },
  97. {
  98. title: '操作',
  99. dataIndex: 'action',
  100. key: 'action',
  101. scopedSlots: { customRender: 'action' }
  102. }
  103. ]
  104. export default {
  105. name: 'StaffAdmin',
  106. components: {
  107. edit
  108. },
  109. props: {
  110. departmentId: {
  111. type: String,
  112. required: true
  113. }
  114. },
  115. watch: {
  116. departmentId: {
  117. handler () {
  118. this.searchUser()
  119. }
  120. // immediate: true
  121. }
  122. // searchUserId () {
  123. // }
  124. },
  125. data () {
  126. return {
  127. columns,
  128. visible: false,
  129. operationTabList: [
  130. {
  131. key: '1',
  132. tab: '使用中'
  133. },
  134. {
  135. key: '0',
  136. tab: '已停用'
  137. }
  138. ],
  139. operationActiveTabKey: '1',
  140. selectedRowKeys: [], // Check here to configure the default column
  141. loading: false,
  142. pagination: {
  143. page: 1,
  144. pageSize: 10,
  145. total: 1
  146. },
  147. staffList: [],
  148. searchUserId: '',
  149. searchText: '',
  150. searchUserDetailData: {},
  151. type: 'add' // 当前弹窗是增加还是编辑
  152. }
  153. },
  154. methods: {
  155. // 删除多个
  156. async deleteUser () {
  157. const { code, data } = await deleteUser(this.selectedRowKeys)
  158. this.selectedRowKeys = []
  159. if (code === 0) {
  160. console.log(data)
  161. this.searchUser()
  162. }
  163. },
  164. // 停用 或者 启用 多个账户
  165. async stopUser () {
  166. const { code, data } = await stopUser(this.selectedRowKeys, this.operationActiveTabKey)
  167. this.selectedRowKeys = []
  168. if (code === 0) {
  169. console.log(data)
  170. this.searchUser()
  171. }
  172. },
  173. // 查询用户详情
  174. async searchUserDetail () {
  175. const { code, data } = await searchUserDetail(this.searchUserId)
  176. if (code === 0) {
  177. console.log(data)
  178. this.searchUserDetailData = data || {}
  179. this.$refs.editForm.formData = this.searchUserDetailData
  180. this.$refs.editForm.backfillForm({ label: this.searchUserDetailData.label, phone: this.searchUserDetailData.phone })
  181. }
  182. },
  183. // 打开编辑弹窗
  184. openModel (text, records, type) {
  185. // if (records.id === '') {
  186. // this.searchUserDetail = {}
  187. // }
  188. this.searchUserId = records.id
  189. this.visible = true
  190. this.type = type
  191. this.searchUserDetail()
  192. },
  193. // 搜索框
  194. onSearch (records) {
  195. this.searchText = records
  196. this.searchUser()
  197. },
  198. // 搜索人员
  199. async searchUser () {
  200. const $par = {
  201. departmentId: this.departmentId,
  202. keyWord: this.searchText,
  203. state: Number(this.operationActiveTabKey),
  204. curPage: 1
  205. }
  206. this.loading = true
  207. const { code, data } = await searchUser($par)
  208. this.loading = false
  209. if (code === 0) {
  210. console.log(data)
  211. const { records, total } = data
  212. this.staffList = records
  213. this.pagination.total = total
  214. }
  215. },
  216. // 编辑员工 或者新增员工
  217. async handleOk () {
  218. const $par = await this.$refs.editForm.handleSubmit()
  219. if ($par.code === 500) return
  220. const { code, data } = await postUser($par)
  221. if (code === 0) {
  222. console.log(data)
  223. }
  224. this.visible = false
  225. console.log($par, '$par')
  226. },
  227. // 选中行
  228. onSelectChange (selectedRowKeys) {
  229. console.log('selectedRowKeys changed: ', selectedRowKeys)
  230. this.selectedRowKeys = selectedRowKeys
  231. }
  232. }
  233. }
  234. </script>
  235. <style scoped lang="less">
  236. .opraiont {
  237. margin-bottom: 10px;
  238. display: flex;
  239. justify-content: space-between;
  240. align-items: center;
  241. .left {
  242. display: flex;
  243. align-items: center;
  244. }
  245. span {
  246. margin-right: 10px;
  247. }
  248. .ant-btn {
  249. margin-right: 10px;
  250. }
  251. }
  252. </style>