dingDepartUser.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { getDingTalkAllDeptUser, refashDingTalkAllDeptUser } from '@/api/expenseManagement'
  2. const DingDepartUser = {
  3. template: `
  4. <a-tree-select
  5. :value="defaultVal"
  6. tree-data-simple-mode
  7. style="width: 100%"
  8. :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
  9. :tree-data="treeData"
  10. :placeholder="placeholder"
  11. multiple
  12. treeCheckable
  13. :treeCheckStrictly="true"
  14. treeNodeFilterProp="title"
  15. @change="handleChange"
  16. />
  17. `,
  18. props: {
  19. value: {
  20. type: Array,
  21. defatut: function(){
  22. return []
  23. }
  24. },
  25. id: {
  26. type: String,
  27. default: ''
  28. },
  29. placeholder: {
  30. type: String,
  31. default: '请选择人员'
  32. },
  33. disabled:{
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. data() {
  39. return {
  40. defaultVal: this.value,
  41. treeData: []
  42. };
  43. },
  44. mounted() {
  45. this.genTreeNode()
  46. },
  47. watch: {
  48. value(newValue, oldValue) {
  49. this.defaultVal = newValue
  50. },
  51. },
  52. methods: {
  53. filterOption (input, option) {
  54. return (
  55. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  56. )
  57. },
  58. handleChange(value) {
  59. this.defaultVal = value;
  60. this.$emit('change', value, this.id);
  61. this.$emit('input', value);
  62. },
  63. // 格式化数据
  64. formatData(data){
  65. console.log(data)
  66. const ret = []
  67. data.map(item => {
  68. // 部门
  69. if(item.deptId){
  70. const node = {
  71. title: item.name,
  72. id:item.deptId,
  73. value: item.deptId,
  74. pId: item.parentId,
  75. autoAddUser: item.autoAddUser,
  76. createDeptGroup: item.createDeptGroup,
  77. disableCheckbox: true,
  78. checkable: false,
  79. children: []
  80. }
  81. if(item.deptUserList && item.deptList){
  82. node.children = this.formatData(item.deptList.concat(item.deptUserList?item.deptUserList:[]))
  83. }else if(item.deptUserList && !item.deptList){
  84. node.children = this.formatData(item.deptUserList)
  85. }else if(!item.deptUserList && item.deptList){
  86. node.children = this.formatData(item.deptList)
  87. }
  88. ret.push(node)
  89. }else{
  90. ret.push({
  91. title: item.name,
  92. id: item.userid,
  93. value: item.userid,
  94. pId: item.parentId,
  95. avatar: item.avatar,
  96. leader: item.leader,
  97. boss: item.boss,
  98. admin: item.admin,
  99. active: item.active,
  100. userid: item.userid,
  101. isLeaf: true
  102. })
  103. }
  104. })
  105. return ret
  106. },
  107. // 获取部门人员
  108. async genTreeNode() {
  109. let ret = await getDingTalkAllDeptUser().then(res => res.data)
  110. const res1 = ret.deptList||[]
  111. const res2 = ret.deptUserList||[]
  112. this.treeData = this.treeData = this.formatData(res1.concat(res2));
  113. console.log(this.treeData,'----')
  114. },
  115. // 更新人员数据
  116. updateDeptUser(){
  117. const _this = this
  118. refashDingTalkAllDeptUser().then(res => {
  119. if(res.status == 200){
  120. // this.treeData = []
  121. // this.genTreeNode()
  122. const h = this.$createElement;
  123. this.$info({
  124. title: '提示',
  125. centered: true,
  126. content: h('div', {}, [
  127. h('p', '数据正在刷新中...'),
  128. h('p', '请10分钟后(按F5刷新页面)再进行操作!'),
  129. ]),
  130. onOk() {
  131. _this.$emit("close")
  132. },
  133. });
  134. }else{
  135. this.$message.error(res.message)
  136. }
  137. this.$emit("loaded")
  138. })
  139. }
  140. },
  141. };
  142. export default DingDepartUser