its-calendar.vue 5.6 KB

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