its-calendar.vue 7.0 KB

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