效果图如下:
需求是:
1、点击input框后选择审核人列表菜单过渡从下往上出现;
2、选择人后点击确定按钮,选择的人出现在input框中;
3、点击空白的地方则关闭选择审核人窗口

代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
/*,蒙版*/
.overlay{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
background: rgba(0, 0, 0, .5);
}
.checklist{
-webkit-transition: .3s;
position: fixed;
bottom: 0;
left: 0;
z-index: 2000;
width: 100%;
background-color: #fff;
}
.wrap {
display: -webkit-flex;
display: flex;
justify-content: space-between;
align-items: center;
height: 45px;
font-size: 16px;
padding: 0 13px;
border-bottom: 1px solid rgb(217, 217, 217);
}
.cancel{
padding: 5px 10px;
font-size: 12px;
font-weight: 400;
display: inline-block;
cursor: pointer;
text-align: center;
color: #333;
border: 1px solid #ccc;
border-radius: 3px;
background-color: #fff;
}
.confirm{
padding: 5px 10px;
font-size: 12px;
font-weight: 400;
display: inline-block;
cursor: pointer;
text-align: center;
border-radius: 3px;
color: #fff;
border: 1px solid #007aff;
background-color: #007aff;
}
.list{
width: 100%;
height: 230px;
overflow-x: hidden;
overflow-y: scroll;
}
.list .line {
display: -webkit-flex;
display: flex;
justify-content: center; /*周围留有空白*/
align-items: center;
height: 30px;
}
.list .line .lines{
display: -webkit-flex;
display: flex;
flex-direction: column;
justify-content: center; /*周围留有空白*/
align-items: flex-start;
width: 90%;
}
/*过渡样式*/
.fade-enter-active, .fade-leave-active {
-webkit-transform: translateY(0px);
}
.fade-enter, .fade-leave-active {
-webkit-transform: translateY(300px);
}
</style>
</head>
<body>
<div id="app">
<p>{{ message }}</p>
<input type="text" @click="btn($event)" v-model="peoPle">
<!--过渡的动画-->
<transition name="fade">
<div class="checklist" v-if="visible" ref="main">
<div class="wrap">
<button class="cancel" @click="onhide">取消</button>
<span class="title">选择审核人</span>
<button class="confirm" @click="onConfirm">完成</button>
</div>
<div class="list">
<div class="line" v-for="item in data">
<div class="lines">
<label class="title">{{item.name}}</label>
</div>
<div>
<input :value="item.name" type="checkbox" v-model="checkedNames">
</div>
</div>
</div>
</div>
</transition>
<!--蒙层-->
<div class="overlay" v-if="visible"></div>
</div>
<script>
var vm = new Vue({
el: '#app',
//屏幕以外的点击
data: {
message: 'Hello Vue.js!',
visible:false,
data:[
{
'name':'智子'
},
{
'name':'王静云'
},
{
'name':'王云'
},
{
'name':'张三'
},
{
'name':'李四'
},
{
'name':'王五'
},
{
'name':'赵璐'
},
{
'name':'李文'
},
{
'name':'海翔'
}
],
peoPle:'',
checkedNames:[]
},
methods:{
/*点击input*/
btn (event) {
//阻止冒泡
event || (event = window.event);
event.stopPropagation ? event.stopPropagation() : (event.cancelBubble = true);
this.visible ? this.hide() : this.show()
},
show () {
this.visible = true;
document.addEventListener('click', this.hidePanel, false)
},
hide () {
this.visible = false;
document.removeEventListener('click', this.hidePanel, false)
},
hidePanel (e) {
if (this.$refs.main && !this.$refs.main.contains(e.target)) {//点击除弹出层外的空白区域
this.hide()
}
},
/*取消*/
onhide(){
this.visible = false;
},
/*完成*/
onConfirm(){
this.visible = false;
this.peoPle= this.checkedNames
}
}
})
</script>
</body>
</html>