audit-company-select.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <SdTreePicker
  3. v-bind="pickerMixinProps"
  4. :load-tree-data="loadTreeData"
  5. :default-expanded-keys="defaultExpandedKeys"
  6. option-value="code"
  7. :search-tree-data="searchTreeData"
  8. :render="(item, direction) => renderItem(item, direction)"
  9. @change="change"
  10. ><a-icon v-if="!readOnly" slot="suffixIcon" type="apartment" />
  11. </SdTreePicker>
  12. </template>
  13. <script>
  14. import AddressBook from '@/addressbook/group-user-service'
  15. import pickerMixin from '@/common/components/sd-picker/picker-mixin'
  16. import SdTreePicker from '@/common/components/sd-tree-picker.vue'
  17. /**
  18. * 组织选择器
  19. * @displayName SdGroupPicker 组织选择器
  20. */
  21. export default {
  22. name: 'AuditCompanySelect',
  23. components: {
  24. SdTreePicker,
  25. },
  26. mixins: [pickerMixin],
  27. props: {
  28. /**
  29. * 根节点{code:'200000',name:'西安分公司'}
  30. */
  31. rootNode: {
  32. type: [Object, Array],
  33. default: undefined,
  34. },
  35. /**
  36. * 默认展开的节点['200000']
  37. */
  38. defaultExpandedKeys: {
  39. type: Array,
  40. default: undefined,
  41. },
  42. /**
  43. * 当开启分级授权时,是否过滤掉启用分级授权的子公司,true时过滤,false时不过滤
  44. *
  45. */
  46. hierarchical: {
  47. type: Boolean,
  48. default: undefined,
  49. },
  50. },
  51. methods: {
  52. loadTreeData(id) {
  53. if (!id) {
  54. const expandedKey = this.defaultExpandedKeys
  55. if (Array.isArray(this.rootNode) && this.rootNode.length) {
  56. return Promise.all(
  57. this.rootNode.map((rootNode) => {
  58. return AddressBook.getGroupTree({
  59. expandedKey,
  60. rootNode,
  61. hierarchical: this.hierarchical,
  62. levPath: true,
  63. })
  64. })
  65. ).then((nodes) => {
  66. return nodes.map((node) => node[0])
  67. })
  68. } else {
  69. return AddressBook.getGroupTree({
  70. expandedKey,
  71. rootNode: this.rootNode,
  72. hierarchical: this.hierarchical,
  73. levPath: true,
  74. })
  75. }
  76. } else {
  77. return AddressBook.getChildNodes(id, {
  78. type: 'G',
  79. isContainSub: false,
  80. hierarchical: this.hierarchical,
  81. levPath: true,
  82. }).then((res) => {
  83. return res.map((item) => {
  84. item.checkable = true
  85. return item
  86. })
  87. })
  88. }
  89. },
  90. searchTreeData(searchValue) {
  91. if (searchValue) {
  92. return AddressBook.groupsQuery(searchValue, {
  93. levPath: true,
  94. hierarchical: this.hierarchical,
  95. }).then((data) => {
  96. return data
  97. })
  98. }
  99. },
  100. renderItem(item, direction) {
  101. return <span title={item.name}>{item.name.split('/').pop()}</span>
  102. },
  103. change(value) {
  104. this.$emit(
  105. 'change',
  106. value?.map((item) => {
  107. return {
  108. name: item.name,
  109. code: item.code,
  110. type: item.type,
  111. orgCode: item.props?.code || item.orgCode,
  112. }
  113. })
  114. )
  115. },
  116. },
  117. }
  118. </script>
  119. <style module lang="scss">
  120. @use '@/common/design' as *;
  121. </style>