123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <template>
- <div class="selectButton">
- <div class="selectButton-div">
- <slot>
- <el-select v-model="selectValue" :placeholder="placeholder" :size="size"
- :clearable="clearable" :disabled="disabled" :multiple="multiple" :filterable="filterable" @change="change">
- <el-option v-for="(item,index) in optionArr" :key="'myButton'+ index" :label="item[prop.label]" :value="item[prop.value]">
- </el-option>
- </el-select>
- </slot>
-
- <el-button @click="handleClick" type="primary" :disabled="disabled" :size="size" class="selectButton-button">
- <slot name="button">
- <i class="el-icon-search"></i>
- </slot>
-
- </el-button>
- </div>
-
- </div>
- </template>
- <script>
- export default {
- props: {
- // 数据源(选择)
- optionArr: {
- type: Array,
- default: ()=>[],
- },
- prop: {
- default: () => {
- return {
- label: 'label',
- value:'value'
- }
- }
-
- },
- //v-model传过来的值(双向绑定的值)
- value: {
- default:''
- },
- // 尺寸
- size: {
- type: String,
- default: 'small'
- },
- // 提示内容
- placeholder: {
- type: String,
- default: ''
- },
- // 单选清空或不清空
- clearable: {
- type: Boolean,
- default: false
- },
- // 是否禁用
- disabled: {
- type: Boolean,
- default: false
- },
- // 多选
- multiple: {
- type: Boolean,
- default: false
- },
- // 是否可搜索
- filterable: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- selectValue: this.value
- }
- },
- watch: {
- },
- mounted() {
- this.init()
- },
- methods: {
- //初始化
- init() {
- // if (this.multiple) {
- // if (typeof this.value == 'object') {
-
- // } else {
- // this.selectValue = []
- // this.selectValue.push(this.value)
- // console.log('不是Array');
- // }
- // } else {
- // if (typeof this.value == 'string') {
-
- // } else {
- // this.selectValue = ''
- // this.selectValue = this.value
- // console.log('不是String');
- // }
- // }
- },
- //切换下拉框的值
- change(val) {
- this.$emit('input', val)
- },
- // 按钮点击事件
- handleClick(e) {
- this.$emit('click', e)
- },
- },
- }
- </script>
- <style lang="scss">
- .selectButton {
- .el-select {
- display: inline-block;
- position: relative;
- width: 100%;
- }
- .el-input__inner {
- color: #606266 !important;
- border-radius: 5px 0px 0px 5px;
- }
- }
- </style>
- <style lang="scss" scoped>
- .selectButton {
- .selectButton-div {
- width: calc(100%);
- display: flex;
- align-items: center;
- }
- .selectButton-button {
- border-radius: 0px 5px 5px 0px;
- }
- }
- </style>
|