ElementUi 组织机构封装组件问题

效果:

组件:

<template>
  <el-popover
    v-model="visible"
    :disabled="disabled"
    trigger="focus"
    :visible-arrow="false"
    placement="bottom"
    @after-leave="inputIsFocus = false"
  >
    <div style="overflow-y: auto; height: 600px">
      <el-tree
        ref="tree"
        :data="data"
        :props="defaultProps"
        node-key="id"
        :highlight-current="true"
        :expand-on-click-node="false"
        :default-expand-all="true"
        @node-click="nodeClick"
      />
    </div>
    <el-input
      slot="reference"
      :suffix-icon="disabled?'':inputIsFocus?'el-icon-arrow-up':'el-icon-arrow-down'"
      :value="orgUnitName"
      :disabled="disabled"
      @focus="disabled?'':inputIsFocus = true"
    />
  </el-popover>

</template>
<script>

import { construct } from '@aximario/json-tree'
import { listOrg } from '@/service/global'
import { mapOrg } from '@/service/global'

export default {
  name: 'OrgSelect',
  props: {
    value: {
      type: String,
      default: function() {
        return ''
      }
    },
    disabled: {
      type: Boolean,
      default: function() {
        return false
      }
    }
  },
  data() {
    return {
      visible: false,
      defaultProps: {
        children: 'children',
        label: 'orgUnitName'
      },
      inputIsFocus: false,
      orgUnitName: '',
      data: [],
      orgMap: []
    }
  },
  methods: {
    init() {
      this.loadOrgTreeData()
    },
    loadOrgTreeData() {
      const _this = this
      listOrg(this.$http, {}).then(result => {
        _this.data = construct(result, {
          id: 'orgUnitId',
          pid: 'parentId',
          children: 'children'
        })
      })
    },
    getSelectName() {
      const _this = this
      mapOrg(this.$http).then(result => {
        _this.orgMap = result
        _this.orgUnitName = _this.orgMap[_this.value]
        _this.$refs['tree'].setCurrentKey(_this.value)
      })
    },
    nodeClick() {
      const current = this.$refs['tree'].getCurrentNode()
      this.orgUnitName = current.orgUnitName
      this.$emit('update:value', current.orgUnitCode)
    },
    clear() {
      this.orgUnitName = ''
      this.$emit('update:value', '')
    }
  }
}
</script>

<style scoped>

</style>

页面引用:

import OrgSelect from '@/components/org-select'

页面使用:

<org-select ref="orgSelect" :value.sync="searchForm.affiliatedUnit"/>

初始化数据:

this.$refs.orgSelect.init()

详情:this.$refs.orgSelect.getSelectName()

清空:this.$refs.orgSelect.clear()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值