index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2022-12-14 16:03:57
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-04-08 17:57:00
  7. -->
  8. <template>
  9. <div class="page-container">
  10. <el-form-item label="发送人员" prop="users">
  11. <div class="grid">
  12. <div class="item">
  13. <el-scrollbar height="400px">
  14. <el-tree
  15. ref="departmentTree"
  16. :data="department_list"
  17. default-expand-all
  18. :empty-text="emptyText"
  19. highlight-current
  20. node-key="id"
  21. :props="defaultProps"
  22. @node-click="handleNodeDepartment"
  23. />
  24. </el-scrollbar>
  25. </div>
  26. <div class="item middle">
  27. <el-scrollbar height="400px">
  28. <div class="people-search">
  29. <el-input
  30. v-model.trim="name"
  31. clearable
  32. placeholder="请输入姓名"
  33. />
  34. <el-button
  35. circle
  36. :icon="Search"
  37. style="margin-left: 10px"
  38. type="primary"
  39. />
  40. <el-button
  41. style="margin-left: 10px"
  42. type="primary"
  43. @click="selectAll"
  44. >
  45. 全选
  46. </el-button>
  47. </div>
  48. <el-tree
  49. ref="departmentPeople"
  50. :data="people_list"
  51. :default-checked-keys="peopleChecked"
  52. default-expand-all
  53. highlight-current
  54. min-width="200px"
  55. node-key="id"
  56. :props="defaultProps"
  57. show-checkbox
  58. @check-change="handleNodeClickPeople"
  59. />
  60. </el-scrollbar>
  61. </div>
  62. <div class="item">
  63. <el-scrollbar height="400px">
  64. <div class="people-search">
  65. <el-input
  66. v-model.trim="name"
  67. clearable
  68. placeholder="请输入姓名"
  69. />
  70. <el-button
  71. circle
  72. :icon="Search"
  73. style="margin-left: 10px"
  74. type="primary"
  75. />
  76. </div>
  77. <div>
  78. <div
  79. v-for="(item, index) in users"
  80. :key="index"
  81. class="select-list"
  82. >
  83. <div class="name">{{ item.name }}</div>
  84. <el-icon
  85. color="#f56c6c"
  86. size="18"
  87. style="line-height: 35px; display: inline-block"
  88. @click="deletePeople(item.id)"
  89. >
  90. <Delete />
  91. </el-icon>
  92. </div>
  93. </div>
  94. </el-scrollbar>
  95. </div>
  96. </div>
  97. </el-form-item>
  98. </div>
  99. </template>
  100. <script>
  101. import { getDepartmentList, getPersonList } from './api/index'
  102. import { handleTree } from '@/utils/publicMethods' //将列表转坏为树形
  103. import { nextTick } from 'vue'
  104. import { Search, Delete } from '@element-plus/icons-vue'
  105. export default defineComponent({
  106. name: 'RoleManagementEdit',
  107. // props: ['pieData'],
  108. emits: ['changeNavfu'],
  109. setup(props, ctx) {
  110. const pie_data = toRefs(props.pieData)
  111. // const $baseMessage = inject('$baseMessage')
  112. const state = reactive({
  113. formRef: null,
  114. departmentTree: null,
  115. department_list: [], //部门列表
  116. departmentPeople: null,
  117. defaultProps: {
  118. children: 'children',
  119. label: 'name',
  120. },
  121. peopleChecked: [], //选中人员列表
  122. people_list: '', //用户列表
  123. name: '', //用户姓名
  124. emptyText: '',
  125. users: [], //已选择的用户
  126. form: {
  127. name: '',
  128. send_type: [],
  129. body: '',
  130. type: '',
  131. users: [],
  132. status: 1,
  133. },
  134. title: '',
  135. dialogFormVisible: false,
  136. list: [],
  137. })
  138. if (pie_data) {
  139. state.users = pie_data
  140. const arr = []
  141. for (let i = 0; i < pie_data.length; i++) {
  142. arr.push(pie_data[i].id)
  143. }
  144. state.peopleChecked = arr
  145. }
  146. watch(props, (newProps) => {
  147. const pie_data = newProps.pieData
  148. console.log(newProps.pieData, 'newProps.pieData')
  149. if (pie_data) {
  150. state.users = pie_data
  151. const arr = []
  152. for (let i = 0; i < pie_data.length; i++) {
  153. arr.push(pie_data[i].id)
  154. }
  155. console.log(arr)
  156. state.peopleChecked = arr
  157. }
  158. getDepartment()
  159. getPerson()
  160. })
  161. //获取部门列表
  162. const getDepartment = async () => {
  163. const { data } = await getDepartmentList({
  164. status: 1,
  165. sortedBy: 'desc',
  166. orderBy: 'sort',
  167. filter: 'id;name;parent_id;sort;status',
  168. })
  169. // const arr_1 = data
  170. const arr_1 = [{ id: 0, name: '全部部门' }].concat(data)
  171. const arr = handleTree(arr_1, 'id', 'parent_id')
  172. state.department_list = arr
  173. nextTick(() => {
  174. state['departmentTree'].setCurrentKey(0)
  175. })
  176. }
  177. //获取用户列表
  178. const getPerson = async (department_id) => {
  179. const { data } = await getPersonList({
  180. department_id: department_id,
  181. status: 1,
  182. filter: 'id;name',
  183. })
  184. state.people_list = data
  185. }
  186. //点击切换部门
  187. const handleNodeDepartment = (node) => {
  188. getPerson(node.id)
  189. }
  190. const handleNodeClickPeople = () => {
  191. const data = state['departmentPeople'].getCheckedNodes()
  192. state.users = data
  193. ctx.emit('changeNavfu', data)
  194. }
  195. //全选
  196. const selectAll = () => {
  197. const arr = []
  198. state.people_list.map((item) => {
  199. arr.push(item.id)
  200. })
  201. state.peopleChecked = arr
  202. }
  203. //删除已选中的人员
  204. const deletePeople = (id) => {
  205. state.users = state.users.filter((item) => {
  206. return item.id !== id
  207. })
  208. const arr = []
  209. state.users.map((item) => {
  210. arr.push(item.id)
  211. })
  212. state['departmentPeople'].setCheckedKeys(arr, true, false)
  213. ctx.emit('changeNavfu', arr)
  214. }
  215. onMounted(() => {
  216. getDepartment()
  217. getPerson()
  218. })
  219. return {
  220. ...toRefs(state),
  221. getDepartment,
  222. getPerson,
  223. handleNodeDepartment,
  224. handleNodeClickPeople,
  225. deletePeople,
  226. selectAll,
  227. Search,
  228. Delete,
  229. }
  230. },
  231. })
  232. </script>
  233. <style lang="scss" scoped>
  234. .page-container {
  235. padding: 0 !important;
  236. }
  237. .vab-tree-border {
  238. width: 100%;
  239. height: 250px;
  240. padding: $base-padding;
  241. overflow-y: auto;
  242. border: 1px solid #dcdfe6;
  243. border-radius: $base-border-radius;
  244. }
  245. .grid {
  246. display: flex;
  247. border: dashed 1px #dcdfe6;
  248. padding: 15px;
  249. width: 100%;
  250. .item {
  251. flex: 1;
  252. margin-right: 5px;
  253. }
  254. .middle {
  255. padding: 0 20px;
  256. border-right: dashed 1px #dcdfe6;
  257. border-left: dashed 1px #dcdfe6;
  258. }
  259. }
  260. .people-search {
  261. display: flex;
  262. margin-bottom: 15px;
  263. }
  264. .select-list {
  265. display: flex;
  266. height: 30px;
  267. padding: 0 10px;
  268. line-height: 30px;
  269. cursor: pointer;
  270. .name {
  271. flex: 1;
  272. }
  273. }
  274. .select-list:hover {
  275. background-color: #eeeeee;
  276. }
  277. </style>