uni-Identify-quality/uni_modules/liu-select/components/liu-select/liu-select.vue
2023-09-22 15:23:12 +08:00

276 lines
5.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view >
<view :class="['scroll-popup', isShow ? 'scroll-open' : '', animation ? 'scroll-animation' : '']">
<view class="scroll-box">
<view class="scroll-top">
<view class="scroll-top-left" @click="getResult('cancel')">取消</view>
<view class="scroll-top-right" :style="'color:'+selectBg" @click="getResult('confirm')">确定</view>
</view>
<scroll-view class="scroll-view_H" scroll-y="true">
<view class="scroll-view-grid-box" v-if="dataList.length>0">
<view v-for="(item, index) in dataList" :key="index" @click="chooseItem(item,index)"
:style="{backgroundColor:item.state?selectBg:noSelectBg}"
:class="{'card-list scroll-view-item-true':item.state,'card-list scroll-view-item':!item.state}">
<view :style="{color:item.state?selectColor:noSelectColor}">{{ item.name }}</view>
<image class="select-img" :src="selectImg" v-if="item.state"></image>
</view>
</view>
<view class="scroll-view-noBox" v-else>
<image :src="noDataImg"></image>
<view class="text">暂无数据</view>
</view>
</scroll-view>
<view v-show="safeArea" class="scroll-temp"></view>
</view>
</view>
<view v-show="isShow" class="scroll-mask" @click="isMask ? close() : ''"></view>
</view>
</template>
<script>
import noData from '../../static/noData.png'
import selectInfo from '../../static/select.png'
export default {
props: {
//是否多选
multiple: {
type: Boolean,
default: true,
},
//列表数据
list: {
type: Array
},
//选中字体颜色
selectColor: {
type: String,
default: '#FFFFFF',
},
//未选中字体颜色
noSelectColor: {
type: String,
default: '#333333',
},
//选中背景色
selectBg: {
type: String,
default: '#1890ff',
},
//未选中背景色
noSelectBg: {
type: String,
default: '#f7f7f7',
},
//是否点击阴影关闭
isMask: {
type: Boolean,
default: true,
},
//是否开启动画
animation: {
type: Boolean,
default: true,
},
//是否开启安全条
safeArea: {
type: Boolean,
default: false,
},
},
data() {
return {
dataList: this.list,
isShow: false,
noDataImg: '',
selectImg: '',
selectArr: this.list
};
},
mounted() {
this.selectImg = selectInfo
this.noDataImg = noData
},
methods: {
open() {
this.isShow = true
this.init()
},
close() {
this.isShow = false
},
init() {
this.dataList = JSON.parse(JSON.stringify(this.selectArr))
this.dataList.forEach(res => {
if (!res.state) {
res.state = false
}
})
},
//选中数据
chooseItem(item, index) {
if (this.multiple) {
item.state = !item.state
this.dataList = JSON.parse(JSON.stringify(this.dataList))
} else {
this.dataList.forEach((res, inx) => {
if (inx == index) {
res.state = !res.state
} else {
res.state = false
}
})
this.dataList = JSON.parse(JSON.stringify(this.dataList))
}
},
getResult(event) {
if (event == 'confirm') {
let result = []
this.dataList.forEach((item, index) => {
if (item.state) {
result.push(item)
}
})
this.selectArr = JSON.parse(JSON.stringify(this.dataList))
this.$emit('change', result)
}
this.close()
}
},
};
</script>
<style lang="scss" scoped>
/* 弹出层默认样式 */
.scroll-popup {
width: 750rpx;
position: fixed;
bottom: -100%;
z-index: 999;
}
/* 点击按钮是将盒子 bottom 值归零即可实现弹出效果,
同理如需更改弹出方向只需将bottom改成top、left、right即可
(默认样式的方向也需一起更改哦) */
.scroll-open {
bottom: 0px !important;
}
.scroll-animation {
transition: all 0.25s linear;
}
/* 遮罩层样式 */
.scroll-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
z-index: 998;
}
.scroll-box {
position: absolute;
bottom: 0;
width: 100%;
background: #ffff;
border-radius: 24rpx 24rpx 0 0;
}
.scroll-temp {
padding-bottom: env(safe-area-inset-bottom);
}
.scroll-top {
height: 88rpx;
line-height: 88rpx;
}
.scroll-top-left {
float: left;
padding-left: 24rpx;
font-size: 28rpx;
}
.scroll-top-right {
float: right;
padding-right: 24rpx;
color: #1890ff;
font-size: 28rpx;
}
.scroll-view_H {
white-space: nowrap;
width: 100%;
height: 400rpx;
line-height: 100rpx;
background-color: #ffffff;
}
.scroll-view-grid-box {
width: calc(100% - 20rpx);
margin: 10rpx;
padding-bottom: 10rpx;
}
.scroll-view-noBox {
width: 100%;
height: 400rpx;
text-align: center;
image {
width: 200rpx;
height: 200rpx;
margin-top: 32rpx;
}
.text {
width: 100%;
text-align: center;
color: #888;
font-size: 28rpx;
margin-top: -40rpx;
}
}
.scroll-view-item {
padding: 0rpx 24rpx;
text-align: left;
border-radius: 6rpx;
font-size: 28rpx;
margin: 12rpx 4rpx;
height: 66rpx;
line-height: 66rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.scroll-view-item-true {
padding: 0rpx 24rpx;
text-align: left;
border-radius: 6rpx;
font-size: 28rpx;
margin: 12rpx 4rpx;
height: 66rpx;
line-height: 66rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-list {
display: flex;
align-items: center;
justify-content: space-between;
.select-img {
min-width: 30rpx;
width: 30rpx;
height: 30rpx;
margin-left: 20rpx;
}
}
</style>