6793c07beef782c7e729d779764eb08382f26690.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 { queryDepartTreeList, searchByKeywords } from '@/api/api'
  19. export default {
  20. name: 'AddressListLeft',
  21. props: ['value'],
  22. data() {
  23. return {
  24. cardLoading: true,
  25. loading: false,
  26. treeDataSource: [],
  27. selectedKeys: [],
  28. expandedKeys: []
  29. }
  30. },
  31. created() {
  32. this.queryTreeData()
  33. },
  34. methods: {
  35. queryTreeData(keyword) {
  36. this.commonRequestThen(queryDepartTreeList({
  37. departName: keyword ? keyword : undefined
  38. }))
  39. },
  40. handleSearch(value) {
  41. if (value) {
  42. this.commonRequestThen(searchByKeywords({ keyWord: value }))
  43. } else {
  44. this.queryTreeData()
  45. }
  46. },
  47. handleTreeSelect(selectedKeys, event) {
  48. if (selectedKeys.length > 0 && this.selectedKeys[0] !== selectedKeys[0]) {
  49. this.selectedKeys = [selectedKeys[0]]
  50. let orgCode = event.node.dataRef.orgCode
  51. this.emitInput(orgCode)
  52. }
  53. },
  54. emitInput(orgCode) {
  55. this.$emit('input', orgCode)
  56. },
  57. commonRequestThen(promise) {
  58. this.loading = true
  59. promise.then(res => {
  60. if (res.success) {
  61. this.treeDataSource = res.result
  62. // update-begin- --- author:wangshuai ------ date:20200102 ---- for:去除默认选中第一条数据、默认展开所有第一级
  63. // 默认选中第一条数据、默认展开所有第一级
  64. // if (res.result.length > 0) {
  65. // this.expandedKeys = []
  66. // res.result.forEach((item, index) => {
  67. // if (index === 0) {
  68. // this.selectedKeys = [item.id]
  69. // this.emitInput(item.orgCode)
  70. // }
  71. // this.expandedKeys.push(item.id)
  72. // })
  73. // }
  74. // update-end- --- author:wangshuai ------ date:20200102 ---- for:去除默认选中第一条数据、默认展开所有第一级
  75. } else {
  76. this.$message.warn(res.message)
  77. console.error('组织机构查询失败:', res)
  78. }
  79. }).finally(() => {
  80. this.loading = false
  81. this.cardLoading = false
  82. })
  83. },
  84. }
  85. }
  86. </script>
  87. <style scoped>
  88. </style>