PickTime.vue 3.0 KB

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