|
@@ -1,78 +1,60 @@
|
|
|
+<!-- 时间类型控件 -->
|
|
|
<template>
|
|
|
<div class="toast-wrap">
|
|
|
<p v-show="val" :class="['ptab',{'check':val != '请选择'}]" @click="showPicker">{{val}}</p>
|
|
|
<p v-show="val != '请选择'" class="tip">点击可修改</p>
|
|
|
- <div class="content pc" v-show="show">
|
|
|
- <van-picker
|
|
|
- :columns="columns"
|
|
|
- :visible-item-count='3'
|
|
|
- />
|
|
|
- <div class="confBtn">
|
|
|
- <div @click="getVal">确认</div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <Picker ref="picker" :show="showTime" @comfirn="getTimeVal" @cancel="close" :picIndex="picIndex"/>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
<script type="text/javascript">
|
|
|
import $ from 'jquery';
|
|
|
- // import {getNum} from '@utils/tools.js';
|
|
|
- // const num = getNum();
|
|
|
- const num = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9];
|
|
|
- const unit = ['分钟', '小时', '天', '周', '月','年','分钟', '小时', '天', '周', '月','年','分钟', '小时', '天', '周', '月','年'];
|
|
|
+ import Picker from './Picker.vue';
|
|
|
export default {
|
|
|
name:'PickTime',
|
|
|
data() {
|
|
|
return {
|
|
|
- columns: [
|
|
|
- {
|
|
|
- values:num,
|
|
|
- className:'column1',
|
|
|
- defaultIndex: 10
|
|
|
- },
|
|
|
- {
|
|
|
- values:num,
|
|
|
- className:'column2',
|
|
|
- defaultIndex: 11
|
|
|
- },
|
|
|
- {
|
|
|
- values:unit,
|
|
|
- className:'column3',
|
|
|
- defaultIndex: 6
|
|
|
- },
|
|
|
- ],
|
|
|
val:this.item.value || '请选择',
|
|
|
- show:false
|
|
|
+ showTime:false,
|
|
|
+ picIndex:this.item.pickIndex||[]
|
|
|
}
|
|
|
},
|
|
|
- props:['item','outBoxClass'],
|
|
|
+ props:['item'],
|
|
|
methods: {
|
|
|
showPicker(){
|
|
|
- const winH = $(window).height();
|
|
|
- // outBoxClass 外层盒子的类名,用以获取高度
|
|
|
- const HH = $("."+this.outBoxClass).height();
|
|
|
- const pH = $('.ptab').offset().top;//时间组件距离顶部的高度
|
|
|
- const btH = winH - pH;console.log("可视区高度:",winH,"时间距顶部的高度:",pH,"差值:",winH-pH) //距离底部的距离
|
|
|
- // 如果底部距离小于弹窗的高度227px + 44,就显示在上方,否则显示下方
|
|
|
- // ios和华为底部会有浏览器自带的箭头,故多减30
|
|
|
- if(btH < 271){
|
|
|
- $('.pc').css('bottom','.88rem');
|
|
|
+ this.showTime = true;
|
|
|
+ $(".btscroll").css({'position':'fixed'})
|
|
|
+ $(".foot").css({'position':'fixed'})
|
|
|
+ },
|
|
|
+ getTimeVal(value,index){//确定
|
|
|
+ // 首位为0则去掉
|
|
|
+ if(value.charAt(0) == 0){
|
|
|
+ this.val = value.substr(1);
|
|
|
}else{
|
|
|
- $('.pc').css('top','.88rem')
|
|
|
+ this.val = value;
|
|
|
}
|
|
|
- this.show = true;
|
|
|
- this.$emit('forbidS'); //禁止滚动
|
|
|
- },
|
|
|
- getVal(){
|
|
|
- const val1 = $(".column1 ul .van-picker-column__item--selected")[0].innerText;
|
|
|
- const val2 = $(".column2 ul .van-picker-column__item--selected")[0].innerText;
|
|
|
- const val3 = $(".column3 ul .van-picker-column__item--selected")[0].innerText;
|
|
|
- this.val = val1 + val2 + val3;
|
|
|
- this.show = false;
|
|
|
- const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
|
|
|
+ this.showTime = false;
|
|
|
+ const newData = Object.assign({},this.item,{value:this.val,valueP:this.val,pickIndex:index});
|
|
|
this.$emit("updata",newData);
|
|
|
- const pH = $('.ptab').offset().top;//恢复滚动的位置
|
|
|
- this.$emit('resetS',pH); //恢复滚动
|
|
|
+ $(".btscroll").css({'position':'absolute'})
|
|
|
},
|
|
|
+ close(){//点击蒙层关闭
|
|
|
+ this.showTime = false;
|
|
|
+ $(".btscroll").css({'position':'absolute'})
|
|
|
+ }
|
|
|
+ },
|
|
|
+ components:{
|
|
|
+ Picker
|
|
|
+ },
|
|
|
+ watch:{
|
|
|
+ item:{
|
|
|
+ handler(newVal,oldVal){
|
|
|
+ this.val = newVal.value|| '请选择';
|
|
|
+ if(!newVal.value){//没有值时复原时间组件中的index
|
|
|
+ this.$refs.picker.resetIndex();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep:true
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
@@ -91,40 +73,12 @@
|
|
|
border-radius: .1rem;
|
|
|
color:#7C828E;
|
|
|
}
|
|
|
- .content{
|
|
|
- box-sizing: border-box;
|
|
|
- padding-top: 25px;
|
|
|
- width: 100%;
|
|
|
- height: 227px;
|
|
|
- background: #fff;
|
|
|
- z-index: 999;
|
|
|
- position: absolute;
|
|
|
- // top:.88rem;
|
|
|
- left: 50%;
|
|
|
- transform: translateX(-50%);
|
|
|
- box-sizing: border-box;
|
|
|
- border-radius: .1rem;
|
|
|
- z-index: 1000;
|
|
|
- font-size: .3rem;
|
|
|
- overflow-y: hidden;
|
|
|
- box-shadow: 0 .12rem .24rem 0 rgba(79,129,255,0.40);
|
|
|
- // box-shadow:0 .15rem .35rem 0 rgba(179,196,236,0.3);
|
|
|
- .confBtn{
|
|
|
- height: 44px;
|
|
|
- line-height: 44px;
|
|
|
- text-align: center;
|
|
|
- border-top: 1px solid #ebedf0;
|
|
|
- margin-top: 25px;
|
|
|
- div{
|
|
|
- color: #colors[theme];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
.check{
|
|
|
color: #colors[theme] !important;
|
|
|
}
|
|
|
.tip{
|
|
|
color: #7C828E;
|
|
|
+ font-size: .24rem;
|
|
|
}
|
|
|
}
|
|
|
</style>
|