PickTime.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!-- 时间类型控件 -->
  2. <template>
  3. <div class="toast-wrap">
  4. <p v-show="val" :class="['ptab',{'check':val != '请选择'}]" @click="showPicker">{{val}}</p>
  5. <p v-show="val != '请选择'" class="tip">点击可修改</p>
  6. <Picker ref="picker" :show="showTime" @comfirn="getTimeVal" @cancel="close" :picIndex="picIndex"/>
  7. </div>
  8. </template>
  9. <script type="text/javascript">
  10. import $ from 'jquery';
  11. import Picker from './Picker.vue';
  12. export default {
  13. name:'PickTime',
  14. data() {
  15. return {
  16. val:this.item.value || '请选择',
  17. showTime:false,
  18. picIndex:this.item.pickIndex||[]
  19. }
  20. },
  21. props:['item'],
  22. methods: {
  23. showPicker(){
  24. this.showTime = true;
  25. $(".btscroll").css({'position':'fixed'})
  26. $(".foot").css({'position':'fixed'})
  27. },
  28. getTimeVal(value,index){//确定
  29. // 首位为0则去掉
  30. if(value.charAt(0) == 0){
  31. this.val = value.substr(1);
  32. }else{
  33. this.val = value;
  34. }
  35. this.showTime = false;
  36. const newData = Object.assign({},this.item,{value:this.val,valueP:this.val,pickIndex:index});
  37. this.$emit("updata",newData);
  38. $(".btscroll").css({'position':'absolute'})
  39. },
  40. close(){//点击蒙层关闭
  41. this.showTime = false;
  42. $(".btscroll").css({'position':'absolute'})
  43. }
  44. },
  45. components:{
  46. Picker
  47. },
  48. watch:{
  49. item:{
  50. handler(newVal,oldVal){
  51. this.val = newVal.value|| '请选择';
  52. //有初始值或者未选择时,重置index
  53. const hasOrg =newVal.value==='1分钟'; //newVal.value.indexOf("分钟")>-1||newVal.value.indexOf("1")>-1||newVal.value.indexOf("0")>-1;
  54. if(!newVal.value||hasOrg){//没有值时复原时间组件中的index
  55. this.$refs.picker.resetIndex();
  56. }
  57. },
  58. deep:true
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="less" scoped>
  64. @import '../less/base.less';
  65. .toast-wrap{
  66. margin-bottom: .2rem;
  67. position: relative;
  68. z-index: 116;
  69. .ptab{
  70. width:100%;
  71. height: .8rem;
  72. line-height: .8rem;
  73. text-align: center;
  74. border:1px solid #E6E6E6;
  75. border-radius: .1rem;
  76. color:#7C828E;
  77. }
  78. .check{
  79. color: #colors[theme] !important;
  80. }
  81. .tip{
  82. color: #7C828E;
  83. font-size: .24rem;
  84. }
  85. }
  86. </style>