user-select-dialog.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view>
  3. <view class="cu-modal bottom-modal" style="min-height: 200upx;" :class="modalName=='bottomModal'?'show':''">
  4. <view class="cu-dialog">
  5. <view class="cu-bar bg-white">
  6. <view class="action text-blue" @tap="hideModal">取消</view>
  7. <view class="action text-green" @tap="selectUsers">确定</view>
  8. </view>
  9. <view>
  10. <ly-tree :tree-data="data"
  11. :props="props"
  12. node-key="id"
  13. :checkOnClickNode ="true"
  14. :showRadio="showRadio"
  15. :show-checkbox ="showCheckBox"
  16. :checkOnlyLeaf = "true"
  17. ref="userTree" />
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import userService from "@/api/sys/userService"
  25. export default {
  26. data() {
  27. return {
  28. data: [],
  29. modalName: null,
  30. labels: null,
  31. treeList: []
  32. };
  33. },
  34. props: {
  35. limit: Number,
  36. value: String,
  37. size: String,
  38. readonly: {
  39. type: Boolean,
  40. default: () => { return false }
  41. },
  42. checkOnlyLeaf: {
  43. type: Boolean,
  44. default: () => { return false }
  45. },
  46. showRadio: {
  47. type: Boolean,
  48. default: () => { return false }
  49. },
  50. showCheckBox: {
  51. type: Boolean,
  52. default: () => { return true }
  53. },
  54. disabled: {
  55. type: Boolean,
  56. default: () => { return false }
  57. },
  58. props: {
  59. type: Object,
  60. default: () => {
  61. return {
  62. children: 'children',
  63. label: 'label'
  64. }
  65. }
  66. }
  67. },
  68. mounted() {
  69. userService.treeData().then((data)=>{
  70. this.data = data
  71. this.setTreeList(this.data)
  72. let labelArra = []
  73. if(this.value){
  74. let keys = this.value.split(',')
  75. keys.forEach((id) => {
  76. this.treeList.forEach((node) => {
  77. if (id === node.id) {
  78. labelArra.push(node.label)
  79. }
  80. })
  81. })
  82. this.labels = labelArra.join(',')
  83. }
  84. })
  85. },
  86. methods:{
  87. setTreeList (datas) { // 遍历树 获取id数组
  88. for (var i in datas) {
  89. this.treeList.push(datas[i])
  90. if (datas[i].children) {
  91. this.setTreeList(datas[i].children)
  92. }
  93. }
  94. },
  95. selectUsers () {
  96. let ids = this.$refs.userTree.getCheckedNodes().filter((item)=>{
  97. return item.type === 'user'
  98. }).map((item)=>{
  99. return item.id
  100. }).join(",");
  101. let names = this.$refs.userTree.getCheckedNodes().filter((item)=>{
  102. return item.type === 'user'
  103. }).map((item)=>{
  104. return item.label
  105. }).join(",");
  106. this.labels = names
  107. this.$emit('doSubmit', ids)
  108. this.hideModal()
  109. },
  110. showModal() {
  111. this.modalName = "bottomModal"
  112. },
  113. hideModal() {
  114. this.modalName = null
  115. }
  116. }
  117. }
  118. </script>