smh-time-range.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template >
  2. <view v-if="isUnder">
  3. <view class='shade'>
  4. </view>
  5. <view class="time1">
  6. <view class="top flex justify-between align-center">
  7. <text @tap="cancel">取消</text>
  8. <text @tap="confirm">确定</text>
  9. </view>
  10. <view style='display: flex;justify-content: space-between;margin:0 38px;'>
  11. <view>开始时间</view>
  12. <view>结束时间</view>
  13. </view>
  14. <picker-view class="picker" :value="value" @change="getime" indicator-style="height:30px;">
  15. <picker-view-column>
  16. <view class="hours" style="line-height:30px; text-align: center;" v-for="(item,index) in hoursList" :key="index">{{item}}</view>
  17. </picker-view-column>
  18. <picker-view-column>
  19. <view style="line-height:30px; text-align: center;">-</view>
  20. </picker-view-column>
  21. <picker-view-column>
  22. <view class="hours" style="line-height:30px; text-align: center;" v-for="(item,index) in hoursList" :key="index">{{item}}</view>
  23. </picker-view-column>
  24. </picker-view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. let minutes=['00','30']
  30. // for (let i = 0; i <= 59; i++) {
  31. // if(i<10){
  32. // i="0"+i
  33. // }
  34. // minutes.push(i)
  35. // }
  36. export default{
  37. props:{
  38. time:{
  39. type: Array,
  40. default() {
  41. return ['15','0','0'];
  42. }
  43. },
  44. isUnder: {
  45. type: Boolean,
  46. default: false
  47. }
  48. },
  49. watch:{
  50. time:function(){
  51. this.value=this.time
  52. },
  53. },
  54. created(){
  55. console.log(this.isUnder)
  56. },
  57. data(){
  58. return{
  59. value:this.time,//默认结束开始时间
  60. hoursList:[
  61. '00:00',
  62. '00:30',
  63. '01:00',
  64. '01:30',
  65. '02:00',
  66. '02:30',
  67. '03:00',
  68. '03:30',
  69. '04:00',
  70. '04:30',
  71. '05:00',
  72. '05:30',
  73. '06:00',
  74. '06:30',
  75. '07:00',
  76. '07:30',
  77. '08:00',
  78. '08:30',
  79. '09:00',
  80. '09:30',
  81. '10:00',
  82. '10:00',
  83. '11:00',
  84. '11:30',
  85. '12:00',
  86. '12:30',
  87. '13:00',
  88. '13:30',
  89. '14:00',
  90. '14:30',
  91. '15:00',
  92. '15:30',
  93. '16:00',
  94. '16:30',
  95. '17:00',
  96. '17:30',
  97. '18:00',
  98. '18:30',
  99. '19:00',
  100. '19:30',
  101. '20:00',
  102. '20:30',
  103. '21:00',
  104. '21:30',
  105. '22:00',
  106. '22:30',
  107. '23:00',
  108. '23:30',
  109. '24:00'],
  110. minutes,
  111. }
  112. },
  113. methods:{
  114. confirm(){
  115. setTimeout(()=>{
  116. console.log(this.value)
  117. let time = this.value[0]+"~"+this.value[1]
  118. this.$emit("confrim",{time:time,start:this.value[0],end:this.value[1]})
  119. },100)
  120. },
  121. cancel(){
  122. let time = this.value[0]+"~"+this.value[1]
  123. this.$emit("cancel",{time:time,start:this.value[0],end:this.value[1]})
  124. },
  125. getime(e){
  126. let val = e.detail.value
  127. console.log(val,val[0],val[1],val[2])
  128. this.value[0] = this.hoursList[val[0]]
  129. this.value[1] = this.hoursList[val[2]]
  130. },
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .shade{
  136. position: fixed;
  137. bottom: 0;
  138. top: 0;
  139. left: 0;
  140. right: 0;
  141. background-color: rgba(0, 0, 0, 0.4);
  142. transition-property: opacity;
  143. transition-duration: 0.3s;
  144. opacity: 1;
  145. z-index: 99;
  146. }
  147. .time1{
  148. position: fixed;
  149. left: 0;
  150. right: 0;
  151. transition-property: -webkit-transform;
  152. transition-property: transform;
  153. transition-property: transform, -webkit-transform;
  154. transition-duration: 0.3s;
  155. bottom: calc(0px);
  156. z-index: 99;
  157. width:100%;
  158. margin: 0 auto;
  159. background-color:#FFFFFF;
  160. color: #000;
  161. height: 450rpx;
  162. .top{
  163. width: 690rpx;
  164. margin: 0 auto;
  165. height: 100rpx;
  166. line-height: 100rpx;
  167. text{
  168. font-weight: bold;
  169. &:nth-child(1){
  170. font-size: 28rpx;
  171. color: #999;
  172. }
  173. &:nth-child(2){
  174. font-size: 28rpx;
  175. color: #0A84FF;
  176. }
  177. }
  178. }
  179. .tip12{
  180. width: 100%;
  181. height: 100rpx;
  182. view{
  183. width: 50%;
  184. text-align: center;
  185. line-height: 100rpx;
  186. font-size: 40rpx;
  187. color: #000000;
  188. }
  189. }
  190. .hours{
  191. font-size: 30rpx;
  192. font-weight: bold;
  193. color: #000;
  194. }
  195. .minutes{
  196. font-size: 30rpx;
  197. font-weight: bold;
  198. color: #000;
  199. }
  200. }
  201. .picker{
  202. width: 100%;
  203. height: 300rpx;
  204. }
  205. </style>