index.vue 6.8 KB

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