dictionaryInfoLeft.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <a-card :loading="cardLoading" :bordered="false" style="height: 100%;">
  3. <a-spin :spinning="loading">
  4. <!-- <a-input-search @search="handleSearch" style="width:100%;margin-top: 10px" placeholder="输入字典名称查询..." enterButton />-->
  5. <a-tree
  6. showLine
  7. checkStrictly
  8. :expandedKeys.sync="expandedKeys"
  9. :selectedKeys="selectedKeys"
  10. :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
  11. :treeData="treeDataSource"
  12. @select="handleTreeSelect"
  13. />
  14. </a-spin>
  15. </a-card>
  16. </template>
  17. <script>
  18. import { queryBusDictTreeList } from '@/api/api'
  19. export default {
  20. name: 'dictionaryInfoLeft',
  21. props: ['value'],
  22. data() {
  23. return {
  24. cardLoading: true,
  25. loading: false,
  26. treeDataSource: [],
  27. selectedKeys: [],
  28. expandedKeys: [],
  29. dictId:''
  30. }
  31. },
  32. created() {
  33. this.queryTreeData()
  34. },
  35. methods: {
  36. queryTreeData(keyword) {
  37. console.log('获取数据')
  38. let storeInfo = JSON.parse(localStorage.getItem("storeInfo"))
  39. this.commonRequestThen(queryBusDictTreeList({
  40. departName: keyword ? keyword : undefined,
  41. ids: this.dictId ? this.dictId : undefined,
  42. hotelId: storeInfo ? storeInfo.id : undefined
  43. }))
  44. },
  45. // handleSearch(value) {
  46. // if (value) {
  47. // this.commonRequestThen(searchByKeywords({ keyWord: value }))
  48. // } else {
  49. // this.queryTreeData()
  50. // }
  51. // },
  52. handleTreeSelect(selectedKeys, event) {
  53. console.log(event.node.dataRef)
  54. //update-begin---author:wangshuai ---date:20220107 for:[JTC-378]通讯录 选中某个部门查询部门人员,想再取消选中查全部,无法取消,只能重新刷新界面------------
  55. if (selectedKeys.length > 0 && event.node.dataRef.parentId != '') {
  56. if(this.selectedKeys[0] !== selectedKeys[0]){
  57. this.selectedKeys = [selectedKeys[0]]
  58. let dictId = event.node.dataRef.id
  59. localStorage.setItem("dictId", dictId)
  60. this.dictId = dictId
  61. this.emitInput(dictId)
  62. }
  63. }else{
  64. this.selectedKeys = []
  65. this.emitInput("")
  66. localStorage.removeItem("dictId")
  67. }
  68. //update-end---author:wangshuai ---date:20220107 for:[JTC-378]通讯录 选中某个部门查询部门人员,想再取消选中查全部,无法取消,只能重新刷新界面------------
  69. },
  70. emitInput(id) {
  71. this.$emit('input', id)
  72. },
  73. commonRequestThen(promise) {
  74. this.loading = true
  75. promise.then(res => {
  76. if (res.success) {
  77. this.treeDataSource = res.result
  78. // update-begin- --- author:wangshuai ------ date:20200102 ---- for:去除默认选中第一条数据、默认展开所有第一级
  79. // 默认选中第一条数据、默认展开所有第一级
  80. if (res.result.length > 0) {
  81. this.expandedKeys = []
  82. res.result.forEach((item, index) => {
  83. if (index === 0) {
  84. this.selectedKeys = [item.id]
  85. this.emitInput(item.orgCode)
  86. }
  87. this.expandedKeys.push(item.id)
  88. })
  89. }
  90. // update-end- --- author:wangshuai ------ date:20200102 ---- for:去除默认选中第一条数据、默认展开所有第一级
  91. } else {
  92. this.$message.warn(res.message)
  93. console.error('查询失败:', res)
  94. }
  95. }).finally(() => {
  96. this.loading = false
  97. this.cardLoading = false
  98. })
  99. },
  100. }
  101. }
  102. </script>
  103. <style scoped>
  104. </style>