its-calendar.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view>
  3. <view class="calendar">
  4. <scroll-view scroll-x="true" class="top-wrap" >
  5. <view class="time-wrap" v-for="(dayitem,dayindex) in dayArr" :key="dayindex" :class="{'action':day_index ==dayindex }" @click.stop="dayList(dayitem,dayindex)">
  6. <text class="time-val">{{dayitem.days}}</text>
  7. <text class="time-xq">{{dayitem.weeks}}</text>
  8. </view>
  9. </scroll-view>
  10. <!-- <view class="calendar_day">
  11. <view class="day_x" :style="{'color': (day_index == index ? '#FE3B3C' : '')}"
  12. v-for="(item, index) in dayArr" :key="index" @click.stop="dayList(item,index)">
  13. <view class="day_x_a">{{item.weeks}}</view>
  14. <view class="day_x_b">{{item.days}}</view>
  15. </view>
  16. </view> -->
  17. <view scroll-y class="calendar_time">
  18. <view class="time_x" :class="host_index == item.timeStamp ? 'time_x_sty' : ''"
  19. v-for="(item, index) in hostArr[day_index]" :key="index"
  20. @click="nowTimes < item.timeStamp ? hosts(item) : ''"
  21. :style="{'color': (nowTimes > item.timeStamp ? '#999999' : '')}">{{item.hours}}</view>
  22. </view>
  23. </view>
  24. <!-- <view class="sub" @click="sub()">
  25. 立即预约
  26. </view> -->
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. sta_num: {
  33. type: Number | String,
  34. default: 8
  35. },
  36. end_num: {
  37. type: Number | String,
  38. default: 23
  39. },
  40. int_num: {
  41. type: Number | String,
  42. default: 30
  43. },
  44. },
  45. data() {
  46. return {
  47. dayArr: [],
  48. hostArr: [],
  49. day_index: 0,
  50. host_index: '',
  51. host_All: [],
  52. nowTimes: '',
  53. }
  54. },
  55. mounted() {
  56. let dateArr = [];
  57. let today = new Date();
  58. let nowTime = today.getTime() // 当前时间戳
  59. this.nowTimes = parseInt(nowTime / 1000)
  60. for (let i = 0; i < 10; i++) {
  61. let newDate = new Date(today.getTime() + i * 1000 * 60 * 60 * 24);
  62. let month = (parseInt(newDate.getMonth()) + 1) > 9 ? (parseInt(newDate.getMonth()) + 1) : "0" + (parseInt(
  63. newDate.getMonth()) + 1); // 当前月份
  64. let day = (newDate.getDate()) > 9 ? newDate.getDate() : "0" + newDate.getDate(); //当前日期
  65. let backTime = newDate.getTime(); // 几天后时间戳
  66. let backDays = newDate.getDay();// 几天后周几
  67. let remTime = (backTime - nowTime) / 1000; // 距离今天几天
  68. let week = '';
  69. // if (remTime == 0) {
  70. // week = "今天"
  71. // } else if (remTime == 86400) {
  72. // week = "明天"
  73. // } else if (remTime == 172800) {
  74. // week = "后天"
  75. // } else {
  76. if (backDays == 0) {
  77. week = "周日";
  78. } else if (backDays == 1) {
  79. week = "周一";
  80. } else if (backDays == 2) {
  81. week = "周二";
  82. } else if (backDays == 3) {
  83. week = "周三";
  84. } else if (backDays == 4) {
  85. week = "周四";
  86. } else if (backDays == 5) {
  87. week = "周五";
  88. } else if (backDays == 6) {
  89. week = "周六";
  90. }
  91. // }
  92. // let fullDate = `${month}-${day}`;
  93. let fullDate = `${day}`;
  94. let ass = {
  95. weeks: week,
  96. days: fullDate
  97. };
  98. dateArr.push(ass);
  99. }
  100. this.dayArr = dateArr;
  101. let timeArr = [];
  102. for (let i = 0; i < 5; i++) {
  103. // let as = new Date(new Date().toLocaleDateString()).getTime() / 1000
  104. let as = new Date(new Date().toLocaleDateString()).getTime() / 1000 + i * 60 * 60 * 24;
  105. let staTime = this.sta_num * 60 * 60 + as;
  106. let endTime = this.end_num * 60 * 60 + as;
  107. let int = this.int_num * 60;
  108. let timeArr_s = [];
  109. for (staTime; staTime < endTime - int; staTime + int) {
  110. staTime = staTime + int;
  111. let hours = this.times(staTime);
  112. let asb = {
  113. hours,
  114. timeStamp: staTime
  115. };
  116. timeArr_s.push(asb);
  117. }
  118. timeArr.push(timeArr_s);
  119. }
  120. this.hostArr = timeArr;
  121. },
  122. methods: {
  123. // 点击日期
  124. dayList(e, index) {
  125. this.day_index = index;
  126. },
  127. // 点击时间
  128. hosts(e) {
  129. this.host_All = e;
  130. this.host_index = e.timeStamp;
  131. this.sub()
  132. },
  133. // 点击立即预约
  134. sub() {
  135. if (this.host_index == '') {
  136. this.$tool.toast('请选择时间');
  137. } else {
  138. let day = this.dayArr[this.day_index];
  139. let time = this.time(this.host_index);
  140. let comTime = {
  141. days: day.days,
  142. weeks: day.weeks,
  143. hours: this.host_All.hours,
  144. timeStamp: this.host_All.timeStamp,
  145. time: time
  146. };
  147. this.$emit('getTime', comTime);
  148. }
  149. },
  150. // 格式化时间
  151. times(data) {
  152. let date = new Date(data * 1000);
  153. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  154. let h = date.getHours();
  155. h = h < 10 ? ('0' + h) : h; //小时补0
  156. let m = date.getMinutes();
  157. m = m < 10 ? ('0' + m) : m; //分钟补0
  158. return h + ':' + m;
  159. },
  160. time(data, type){
  161. let date = new Date(data * 1000);
  162. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  163. let y = date.getFullYear();
  164. let MM = date.getMonth() + 1;
  165. MM = MM < 10 ? ('0' + MM) : MM; //月补0
  166. let d = date.getDate();
  167. d = d < 10 ? ('0' + d) : d; //天补0
  168. let h = date.getHours();
  169. h = h < 10 ? ('0' + h) : h; //小时补0
  170. let m = date.getMinutes();
  171. m = m < 10 ? ('0' + m) : m; //分钟补0
  172. let s = date.getSeconds();
  173. s = s < 10 ? ('0' + s) : s; //秒补0
  174. if (type == 'yymmdd') {
  175. return y + '-' + MM + '-' + d;
  176. } else if (type == 'hhmmss') {
  177. return h + ':' + m + ':' + s;
  178. } else {
  179. return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
  180. }
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. page {
  187. background-color: #F4F4F4;
  188. }
  189. .calendar {
  190. width: 710rpx;
  191. height: 590rpx;
  192. background-color: #FFFFFF;
  193. margin: 20rpx auto 10rpx;
  194. border-radius: 8rpx;
  195. }
  196. .calendar_day {
  197. display: flex;
  198. width: 100%;
  199. height: 120rpx;
  200. .day_x {
  201. display: flex;
  202. // flex-flow: column nowrap;
  203. flex-flow: nowrap;
  204. justify-content: center;
  205. align-items: center;
  206. width: 20%;
  207. height: 100%;
  208. font-size: 30rpx;
  209. color: #333333;
  210. }
  211. }
  212. .calendar_time {
  213. display: flex;
  214. width: 100%;
  215. height: 448rpx;
  216. flex-flow: row wrap;
  217. align-content: flex-start;
  218. margin: 20rpx 0;
  219. overflow-y: auto;
  220. .time_x {
  221. display: flex;
  222. flex-flow: row;
  223. justify-content: center;
  224. align-items: center;
  225. width: 20%;
  226. height: 54rpx;
  227. border-radius: 26rpx;
  228. margin: 10rpx 0;
  229. font-size: 30rpx;
  230. color: #333333;
  231. }
  232. .time_x_sty {
  233. background-color: #262261;
  234. color: #fff !important;
  235. }
  236. }
  237. .sub {
  238. display: flex;
  239. justify-content: center;
  240. align-items: center;
  241. width: 710rpx;
  242. height: 100rpx;
  243. border-radius: 50rpx;
  244. margin: 30rpx auto;
  245. color: #FFFFFF;
  246. font-size: 36rpx;
  247. // background-color: #FE3B3C;
  248. }
  249. .top-wrap {
  250. white-space: nowrap;
  251. width: 700rpx;
  252. // height: 100rpx;
  253. padding:20rpx 0;
  254. .time-wrap {
  255. margin: auto 15rpx;
  256. display: inline-block;
  257. width: 158rpx;
  258. height: 63rpx;
  259. border-radius: 32rpx;
  260. line-height: 63rpx;
  261. text-align: center;
  262. background-color: #FDF9FA;
  263. .time-xq {
  264. font-size: 22rpx;
  265. font-weight: 500;
  266. color: #999999;
  267. }
  268. .time-val {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #333333;
  272. }
  273. }
  274. .action {
  275. background-color: #262261;
  276. .time-xq {
  277. color: #FDF9FA;
  278. }
  279. .time-val {
  280. color: #FDF9FA;
  281. }
  282. }
  283. }
  284. </style>