index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-model="props.dialogVisible"
  5. :title="props.title"
  6. width="1000"
  7. append-to-body
  8. draggable
  9. >
  10. <el-select
  11. v-model="userId"
  12. filterable
  13. remote
  14. reserve-keyword
  15. placeholder="输入姓名,手机号,工号查找"
  16. :remote-method="remoteMethod"
  17. :loading="loading"
  18. style="width: 240px"
  19. clearable
  20. >
  21. <el-option
  22. v-for="item in options"
  23. :key="item.value"
  24. :label="`${item.label}-${item.mobile}`"
  25. :value="item.value"
  26. >
  27. </el-option>
  28. </el-select>
  29. <div class="dialog-mian">
  30. <div v-show="userId == '' || userId == null">
  31. <el-tree
  32. ref="treeRef"
  33. style="max-width: 600px"
  34. class="filter-tree"
  35. :data="deptList"
  36. :props="defaultProps"
  37. :default-expand-all="true"
  38. :expand-on-click-node="false"
  39. @node-click="treeClick"
  40. >
  41. </el-tree>
  42. </div>
  43. <div>
  44. <el-radio-group v-model="userId" v-show="userId">
  45. <div style="display: flex; flex-direction: column">
  46. <el-radio
  47. v-for="item in options"
  48. :key="item.value"
  49. :value="item.value"
  50. style="margin-bottom: 15px"
  51. >
  52. <p style="margin: 0">{{ item.label }}</p>
  53. <p style="margin: 0">{{ item.value }}</p>
  54. </el-radio>
  55. </div>
  56. </el-radio-group>
  57. <el-radio-group v-model="treeReId" v-show="userList.length > 0 && !userId">
  58. <div style="display: flex; flex-direction: column">
  59. <el-radio
  60. v-for="item in userList"
  61. :key="item.id"
  62. :value="item.id"
  63. style="margin-bottom: 15px"
  64. >
  65. <p style="margin: 0">{{ item.name }}</p>
  66. <p style="margin: 0">{{ item.id }}</p>
  67. </el-radio>
  68. </div>
  69. </el-radio-group>
  70. </div>
  71. </div>
  72. <template #footer>
  73. <div class="dialog-footer">
  74. <el-button @click="dialogVisible = false">取消</el-button>
  75. <el-button type="primary" @click="submit">
  76. 确认
  77. </el-button>
  78. </div>
  79. </template>
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script setup lang="ts">
  84. import { defineProps, ref, onMounted, defineEmits } from "vue";
  85. import api from "@/api";
  86. type tableType = {
  87. id: string;
  88. name: string;
  89. };
  90. const defaultProps = {
  91. children: "children",
  92. label: "name",
  93. };
  94. const props = defineProps<{
  95. dialogVisible: boolean;
  96. deptIds: Array<[]>;
  97. deptList: Array<tableType>;
  98. title: string;
  99. }>();
  100. interface ListItem {
  101. value: string;
  102. label: string;
  103. }
  104. const list = ref<ListItem[]>([]);
  105. const options = ref<ListItem[]>([]);
  106. const userId = ref<string>("");
  107. const loading = ref(false);
  108. const treeReId=ref<string>("");
  109. const emits=defineEmits(["closeDialog"]);
  110. const userList = ref<any[]>([]);
  111. const remoteMethod = (query: string) => {
  112. if (query) {
  113. loading.value = true;
  114. api.userApi
  115. .AllMemberList({
  116. name: query,
  117. })
  118. .then((res: any) => {
  119. if (res.code === 200) {
  120. // userList.value = res.data;
  121. let arr: any = [];
  122. res.data.forEach((item) => {
  123. arr.push({
  124. label: item.name,
  125. value: item.id,
  126. mobile: item.mobile,
  127. });
  128. });
  129. loading.value = false;
  130. options.value = arr;
  131. }
  132. });
  133. // setTimeout(() => {
  134. // loading.value = false
  135. // options.value = list.value.filter((item) => {
  136. // return item.label.toLowerCase().includes(query.toLowerCase())
  137. // })
  138. // }, 200)
  139. } else {
  140. options.value = [];
  141. }
  142. };
  143. function treeClick(node: any) {
  144. api.userApi
  145. .AllMemberList({
  146. deptId: node.id,
  147. })
  148. .then((res: any) => {
  149. if (res.code === 200) {
  150. userList.value = res.data;
  151. // options.value=arr
  152. }
  153. });
  154. }
  155. function submit(){
  156. if(props.title=='设置负责人'){
  157. if(userId.value){
  158. const obj=options.value.map((item:any)=>{
  159. if(item.value==userId.value){
  160. return {
  161. name:item.label,
  162. id:item.value,
  163. mobile:item.mobile
  164. }
  165. }
  166. })
  167. api.institutionApi.setDeptLeader({
  168. deptId:props.deptIds,
  169. leaderId:obj[0].userId
  170. }).then(res=>{
  171. if(res.code==200){
  172. emits('closeDialog')
  173. }
  174. })
  175. }else{
  176. let flag={}
  177. userList.value.some((item:any)=>{
  178. if( item.id==treeReId.value){
  179. flag={...item}
  180. return true
  181. }
  182. return false
  183. })
  184. api.institutionApi.setDeptLeader({
  185. deptId:props.deptIds,
  186. leaderId:flag.userId
  187. }).then(res=>{
  188. if(res.code==200){
  189. emits('closeDialog')
  190. }
  191. })
  192. // emits('closeDialog',flag)
  193. }
  194. }else{
  195. if(userId.value){
  196. const obj=options.value.map((item:any)=>{
  197. if(item.value==userId.value){
  198. return {
  199. name:item.label,
  200. id:item.value,
  201. mobile:item.mobile
  202. }
  203. }
  204. })
  205. emits('closeDialog',obj[0])
  206. }else{
  207. let flag={}
  208. userList.value.some((item:any)=>{
  209. if( item.id==treeReId.value){
  210. flag={...item}
  211. return true
  212. }
  213. return false
  214. })
  215. emits('closeDialog',flag)
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .dialog-mian {
  222. display: flex;
  223. border: 1px solid #ccc;
  224. border-radius: 10px;
  225. min-height: 500px;
  226. margin-top: 20px;
  227. > div {
  228. flex: 1;
  229. padding: 15px;
  230. box-sizing: border-box;
  231. max-height: 500px;
  232. overflow-y: auto;
  233. }
  234. > div:last-child {
  235. border-left: 1px solid #ccc;
  236. }
  237. }
  238. </style>