its-calendar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view>
  3. <view class="calendar">
  4. <view class="calendar_day">
  5. <view class="day_x" :style="{'color': (day_index == index ? '#FE3B3C' : '')}"
  6. v-for="(item, index) in dayArr" :key="index" @click.stop="dayList(item,index)">
  7. <view class="day_x_a">{{item.weeks}}</view>
  8. <view class="day_x_b">{{item.days}}</view>
  9. </view>
  10. </view>
  11. <view scroll-y class="calendar_time">
  12. <view class="time_x" :class="host_index == item?.timeStamp ? 'time_x_sty' : ''"
  13. v-for="(item, index) in timeHostArr[day_index]" :key="index"
  14. @click="nowTimes < item?.timeStamp ? hosts(item) : ''"
  15. :style="{'color': (nowTimes > item?.timeStamp ? '#999999' : '')}">{{item?.hours}}</view>
  16. </view>
  17. </view>
  18. <!-- <view class="sub" @click="sub()">
  19. 立即预约
  20. </view> -->
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. timeArr: {
  27. type: Array,
  28. default: () => []
  29. },
  30. timeHostArr:{
  31. type: Array,
  32. default: () => []
  33. },
  34. },
  35. data() {
  36. return {
  37. dayArr: [],
  38. hostArr: [],
  39. day_index: 0,
  40. host_index: '',
  41. host_All: [],
  42. nowTimes: '',
  43. }
  44. },
  45. watch: {
  46. timeArr: {
  47. handler(newVal) {
  48. let dateArr = newVal.map(item => {
  49. let day = new Date(item)
  50. const daysOfWeek = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  51. return {
  52. weeks: daysOfWeek[day.getDay()],
  53. days: item.slice(5)
  54. }
  55. })
  56. this.dayArr = dateArr
  57. // let timeArr = []
  58. // for (let i = 0; i < 4; i++) {
  59. // // let as = new Date(new Date().toLocaleDateString()).getTime() / 1000
  60. // let as = new Date(new Date().toLocaleDateString()).getTime() / 1000 + i * 60 * 60 * 24
  61. // let staTime = 9 * 60 * 60 + as
  62. // let endTime = 18 * 60 * 60 + as
  63. // let int = 15 * 60
  64. // let timeArr_s = []
  65. // console.log(staTime, '>>>>staTime99999');
  66. // for (staTime; staTime < endTime - int; staTime + int) {
  67. // console.log(staTime, '>>>>>staTime');
  68. // staTime = staTime + int
  69. // let hours = this.times(staTime)
  70. // let asb = {
  71. // hours,
  72. // timeStamp: staTime
  73. // }
  74. // timeArr_s.push(asb)
  75. // }
  76. // timeArr.push(timeArr_s)
  77. // }
  78. // console.log(timeArr, '>>>>>>>999>');
  79. // this.hostArr = timeArr
  80. },
  81. immediate: true
  82. }
  83. },
  84. mounted() {},
  85. methods: {
  86. // 点击日期
  87. dayList(e, index) {
  88. this.day_index = index
  89. this.$emit('getByDate', this.timeArr[index])
  90. },
  91. // 点击时间
  92. hosts(e) {
  93. this.host_All = e
  94. this.host_index = e.timeStamp
  95. },
  96. // 点击立即预约
  97. sub() {
  98. if (this.host_index == '') {
  99. this.$tool.toast('请选择时间')
  100. } else {
  101. let day = this.dayArr[this.day_index]
  102. let time = this.time(this.host_index)
  103. let comTime = {
  104. days: day.days,
  105. weeks: day.weeks,
  106. hours: this.host_All.hours,
  107. timeStamp: this.host_All.timeStamp,
  108. time: time
  109. }
  110. this.$emit('getTime', comTime);
  111. }
  112. },
  113. // 格式化时间
  114. times(data) {
  115. let date = new Date(data * 1000);
  116. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  117. let h = date.getHours();
  118. h = h < 10 ? ('0' + h) : h; //小时补0
  119. let m = date.getMinutes();
  120. m = m < 10 ? ('0' + m) : m; //分钟补0
  121. return h + ':' + m
  122. },
  123. time(data, type){
  124. let date = new Date(data * 1000);
  125. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  126. let y = date.getFullYear();
  127. let MM = date.getMonth() + 1;
  128. MM = MM < 10 ? ('0' + MM) : MM; //月补0
  129. let d = date.getDate();
  130. d = d < 10 ? ('0' + d) : d; //天补0
  131. let h = date.getHours();
  132. h = h < 10 ? ('0' + h) : h; //小时补0
  133. let m = date.getMinutes();
  134. m = m < 10 ? ('0' + m) : m; //分钟补0
  135. let s = date.getSeconds();
  136. s = s < 10 ? ('0' + s) : s; //秒补0
  137. if (type == 'yymmdd') {
  138. return y + '-' + MM + '-' + d
  139. } else if (type == 'hhmmss') {
  140. return h + ':' + m + ':' + s;
  141. } else {
  142. return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss">
  149. page {
  150. background-color: #F4F4F4;
  151. }
  152. .calendar {
  153. width: 710rpx;
  154. height: 460rpx;
  155. background-color: #FFFFFF;
  156. margin: 20rpx auto 10rpx;
  157. border-radius: 8rpx;
  158. }
  159. .calendar_day {
  160. display: flex;
  161. width: 100%;
  162. height: 120rpx;
  163. .day_x {
  164. display: flex;
  165. flex-flow: column nowrap;
  166. justify-content: center;
  167. align-items: center;
  168. width: 20%;
  169. height: 100%;
  170. font-size: 30rpx;
  171. color: #333333;
  172. }
  173. }
  174. .calendar_time {
  175. display: flex;
  176. width: 100%;
  177. height: 448rpx;
  178. flex-flow: row wrap;
  179. align-content: flex-start;
  180. margin: 20rpx 0;
  181. overflow-y: auto;
  182. .time_x {
  183. display: flex;
  184. flex-flow: row;
  185. justify-content: center;
  186. align-items: center;
  187. width: 20%;
  188. height: 54rpx;
  189. border-radius: 26rpx;
  190. margin: 10rpx 0;
  191. font-size: 30rpx;
  192. color: #333333;
  193. }
  194. .time_x_sty {
  195. background-color: #FFE97B;
  196. color: #000000 !important;
  197. }
  198. }
  199. .sub {
  200. display: flex;
  201. justify-content: center;
  202. align-items: center;
  203. width: 710rpx;
  204. height: 100rpx;
  205. border-radius: 50rpx;
  206. margin: 30rpx auto;
  207. color: #FFFFFF;
  208. font-size: 36rpx;
  209. background-color: #FE3B3C;
  210. }
  211. </style>