dingDepartUser.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: [],
  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. key: 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.userid,
  94. value: item.userid,
  95. key:item.userid,
  96. pId: item.parentId,
  97. avatar: item.avatar,
  98. leader: item.leader,
  99. boss: item.boss,
  100. admin: item.admin,
  101. active: item.active,
  102. userid: item.userid,
  103. isLeaf: true
  104. })
  105. }
  106. })
  107. return ret
  108. },
  109. // 获取部门人员
  110. async genTreeNode() {
  111. let ret = await getDingTalkAllDeptUser().then(res => res.data)
  112. const res1 = ret.deptList||[]
  113. const res2 = ret.deptUserList||[]
  114. this.treeData = this.treeData = this.formatData(res1.concat(res2));
  115. console.log(this.treeData,'----')
  116. this.defaultVal = this.value
  117. },
  118. // 更新人员数据
  119. updateDeptUser(){
  120. const _this = this
  121. refashDingTalkAllDeptUser().then(res => {
  122. if(res.status == 200){
  123. // this.treeData = []
  124. // this.genTreeNode()
  125. const h = this.$createElement;
  126. this.$info({
  127. title: '提示',
  128. centered: true,
  129. content: h('div', {}, [
  130. h('p', '数据正在刷新中...'),
  131. h('p', '请10分钟后(按F5刷新页面)再进行操作!'),
  132. ]),
  133. onOk() {
  134. _this.$emit("close")
  135. },
  136. });
  137. }else{
  138. this.$message.error(res.message)
  139. }
  140. this.$emit("loaded")
  141. })
  142. }
  143. },
  144. };
  145. export default DingDepartUser