index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view>
  3. <view class="time1" :class='isShow==true?"on":""'>
  4. <view class="top acea-row row-between-wrapper">
  5. <text @tap="cancel">取消</text>
  6. <text @tap="confirm">确定</text>
  7. </view>
  8. <picker-view class="picker" :value="value" @change="getime" indicator-style="height:34px;">
  9. <picker-view-column>
  10. <view class="hours" v-for="(item,index) in hoursList" :key="index">{{item}}</view>
  11. </picker-view-column>
  12. <picker-view-column>
  13. <view class="minutes" v-for="(item,index) in minutes" :key="index">{{item}}</view>
  14. </picker-view-column>
  15. <picker-view-column>
  16. <view class="center">-</view>
  17. </picker-view-column>
  18. <picker-view-column>
  19. <view class="hours" v-for="(item,index) in hoursList" :key="index">{{item}}</view>
  20. </picker-view-column>
  21. <picker-view-column>
  22. <view class="minutes" v-for="(item,index) in minutes" :key="index">{{item}}</view>
  23. </picker-view-column>
  24. </picker-view>
  25. </view>
  26. <view class="mask" @tap="cancel" catchtouchmove="true" :hidden="isShow==false"></view>
  27. </view>
  28. </template>
  29. <script>
  30. let minutes=[]
  31. for (let i = 0; i <= 59; i++) {
  32. if(i<10){
  33. i="0"+i
  34. }
  35. minutes.push(i)
  36. }
  37. let hoursList = []
  38. for (let i = 0; i <= 23; i++) {
  39. if(i<10){
  40. i="0"+i
  41. }
  42. hoursList.push(i)
  43. }
  44. export default{
  45. props:{
  46. isShow:{
  47. type: Boolean,
  48. default: false
  49. },
  50. time:{
  51. type: Array,
  52. default() {
  53. return [];
  54. }
  55. }
  56. },
  57. watch:{
  58. time:function(){
  59. this.value=this.time
  60. }
  61. },
  62. created(){
  63. },
  64. data(){
  65. return{
  66. value:this.time,//默认结束开始时间
  67. hoursList,
  68. minutes,
  69. }
  70. },
  71. methods:{
  72. confirm(){
  73. let time = this.value[0]+":"+this.value[1]+" - "+this.value[3]+":"+this.value[4]
  74. if(this.value[3]>this.value[0] || (this.value[3]==this.value[0] && this.value[4]>=this.value[1])){
  75. this.$emit("confrim",{time:time,val:this.value})
  76. }else{
  77. return this.$util.Tips({
  78. title: '开始时间必须小于结束时间'
  79. });
  80. }
  81. },
  82. cancel(){
  83. let time = this.value[0]+":"+this.value[1]+" - "+this.value[3]+":"+this.value[4]
  84. this.$emit("cancel",{time:time})
  85. },
  86. getime(e){
  87. let val = e.detail.value
  88. this.value[0] = this.hoursList[val[0]]
  89. this.value[1] = this.minutes[val[1]]
  90. this.value[2] = val[2]
  91. this.value[3] = this.hoursList[val[3]]
  92. this.value[4] = this.minutes[val[4]]
  93. },
  94. }
  95. }
  96. </script>
  97. <style lang="scss">
  98. .time1{
  99. width:100%;
  100. margin: 0 auto;
  101. background-color:#FFFFFF;
  102. color: #000;
  103. height: 568rpx;
  104. position: fixed;
  105. bottom: 0;
  106. z-index: 99;
  107. transform: translate3d(0, 200%, 0);
  108. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  109. &.on{
  110. transform: translate3d(0, 0, 0);
  111. }
  112. .top{
  113. height: 90rpx;
  114. border-bottom: 1px solid #eee;
  115. padding: 0 30rpx;
  116. text{
  117. font-size: 32rpx;
  118. &:nth-child(1){
  119. color: #888;
  120. }
  121. &:nth-child(2){
  122. color: #007aff;
  123. }
  124. }
  125. }
  126. .tip12{
  127. width: 100%;
  128. height: 100rpx;
  129. view{
  130. width: 50%;
  131. text-align: center;
  132. line-height: 100rpx;
  133. font-size: 40rpx;
  134. color: #000000;
  135. }
  136. }
  137. .hours{
  138. font-size: 32rpx;
  139. color: #000;
  140. line-height:34px;
  141. text-align: center;
  142. }
  143. .minutes{
  144. font-size: 32rpx;
  145. color: #000;
  146. line-height:34px;
  147. text-align: center;
  148. }
  149. .center{
  150. line-height:34px;
  151. text-align: center;
  152. }
  153. }
  154. .picker{
  155. width: 100%;
  156. height: 476rpx;
  157. }
  158. </style>