Files
GX.O3.WMS/APK/APP_O3/components/xfl-select/xfl-select.vue
T

400 lines
13 KiB
Vue
Executable File

<template>
<div class="show-box" :class="{disabled: disabled, active: isShowList}" :style="style_Container">
<view class="gary-layer" v-if="showGaryLayer" @click="hideLayer"></view>
<!-- 显示框 -->
<!-- <div class="div_input" :class="{placeholder: selectText === placeholder||selectText ==='无数据'}" @click="onUpperClick" style="height: 60rpx;">
{{selectText}}
</div> -->
<input class="div_input" :disabled="!isCanInput" @click="onUpperClick" @input="fuzzySearch" v-model="selectText"
:class="{placeholder: selectText === placeholder||selectText ==='无数据'}" style="height: 60rpx;"/>
<!-- 右侧的小三角图标 -->
<span
@click="onUpperClick"
class="iconfont iconarrowBottom-fill right-arrow"
:class="{isRotate: isRotate}">
</span>
<!-- 清除按钮图标 -->
<span v-if="clearable && selectText && selectText != placeholder"
class="right-arrow" @click="onClear" >
<span class="iconfont iconshanchu1 clear"></span>
</span>
<!-- 列表框 -->
<div class="list-container" style="z-index: 99999;"
:style="'top:' + listTop__ + 'rpx;'" v-show="isShowListA">
<span class="popper__arrow"></span> <!-- 列表框左上角的空心小三角 -->
<scroll-view
class="list" style="background-color: #fff;"
:style="'height: ' + boxHeight +'em;'"
scroll-y=true scroll-x=true>
<div
class="item" @click="onClickItem(index, item.value)"
v-for="(item, index) in list" :key="index"
:class="{active: activeIndex == index, disabled: item.disabled}">
<div>{{item.value}}</div>
</div>
<div v-show="list.length==0" class="data-state item" @click="noDataClick">无数据</div>
</scroll-view>
</div>
</div>
</template>
<script>
export default {
name: 'xfl-select',
props: {
listOrigin: { // 原始列表数据
type: Array,
default: function(){
return [];
}
},
list: { // 原始数据
type: Array,
default: function(){
return [];
}
},
focusShowList: null, // 当input获取焦点时,是否自动弹出列表框
initValue: null, // 选择框的初始值
isCanInput: { // 选择框是否可以输入值
type: Boolean,
default: false,
},
selectHideType: { // 本选择框与其它选择框之间的关系
type: String,
default: 'hideAll', // 'independent' - 是独立的,与其它选择框互不影响 'hideAll' - 任何一个选择框展开时,隐藏所有其它选择框
// 'hideOthers'- 当本选择框展开时,隐藏其它的选择框。 当其它选择框展开时,不隐藏本选择框。
// 'hideSelf' - 当本选择框展开时,不隐藏其它的选择框。当其它选择框展开时,隐藏本选择框。
},
placeholder: { // 选择框的placeholder
type: String,
default: '请选择',
},
style_Container: { // 最外层的样式
type: String,
default: ''
},
disabled: { // 是否禁用整个选择框
type: Boolean,
default: false,
},
showItemNum: { // 显示列表框的窗口高度,数字表示能显示几个列表项
type: Number,
default: 5
},
listShow: { // 是否显示列表框
type: Boolean,
default: false
},
clearable: { // 是否显示右侧的清除按钮
type: Boolean,
default: true
},
defaultSelectText:{
type:String,
default:''
},
},
mounted(){
if(this.defaultSelectText && this.defaultSelectText.length>0) {
this.selectText = this.defaultSelectText;
}
},
data() {
return {
showGaryLayer:false,
isShowListA:false,
boxHeight:1,
isShowList: false, // 是否显示列表框
selectText: '', // 已经选择的内容
activeIndex: -1, // 列表中当前活动的索引号
isRotate: false, // 右侧的小三角是否旋转
listTop__: 70, // 列表框的top位置,在初始时,根据input节点的高度来调整
};
},
computed:{},
watch:{
selectText(newVal,oldVal){
//console.log(this.selectText)
}
},
activated() {
console.log(this.list)
},
methods:{
fuzzySearch(){
let _self = this;
let tempList = this.listOrigin;
this.list = tempList.filter(e => {
return e.value.includes(_self.selectText)
})
console.log(this.list)
},
hideLayer(){
this.showGaryLayer = false;
this.isShowListA = false;
},
noDataClick(){
this.isShowList = false;
this.isShowListA = false;
},
onUpperClick(){
if(this.disabled){
return;
}
if(this.listOrigin.length<1){
this.boxHeight = 2;
this.isShowListA = false;
this.showGaryLayer = false;
}
if(this.listOrigin.length>=1 && this.listOrigin.length<=5){
let itemBox = this.listOrigin.length;
this.boxHeight = itemBox*2;
this.isShowListA = !this.isShowListA;
this.showGaryLayer = true;
}
if(this.listOrigin.length>5){
this.boxHeight = 10;
this.isShowListA = !this.isShowListA;
this.showGaryLayer = true;
}
this.isShowList = !this.isShowList;
},
onClickItem(index, value){ // 列表项上的点击事件
if( !this.itemIsActive(index) ){ //如果点在非选中项上
this.clearItemActive(); // 清空其它的选中的列表项
this.setItemActive(index, value); // 将这一项设置为选中项
this.$emit('change', {newVal: value, oldVal: this.selectText,
index: index, orignItem: this.list[index]});
this.selectText = value;
this.isShowList = false;
this.isShowListA = false;
}
if( this.itemIsActive(index) ){ //如果点在选中项上
this.clearItemActive(); // 清空其它的选中的列表项
this.setItemActive(index, value); // 将这一项设置为选中项
this.$emit('change', {newVal: value, oldVal: this.selectText,
index: index, orignItem: this.list[index]});
this.selectText = value;
this.isShowList = false;
this.isShowListA = false;
}
this.showGaryLayer = false;
},
itemIsActive(index){ // 某个列表项是否是被选中的(活动的)
return index === this.activeIndex;
},
setItemActive(index, value){ //选中某一项,必须传入索引和对应的值
this.activeIndex = index;
},
clearItemActive(index = -1){ // 设置为不选中
if(index < 0){ // 清空全部
this.activeIndex = -1;
}
},
}
}
</script>
<style scoped lang="less">
@normal-color: #606266; //正常情况下的字体颜色
@hover-color: #c0c4cc; //边框的颜色
@active-color: #409eff; //活动的颜色
@mouse-move-color: #f5f7fa; //在列表项上按下时的列表项的背景色
@arrowWidth: 12%;
.placeholder11{
color: red; top: 10px;
}
.gary-layer{
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #585858;
opacity: 0;
z-index: 9999;
}
.show-box{
height: 60rpx;
position: relative;
text-align: left;
-webkit-appearance: none;
background-color: #fff;
background-image: none;
border-radius: 4px;
border: 1px solid @hover-color;
box-sizing: border-box;
color: @normal-color;
display: inline-block;
font-size: inherit;
&.active{
border-color: @active-color;
}
// &:hover{
// border-color: @normal-color;
// &.active{
// border-color: @active-color;
// }
// }
&.disabled{
background-color: #f0f0f0;
}
height: 100%;
line-height: inherit;
outline: none;
padding: 0 0 0 0;
transition: border-color .2s cubic-bezier(.645,.045,.355,1);
width: 100%;
.input{
width: 100%; height: 100%;
display: flex; align-items: center; justify-content: flex-start;
}
.div_input{
width: 100%; height: 100%;
font-size: 32rpx;
display: flex;
align-items: center;
justify-content: flex-start;
margin-right: @arrowWidth;
flex-wrap: nowrap;
padding-left: 24rpx;
border: none;
}
.placeholder{
color: #bbb;
}
//*************************** 右侧的小箭头 ***************************
.right-arrow{
&.isRotate{
transform: rotate(180deg);
}
transition: transform .2s cubic-bezier(.645,.045,.355,1);
position: absolute; font-size: 1em; right: 0px; display: flex;
top: 0;
align-items: center; color: @hover-color; height: 100%;
font-weight: 100; width: @arrowWidth; justify-content: center;
}
.clear{
color: #fff; line-height: 1;
background-color: @hover-color; border-radius: 50%; padding: 2px;
}
/****** 列表框部分样式 *****/
.list-container{
position: absolute; width: 100%; left: 0; top: 50px;
box-sizing: border-box; z-index: 100;
//*************************** 弹出框上面的小三角 ***************************
.popper__arrow{
transform: translateX(-400%);
position: absolute;
display: block;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 6px;
filter: drop-shadow(0 2px 12px rgba(0,0,0,.03));
left: 30%;
margin-right: 3px;
border-top-width: 0;
border-bottom-color: #dcdfe6;
top: -5px;
&:after{
content: " ";
border-width: 6px;
position: absolute;
display: block;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
top: 1px;
margin-left: -6px;
border-top-width: 0;
border-bottom-color: #fff;
}
}
.list{
font-size: 32rpx;
border-radius: 4px;
border: 1px solid #dcdfe6;
width: 100%;
max-height: 10em;
background-color: #fff;
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
padding: 5rpx 0;
//*************************** 弹出框中每一项样式 ***************************
.item{
&:hover{
background-color: @mouse-move-color;
&.disabled{
background-color: transparent;
}
}
&.active{
color: @active-color;
font-weight: 500;
background-color: @mouse-move-color;
}
&.disabled{
color: @hover-color;
}
padding: 0 5rpx;
line-height: 2;
}
.data-state{
color: @hover-color;
}
}
}
}
.mask_div{
background-color: #FFFFFF00;
width: 100%;
height: 100%;
position: absolute;
z-index: 100;
left: 0;
right: 0;
top: 0;
}
//************************************** 以下为字体 ****************************************
@font-face {font-family: "iconfont";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JJVEHqyf9hcio6x0UUjmAfOg9iHUvl4xmjRJjBjBI4IC7NAxZVgBi87Ae0liqHZGIKhluZKD6dH2j+8Jd0AY9MUcVKXLU5I9a6XU7FUcUppMkCss5MAeXmM7a3Q4A') format('woff')
}
.iconfont {
font-family: "iconfont" !important;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.iconshanchu1:before {
content: "\e68c";
}
.icongou:before {
content: "\e786";
}
.iconarrowBottom-fill:before {
content: "\e60e";
}
</style>