dingDepartUser.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. console.log(value);
  60. this.defaultVal = value;
  61. this.$emit('change', value, this.id);
  62. this.$emit('input', value);
  63. },
  64. // 格式化数据
  65. formatData(data){
  66. console.log(data)
  67. const ret = []
  68. data.map(item => {
  69. // 部门
  70. if(item.deptId){
  71. const node = {
  72. title: item.name,
  73. id:item.deptId,
  74. value: item.deptId,
  75. pId: item.parentId,
  76. autoAddUser: item.autoAddUser,
  77. createDeptGroup: item.createDeptGroup,
  78. disableCheckbox: true,
  79. checkable: false,
  80. children: []
  81. }
  82. if(item.deptUserList && item.deptList){
  83. node.children = this.formatData(item.deptList.concat(item.deptUserList?item.deptUserList:[]))
  84. }else if(item.deptUserList && !item.deptList){
  85. node.children = this.formatData(item.deptUserList)
  86. }else if(!item.deptUserList && item.deptList){
  87. node.children = this.formatData(item.deptList)
  88. }
  89. ret.push(node)
  90. }else{
  91. ret.push({
  92. title: item.name,
  93. id: item.deptOrder,
  94. value: item.userid,
  95. pId: item.parentId,
  96. avatar: item.avatar,
  97. leader: item.leader,
  98. boss: item.boss,
  99. admin: item.admin,
  100. active: item.active,
  101. userid: item.userid,
  102. isLeaf: true
  103. })
  104. }
  105. })
  106. return ret
  107. },
  108. // 获取部门人员
  109. async genTreeNode() {
  110. let ret = await getDingTalkAllDeptUser().then(res => res.data)
  111. const res1 = ret.deptList||[]
  112. const res2 = ret.deptUserList||[]
  113. this.treeData = this.treeData = this.formatData(res1.concat(res2));
  114. console.log(this.treeData,'----')
  115. },
  116. // 更新人员数据
  117. updateDeptUser(){
  118. const _this = this
  119. refashDingTalkAllDeptUser().then(res => {
  120. if(res.status == 200){
  121. // this.treeData = []
  122. // this.genTreeNode()
  123. const h = this.$createElement;
  124. this.$info({
  125. title: '提示',
  126. centered: true,
  127. content: h('div', {}, [
  128. h('p', '数据正在刷新中...'),
  129. h('p', '请10分钟后(按F5刷新页面)再进行操作!'),
  130. ]),
  131. onOk() {
  132. _this.$emit("close")
  133. },
  134. });
  135. }else{
  136. this.$message.error(res.message)
  137. }
  138. this.$emit("loaded")
  139. })
  140. }
  141. },
  142. };
  143. export default DingDepartUser