user-select-dialog.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 = "checkOnlyLeaf"
  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. this.$refs.userTree.setCheckedKeys(keys);
  84. }
  85. })
  86. },
  87. methods:{
  88. setTreeList (datas) { // 遍历树 获取id数组
  89. for (var i in datas) {
  90. this.treeList.push(datas[i])
  91. if (datas[i].children) {
  92. this.setTreeList(datas[i].children)
  93. }
  94. }
  95. },
  96. selectUsers () {
  97. let ids = this.$refs.userTree.getCheckedNodes().filter((item)=>{
  98. return item.type === 'user'
  99. }).map((item)=>{
  100. return item.id
  101. }).join(",");
  102. let names = this.$refs.userTree.getCheckedNodes().filter((item)=>{
  103. return item.type === 'user'
  104. }).map((item)=>{
  105. return item.label
  106. }).join(",");
  107. this.labels = names
  108. this.$emit('doSubmit', ids)
  109. this.hideModal()
  110. },
  111. showModal() {
  112. this.modalName = "bottomModal"
  113. },
  114. hideModal() {
  115. this.modalName = null
  116. }
  117. }
  118. }
  119. </script>