jp-office-select.vue 2.6 KB

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