its-calendar.vue 7.1 KB

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