selectPage.vue
4.4 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!-- 选择分页 -->
<template>
<div>
<el-popover popper-class="select-page" ref="popover" placement="bottom-start" trigger="click" v-model="popoverVisible" :disabled="targetItem.isDisabled" @show="onShowPopover" @hide="onHidePopover">
<el-input v-model="searchInput" :style="{ width: width - 32 + 'px', display: 'block' }" placeholder="输入搜索" @input="handleSearchInput"></el-input>
<el-radio-group class="select-tree" v-model="form[targetItem.name]" @change="handleChangeRadio">
<el-radio class="page-radio" :style="`width: ${width - 32}px`" :title="item.merchantName" v-for="item in currList" :key="item.id" :label="item.id">{{ item.merchantName }}</el-radio>
</el-radio-group>
<div class="btns" v-show="page.total > 5">
<el-button :size="size" :disabled="page.pageNum == 1" @click="handlePage(false)">上一页</el-button>
<span>{{ page.pageNum }}/{{ page.totalPage }}</span>
<el-button :size="size" :disabled="page.pageNum == page.totalPage" @click="handlePage(true)">下一页</el-button>
</div>
<el-input slot="reference" ref="input" v-model="form[targetItem.nameLabel]" :clearable="!targetItem.noClearable" :disabled="targetItem.isDisabled" :style="`width: ${width}px`" :class="{ rotate: popoverVisible }" suffix-icon="el-icon-arrow-down" :placeholder="'请选择' + targetItem.label" @clear="handleClear"></el-input>
</el-popover>
</div>
</template>
<script>
export default {
name: 'selectPage',
data() {
return {
size: 'small',
isExpand: false,
searchInput: '',
timer: '',
// 树状菜单显示状态
popoverVisible: false,
currList: [],
tempList: [],
allMerchantList: [],
page: {
pageSize: 5,
pageNum: 1,
total: 0,
totalPage: 0
}
}
},
props: {
// 输入框宽度
width: {
type: String,
default: '360'
},
form: {
type: Object,
default: () => {}
},
targetItem: {
type: Object,
default: () => {}
},
treeData: {
type: Array,
default: () => []
}
},
mounted() {
this.getAllMerchantList()
},
methods: {
getCurrList() {
this.currList = this.tempList.slice((this.page.pageNum - 1) * this.page.pageSize, this.page.pageNum * this.page.pageSize)
},
getAllMerchantList() {
this.$apis.employee.getAllMerchantListApi({}).then(res => {
this.allMerchantList = res
this.tempList = res
this.page.total = res.length
this.page.totalPage = Math.ceil(res.length / this.page.pageSize)
this.getCurrList()
})
},
handlePage(isNext) {
this.page.pageNum = isNext ? this.page.pageNum + 1 : this.page.pageNum - 1
this.getCurrList()
},
handleChangeRadio(val) {
this.form[this.targetItem.nameLabel] = this.currList.find(item => item.id == val).merchantName
this.$emit('handleChange', val)
this.onHidePopover()
},
// 显示时触发
onShowPopover() {
this.popoverVisible = true
},
// 隐藏时触发
onHidePopover() {
this.searchInput = ''
this.handleSearchInput(this.searchInput)
this.popoverVisible = false
},
handleClear(val) {
this.form[this.targetItem.name] = ''
this.form[this.targetItem.nameLabel] = ''
this.$emit('handleChange')
},
handleSearchInput(val) {
if (this.timer) {
clearTimeout(this.timer)
}
this.timer = setTimeout(() => {
this.tempList = val ? this.allMerchantList.filter(item => new RegExp(['', ...val, ''].join('.*')).test(item.merchantName)) : this.allMerchantList
this.page.total = this.tempList.length
this.page.pageNum = 1
this.page.totalPage = Math.ceil(this.tempList.length / this.page.pageSize)
this.getCurrList()
}, 600)
}
}
}
</script>
<style>
.el-input.el-input--suffix.rotate .el-input__suffix .el-icon-arrow-down {
transform: rotate(-180deg);
}
.select-tree {
max-height: 400px;
overflow-y: scroll;
}
.page-radio {
display: block;
/* width: 320px; */
height: 36px;
line-height: 36px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.select-page {
padding-bottom: 6px;
}
.select-page .btns {
display: flex;
justify-content: space-between;
align-items: center;
}
.select-page .el-radio__input{
display: none;
}
.select-page .el-radio__label{
padding-left: 0;
}
</style>