299 lines
6.4 KiB
Vue
299 lines
6.4 KiB
Vue
|
|
<template>
|
|||
|
|
<view class="g-picker">
|
|||
|
|
<!-- <view class="g-picker-value" @click="showPicker">
|
|||
|
|
<text class="_value" v-if="value">{{value}}</text>
|
|||
|
|
<text class="_placeholder" v-else>{{placeholder}}</text>
|
|||
|
|
</view> -->
|
|||
|
|
<picker mode="selector" :range="columnsList" :range-key="filter.label" @cancel="onCancel" @change="confirm" filterable>
|
|||
|
|
<uni-search-bar v-if="searchFlag" bgColor="#fff" v-model="searchName" class="search" radius="5"
|
|||
|
|
placeholder="请输入" clearButton="auto" cancelButton="none" @input="searchChange" />
|
|||
|
|
<view @click="isSearchFn()" class="picker" style="margin-left: 24rpx;">
|
|||
|
|
<view class="" style="color: #e1e1e1;" v-if="!value">
|
|||
|
|
{{placeholder}}
|
|||
|
|
</view>
|
|||
|
|
<view class="" v-else>
|
|||
|
|
{{value}}
|
|||
|
|
</view>
|
|||
|
|
</view>
|
|||
|
|
</picker>
|
|||
|
|
<!-- <u-popup :show="show" :round="6" mode="bottom">
|
|||
|
|
<view class="g-picker-con">
|
|||
|
|
<view class="g-picker-operate">
|
|||
|
|
<text @click="show = false">取消</text>
|
|||
|
|
<u-input v-if="searchFlag" class="g-input" v-model="searchName" placeholder="请输入">
|
|||
|
|
</u-input>
|
|||
|
|
<text @click="confirm">确认</text>
|
|||
|
|
</view>
|
|||
|
|
<scroll-view class="g-picker-list" scroll-y="true">
|
|||
|
|
<view class="g-picker-item" v-for="(col, inx) in searchList" :key="inx"
|
|||
|
|
@click="checkItem(col, inx)">
|
|||
|
|
<view :class="['g-picker-item_label', col._check ? 'g-picker-item--actived' : '']"
|
|||
|
|
:style="{color: col._check ? activedColor : '#333'}">{{ col[filter.label] }}</view>
|
|||
|
|
<u-icon class="g-picker-item_icon" v-show="col._check" name="checkbox-mark"
|
|||
|
|
:color="activedColor"></u-icon>
|
|||
|
|
</view>
|
|||
|
|
</scroll-view>
|
|||
|
|
</view>
|
|||
|
|
</u-popup> -->
|
|||
|
|
</view>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<script>
|
|||
|
|
export default {
|
|||
|
|
model: {
|
|||
|
|
prop: 'value',
|
|||
|
|
event: 'change'
|
|||
|
|
},
|
|||
|
|
props: {
|
|||
|
|
// picker组件绑定值,默认 name 用,拼接
|
|||
|
|
value: {
|
|||
|
|
type: String,
|
|||
|
|
default: ""
|
|||
|
|
},
|
|||
|
|
// 数据源
|
|||
|
|
columns: {
|
|||
|
|
type: Array,
|
|||
|
|
default: () => {
|
|||
|
|
return []
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
// 数据显示格式化
|
|||
|
|
filter: {
|
|||
|
|
type: Object,
|
|||
|
|
default: () => {
|
|||
|
|
return {
|
|||
|
|
label: 'label',
|
|||
|
|
value: 'value'
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
defaultList: {
|
|||
|
|
type: Array,
|
|||
|
|
default: () => {
|
|||
|
|
return []
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
// 是否开启搜索
|
|||
|
|
// searchFlag: {
|
|||
|
|
// type: Boolean,
|
|||
|
|
// default: false
|
|||
|
|
// },
|
|||
|
|
// 是否禁用
|
|||
|
|
disabled: {
|
|||
|
|
type: Boolean,
|
|||
|
|
default: false
|
|||
|
|
},
|
|||
|
|
// 选中后颜色
|
|||
|
|
activedColor: {
|
|||
|
|
type: String,
|
|||
|
|
default: "#000"
|
|||
|
|
},
|
|||
|
|
// 文本对齐方式
|
|||
|
|
inputAlign: {
|
|||
|
|
type: String,
|
|||
|
|
default: "right"
|
|||
|
|
},
|
|||
|
|
// 默认提示
|
|||
|
|
placeholder: {
|
|||
|
|
type: String,
|
|||
|
|
default: "请选择"
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
data() {
|
|||
|
|
return {
|
|||
|
|
show: false,
|
|||
|
|
columnsList: [],
|
|||
|
|
value_chx: [],
|
|||
|
|
searchName: "",
|
|||
|
|
searchFlag: false,
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
watch: {
|
|||
|
|
value: {
|
|||
|
|
handler(n) {
|
|||
|
|
if (n) this.reShow();
|
|||
|
|
},
|
|||
|
|
immediate: true
|
|||
|
|
},
|
|||
|
|
columns: {
|
|||
|
|
handler(n) {
|
|||
|
|
this.columnsList = n
|
|||
|
|
if (n.length) {
|
|||
|
|
for (let val of this.columnsList) {
|
|||
|
|
this.$set(val, '_check', false)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
console.log(n)
|
|||
|
|
},
|
|||
|
|
immediate: true
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
computed: {
|
|||
|
|
searchList() {
|
|||
|
|
console.log(this.searchName)
|
|||
|
|
const resultList = this.columnsList.filter(item => this.searchName ? item[this.filter.label].includes(this.searchName) : true)
|
|||
|
|
this.defaultList.forEach(item => {
|
|||
|
|
const find = resultList.find(ele => ele[this.filter.value] == item);
|
|||
|
|
if(find) {
|
|||
|
|
find._check = true;
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
console.log(resultList, 1111)
|
|||
|
|
return resultList;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
methods: {
|
|||
|
|
searchChange(e) {
|
|||
|
|
console.log(e, this.searchName)
|
|||
|
|
this.columnsList = this.columns.filter(item => item[this.filter.label].includes(e))
|
|||
|
|
},
|
|||
|
|
showPicker() {
|
|||
|
|
if (this.disabled) return
|
|||
|
|
this.show = true
|
|||
|
|
},
|
|||
|
|
reShow() {
|
|||
|
|
let data = this.value.split(",")
|
|||
|
|
setTimeout(() => {
|
|||
|
|
for (let val of this.columnsList) {
|
|||
|
|
if (data.includes(val[this.filter.label])) val._check = true
|
|||
|
|
}
|
|||
|
|
}, 100)
|
|||
|
|
},
|
|||
|
|
checkItem(col, inx) {
|
|||
|
|
col._check = !col._check
|
|||
|
|
},
|
|||
|
|
// close() {
|
|||
|
|
// this.show = false
|
|||
|
|
// this.$emit("close")
|
|||
|
|
// },
|
|||
|
|
confirm(event) {
|
|||
|
|
// console.log(event, this.columnsList[event.detail.value]);
|
|||
|
|
// let value = [],
|
|||
|
|
// label = []
|
|||
|
|
// // this.value_chx = this.columns.filter(v => v._check)
|
|||
|
|
// this.value_chx = [this.columns[event.detail.value]];
|
|||
|
|
// for (let val of this.value_chx) {
|
|||
|
|
// value.push(val[this.filter.value])
|
|||
|
|
// label.push(val[this.filter.label])
|
|||
|
|
// }
|
|||
|
|
this.show = false
|
|||
|
|
// this.$emit('confirm', this.value_chx, value, label)
|
|||
|
|
// this.$emit('change', label.join(","))
|
|||
|
|
this.$emit('confirm', this.columnsList[event.detail.value])
|
|||
|
|
|
|||
|
|
this.onCancel();
|
|||
|
|
},
|
|||
|
|
onCancel() {
|
|||
|
|
this.searchFlag = false;
|
|||
|
|
},
|
|||
|
|
isSearchFn() {
|
|||
|
|
setTimeout(() => {
|
|||
|
|
this.searchFlag = true;
|
|||
|
|
}, 500);
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
<style lang="scss" scoped>
|
|||
|
|
:deep(.uni-picker-action) {
|
|||
|
|
.uni-picker-action {
|
|||
|
|
font-size: 34rpx;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
.search {
|
|||
|
|
position: fixed;
|
|||
|
|
/* bottom: 465rpx; */
|
|||
|
|
/* bottom: 244rpx; */
|
|||
|
|
bottom: 244px;
|
|||
|
|
left: 50%;
|
|||
|
|
transform: translateX(-50%);
|
|||
|
|
z-index: 9999;
|
|||
|
|
padding: 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.search :deep( .uni-searchbar__box) {
|
|||
|
|
width: 55vw;
|
|||
|
|
border: 2rpx solid #f5f5f5;
|
|||
|
|
}
|
|||
|
|
.g-picker {
|
|||
|
|
|
|||
|
|
.g-picker-value {
|
|||
|
|
display: flex;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.g-picker-con {
|
|||
|
|
color: #333;
|
|||
|
|
font-size: 28rpx;
|
|||
|
|
|
|||
|
|
.g-picker-operate {
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
justify-content: space-between;
|
|||
|
|
height: 80rpx;
|
|||
|
|
padding: 0 32rpx;
|
|||
|
|
position: relative;
|
|||
|
|
|
|||
|
|
.g-input {
|
|||
|
|
width: 50%;
|
|||
|
|
position: absolute;
|
|||
|
|
top: 50%;
|
|||
|
|
left: 50%;
|
|||
|
|
transform: translate(-50%, -50%);
|
|||
|
|
z-index: 11;
|
|||
|
|
border: 1rpx solid;
|
|||
|
|
padding: 0 32rpx !important;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
text {
|
|||
|
|
color: #999;
|
|||
|
|
|
|||
|
|
&:last-child {
|
|||
|
|
color: #3c9cff;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.g-picker-list {
|
|||
|
|
min-height: 30vh;
|
|||
|
|
max-height: 60vh;
|
|||
|
|
// overflow-y: scroll;
|
|||
|
|
|
|||
|
|
.g-picker-item {
|
|||
|
|
position: relative;
|
|||
|
|
width: 100%;
|
|||
|
|
height: 80rpx;
|
|||
|
|
|
|||
|
|
.g-picker-item_label {
|
|||
|
|
width: 66%;
|
|||
|
|
margin: 0 auto;
|
|||
|
|
text-align: center;
|
|||
|
|
line-height: 80rpx;
|
|||
|
|
white-space: nowrap;
|
|||
|
|
text-overflow: ellipsis;
|
|||
|
|
overflow: hidden;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.g-picker-item--actived {
|
|||
|
|
font-weight: 600;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.g-picker-item_icon {
|
|||
|
|
position: absolute;
|
|||
|
|
top: 50%;
|
|||
|
|
right: 40rpx;
|
|||
|
|
transform: translateY(-50%);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
._value {
|
|||
|
|
word-break: break-all;
|
|||
|
|
line-height: 36rpx;
|
|||
|
|
}
|
|||
|
|
._placeholder {
|
|||
|
|
color: rgb(192, 196, 204);
|
|||
|
|
font-size: 28rpx;
|
|||
|
|
}
|
|||
|
|
</style>
|