its-calendar.vue 5.3 KB

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