calendar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view>
  3. <view class="form-item">
  4. <view class="title">
  5. <text class="necessary">*</text>
  6. 开始时间:
  7. </view>
  8. <picker mode="date" :value="start_date" :start="start_date" :end="other" @change="bindDateChange" style="">
  9. <view class="date">{{start_date}}</view>
  10. </picker>
  11. </view>
  12. <view class="form-item">
  13. <view class="title"><text class="necessary">*</text>结束时间:</view>
  14. <picker mode="date" :value="start_date" :start="start_date" @change="bindDateChange2">
  15. <view class="date">{{end_date}}</view>
  16. </picker>
  17. </view>
  18. </view>
  19. <!-- <view class="leave_cont">
  20. <view class="ul">
  21. <view class="li">
  22. <view class="flex1">
  23. <picker mode="date" :value="start_date" :start="start_date" :end="other" @change="bindDateChange">
  24. <view class="date">{{start_date}}</view>
  25. </picker>
  26. </view>
  27. </view>
  28. ~
  29. <view class="li">
  30. <view class="flex1">
  31. <picker mode="date" :value="start_date" :start="start_date" @change="bindDateChange2">
  32. <view class="date">{{end_date}}</view>
  33. </picker>
  34. </view>
  35. </view>
  36. </view>
  37. </view> -->
  38. </template>
  39. <script>
  40. export default {
  41. name: 'calendar',
  42. props: {
  43. // bindData: {
  44. // type: Object,
  45. // default: ''
  46. // },
  47. bindStartTime: {
  48. type: String,
  49. default: ''
  50. },
  51. bindEndTime: {
  52. type: String,
  53. default: ''
  54. }
  55. },
  56. data() {
  57. console.log(this.bindStartTime)
  58. const currentDate = this.getTime({
  59. format: true
  60. })
  61. return {
  62. start_date:this.bindStartTime,
  63. end_date: this.bindEndTime,
  64. other: '请输入'
  65. }
  66. },
  67. computed: {
  68. },
  69. methods: {
  70. // 选择日期
  71. bindDateChange: function(e) {
  72. this.start_date = e.target.value;
  73. alert(this.start_date);
  74. this.$emit('func', this.start_date) // 子组件向发射事件,
  75. },
  76. bindDateChange2: function(e) {
  77. this.end_date = e.target.value;
  78. this.other = this.end_date;
  79. this.$emit('func2', this.end_date) // 子组件向发射事件,
  80. },
  81. // 获取当前时间
  82. // getDate(type) {
  83. // const date = new Date();
  84. // let year = date.getFullYear();
  85. // let month = date.getMonth() + 1;
  86. // let day = date.getDate();
  87. // if (type === 'start') {
  88. // year = year - 60;
  89. // } else if (type === 'end') {
  90. // year = year + 2;
  91. // }
  92. // month = month > 9 ? month : '0' + month;;
  93. // day = day > 9 ? day : '0' + day;
  94. // return `${year}-${month}-${day}`;
  95. // },
  96. getTime() {
  97. var date = new Date(),
  98. year = date.getFullYear(),
  99. month = date.getMonth() + 1,
  100. day = date.getDate(),
  101. hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
  102. minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
  103. second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  104. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  105. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  106. var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  107. return timer;
  108. }
  109. }
  110. }
  111. </script>
  112. <style>
  113. picker{
  114. border:1px solid #EDEDED;display: block;
  115. height: 100%;width:500rpx;line-height:70rpx;height:70rpx;padding:0 20rpx
  116. }
  117. .date{
  118. color:#999
  119. }
  120. /* .leave_cont .ul {
  121. border: 1px solid red;
  122. margin: 24rpx 24rpx;
  123. border: 1px solid #E8F1FF;
  124. border-radius: 36rpx;
  125. line-height: 70rpx;
  126. position: relative;
  127. }
  128. .leave_cont .ul .li {
  129. display: inline-block;
  130. text-align: center;
  131. width: 35%
  132. }
  133. .leave_cont .ul .li text {
  134. padding: 40rpx 0;
  135. font-size: 30rpx;
  136. color: #666666;
  137. text-align: center;
  138. }
  139. .leave_cont .ul .li .flex1 {
  140. flex: 1;
  141. color: #999999;
  142. font-size: 32rpx;
  143. }
  144. .date {
  145. height: 42rpx;
  146. }
  147. .canlendar-icon {
  148. width: 36rpx;
  149. height: 36rpx;
  150. position: absolute;
  151. right: 30rpx;
  152. top: 16rpx;
  153. } */
  154. </style>