liuxiaolong
2019-05-06 770c069996e1d2979c1170c1639c18b02d07e72f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
  <div class="select-king" ref="selectKing">
    <!-- <el-input v-model="selectVal" @focus="isShowOptions=true"  :placeholder="placeholder" :readonly="true">
        <i slot="suffix" v-show="!isShowOptions" class="el-input__icon fas fa-angle-down"></i>
        <i slot="suffix" v-show="isShowOptions" class="el-input__icon fas fa-angle-up"></i>
    </el-input>-->
    <!-- <div class="select-king-options-bg" v-show="isShowOptions" @click="isShowOptions=false"></div> -->
    <!-- <div class="select-king-options " v-show="isShowOptions">
        <div class="border px-1 my-1 bg-white options">
          <slot></slot>
        </div>
    </div>-->
    <el-select
      :title="value"
      v-model="value"
      :disabled="disabled"
      ref="select"
      @focus="isShowOptions=true"
      @blur="isShowOptions=false"
      :placeholder="placeholder"
      @visible-change="(value)=>{$emit('visible-change',value)}"
    >
      <el-option value class="select-king-options" :style="optionsWidth?`width:${optionsWidth}`:''">
        <div @click.stop>
          <slot></slot>
        </div>
      </el-option>
    </el-select>
  </div>
</template>
<script>
import { Select, Option, Input } from 'element-ui'
export default {
  name: 'selectKing',
  components: {
    elInput: Input,
    elSelect: Select,
    elOption: Option
  },
  data() {
    return {
      // selectVal: '',
      isShowOptions: false
    }
  },
  props: {
    value: {
      default: '',
      type: String
    },
    placeholder: {
      default: '请选择',
      type: String
    },
    optionsWidth: {
      default: '',
      type: String
    },
    disabled: {
      default: false,
      type: Boolean
    }
  },
  computed: {
    orgId() {
      return this.$store.getters.basicUserInfo.orgId
    }
  },
  methods: {
    setVal(item) {
      // console.log(item, 'select-king-setVal')
      // this.$emit('change', this.isLock)
    },
    close() {
      this.$refs.select.blur()
    },
    targetClose(ev) {
      let target = ev.target
      while (target !== this.$refs.selectKing && target !== document.body) {
        target = target.parentNode
      }
      if (target !== this.$refs.selectKing) {
        this.isShowOptions = false
      }
    }
  },
  mounted() {
    /* 空白关闭函数 start */
    // document.body.addEventListener('click', this.targetClose)
    /* 空白关闭函数 end */
  },
  destroyed() {
    // document.body.removeEventListener('click', this.targetClose)
  }
}
</script>
<style lang="scss" scoped>
// .select-king {
.select-king-options {
  &.el-select-dropdown__item {
    height: auto;
    padding: 0;
    cursor: inherit;
  }
  &.el-select-dropdown__item.hover,
  &.el-select-dropdown__item:hover {
    background: transparent !important;
  }
  &.el-select-dropdown__item.selected {
    color: #606266;
    font-weight: normal;
  }
}
// }
</style>