自定义弹窗搜索组件

<template>
    <view>
        <view>
            <!-- 普通弹窗 -->
            <uni-popup ref="popup" background-color="#fff">
                <view>
                    <view class="searchin">
                        <view style="display: flex;width: 100%;">
                            <button plain="true" size="mini" class="colbtn" @click="cancelChange">取消</button>
                            <uni-easyinput class="searcheas" radius="0" placeholder="搜索" v-model="searchKey"
                                @input="search" />
                            <button plain="true" size="mini" class="subbtn" @click="sureSelect">确定</button>
                        </view>
                        <picker-view :value="pickerValue" indicator-style="height:50px;" @change="bindChange">
                            <picker-view-column>
                                <view class="item" v-for="(item,index) in pickerList" :key="index"
                                    @click="qdChange(item)">
                                    <text style="color: #a5a5a5 ;">{{item.code}}</text>
                                    <text style="margin-left: 10px;">{{item.name}}</text>
                                    <text style="margin-left: 10px;color: #ffb245 ;">{{item.py}}</text>
                                </view>
                            </picker-view-column>
                        </picker-view>
                    </view>
                </view>
            </uni-popup>
        </view>
    </view>
</template>

<script>
    export default {
        props: ['list'],
        watch: {
            list() {
                this.requestList()
            }
        },
        data() {
            return {
                pickerValue: [],
                pickerList: [],
                searchKey: '',
                searchval: '',
                index: 0,
            }
        },
        methods: {
            // 打开弹窗
            toggle(type) {
                this.searchKey = ''
                this.$refs.popup.open(type)
            },
            requestList() {
                this.pickerList = this.list
            },
            // 筛选
            search(val) {
                this.pickerList = []
                if (val !== '') {
                    this.list.forEach(v => {
                        if (v.name.indexOf(val) !== -1 || v.code.indexOf(val) !== -1 || v.py.indexOf(val) !== -1) {
                            this.pickerList.push(v)
                        }
                    })
                } else {
                    this.pickerList = this.list
                }
            },
            // 选择取消
            cancelChange() {
                this.$refs.popup.close()
            },
            // 确定
            sureSelect() {
                this.searchval = this.pickerList[this.index]
                this.$refs.popup.close()
                this.$emit("searchVal", this.searchval)
            },
            // 切换选择
            bindChange(n) {
                this.index = n.detail.value[0]
                this.searchval = this.pickerList[n.detail.value[0]]
            },
            // 点击选择
            qdChange(item) {
                this.searchval = item
                this.$refs.popup.close()
                this.$emit("searchVal", this.searchval)
            },
        }
    }
</script>

<style lang="scss">
    picker-view {
        width: 100%;
        height: 700rpx;
        margin-top: 20rpx;
    }

    .item {
        line-height: 100rpx;
        text-align: center;
    }

    .searchin {
        .uni-easyinput__content-input.data-v-abe12412 {
            margin-top: -7px;
        }

        .searcheas {
            margin-top: 15rpx;
            font-size: 3em;
            width: 70%;
        }

        .subbtn {
            margin-top: 13px;
            border-style: none;
            font-size: 14px;
            padding: 0px 10px;
        }

        .colbtn {
            margin-top: 13px;
            border-style: none;
            font-size: 12px;
            padding: 0px 10px;
        }

        .uni-easyinput.data-v-abe12412 {
            height: 30px;
        }
    }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值