jp-office-select.vue 2.8 KB

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