gui-schedule.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="gui-schedule-wrap">
  3. <view class="gui-flex gui-rows gui-space-between gui-align-items-center">
  4. <picker mode="date"
  5. :value="currentDayIn"
  6. :start="startDate"
  7. :end="endDate"
  8. @change="selectDate">
  9. <text
  10. class="gui-schedule-header-date gui-icons">{{cYear}} 年 {{cMonthStr}} 月 &#xe603;</text>
  11. </picker>
  12. <text class="gui-border gui-schedule-today" @tap="gotoToday">返回今天</text>
  13. </view>
  14. <view class="gui-flex gui-rows gui-nowrap">
  15. <text class="gui-schedule-weeks gui-color-gray gui-block-text"
  16. v-for="(item, index) in weeks" :key="index">{{item}}</text>
  17. </view>
  18. <view class="gui-flex gui-rows gui-wrap">
  19. <view class="gui-schedule-7item gui-flex gui-rows gui-justify-content-center"
  20. v-for="(item, index) in days" :key="index">
  21. <view
  22. class="gui-date-ditems gui-flex gui-columns gui-justify-content-center"
  23. v-if="item != ''"
  24. :style="{
  25. backgroundColor:currentDayIn == cYear+'-'+cMonthStr+'-'+ item.date
  26. ? activeBgColor : bgColor
  27. }"
  28. @click="chooseDate(cYear+'-'+cMonthStr+'-'+item.date, item.date)">
  29. <text class="gui-date-day gui-block-text"
  30. :class="[currentDayIn == (cYear+'-'+cMonthStr+'-'+item.date) ?
  31. 'gui-d-current-txt' : '']">{{item.date}}</text>
  32. <text class="gui-date-nl gui-block-text" v-if="isLunar"
  33. :class="[currentDayIn == (cYear+'-'+cMonthStr+'-'+item.date) ?
  34. 'gui-d-current-txt' : '']">{{item.nl}}</text>
  35. <view class="gui-schedule-point"
  36. v-if="item.haveSe"
  37. :style="{backgroundColor:pointColor}"></view>
  38. </view>
  39. <view class="gui-date-ditems" v-else style="background-color:none;"></view>
  40. </view>
  41. </view>
  42. <view class="gui-border-b gui-schedule-line"></view>
  43. <view class="gui-schedule-time-list-wrap">
  44. <view class="gui-schedule-time-list gui-flex gui-rows gui-nowrap"
  45. v-for="(item, index) in hours" :key="index">
  46. <text class="gui-schedule-timer gui-block-text gui-color-gray">{{item}}:00</text>
  47. <view class="gui-border-b gui-schedule-body gui-flex gui-columns">
  48. <text class="gui-schedules gui-block-text"
  49. v-for="(schedule, idx) in schedulesIn[index]" :key="idx"
  50. @tap="scheduleTap" :data-id="schedule.id"
  51. :style="{
  52. backgroundColor:schedule.bgColor,
  53. color:schedule.color}">{{schedule.content}}</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import guiCalendar from './gui-calendar.js';
  61. export default{
  62. name : "gui-schedule",
  63. data() {
  64. return {
  65. cYear : 2020,
  66. cMonth : 1,
  67. cDay : 10,
  68. cMonthStr : '01',
  69. weeks : ['一', '二', '三', '四', '五', '六', '日'],
  70. days : [],
  71. currentDayIn : '',
  72. hours : ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'],
  73. schedulesIn: []
  74. }
  75. },
  76. props:{
  77. // 当前默认日期
  78. currentDate : {type:String, default:""},
  79. bgColor : {type:String, default:"#F8F8F8"},
  80. activeBgColor : {type:String, default:"#008AFF"},
  81. isLunar : {type:Boolean, default:true },
  82. startDate : {type:String, default:'1950-01-01'},
  83. endDate : {type:String, default:'2050-01-01'},
  84. schedules : {type:Array, default:function () {return []}},
  85. pointColor : {type:String, default:"#FF0036"}
  86. },
  87. created:function(){
  88. this.currentDayIn = this.currentDate;
  89. this.initTime();
  90. this.getSchedulesIn();
  91. },
  92. methods:{
  93. initTime : function(){
  94. if(this.currentDayIn == ''){
  95. var dateObj = new Date();
  96. this.cYear = Number(dateObj.getFullYear());
  97. this.cMonth = Number(dateObj.getMonth() + 1);
  98. this.cMonthStr = this.cMonth < 10 ? '0' + this.cMonth : this.cMonth;
  99. this.cDay = dateObj.getDate();
  100. this.cDay = this.cDay < 10 ? '0' + this.cDay : this.cDay;
  101. this.currentDayIn = this.cYear + '-' + this.cMonthStr + '-' + this.cDay;
  102. this.changeMonth();
  103. }else{
  104. var dates = this.currentDayIn.split(' ');
  105. if (!dates[1]) { dates[1] = '';}
  106. var dayArr = dates[0].split('-');
  107. this.cYear = Number(dayArr[0]);
  108. this.cMonth = dayArr[1];
  109. this.cDay = dayArr[2];
  110. var reg = new RegExp('^0[0-9]+$');
  111. if(reg.test(this.cMonth)){this.cMonth = this.cMonth.substr(1,1);}
  112. this.cMonth = Number(this.cMonth);
  113. this.cMonthStr = this.cMonth < 10 ? '0'+this.cMonth : this.cMonth;
  114. this.currentDayIn = dates[0];
  115. this.currentTimeIn = dates[1];
  116. this.changeMonth();
  117. }
  118. },
  119. changeMonth:function(){
  120. var daysList = [];
  121. var days = this.getDaysInOneMonth();
  122. var startWeek = this.getDay();
  123. var forSteps = 0;
  124. for (var i = (0 - startWeek); i < days; i++){
  125. if(i >= 0){
  126. daysList[forSteps] = {date : i >= 9 ? i + 1 : '0' + (i+1), nl : ''};
  127. daysList[forSteps].nl = guiCalendar.getLunarInfo(this.cYear, this.cMonth, i + 1);
  128. daysList[forSteps].haveSe = this.haveSchedule(daysList[forSteps].date);
  129. }else{
  130. daysList[forSteps] = '';
  131. }
  132. forSteps++;
  133. }
  134. this.days = daysList;
  135. },
  136. haveSchedule : function (day) {
  137. var cDay = this.cYear+'-'+this.cMonthStr+'-'+day;
  138. for(let i = 0; i < this.schedules.length; i++){
  139. if(this.schedules[i].datetime.indexOf(cDay) != -1){
  140. return true;
  141. }
  142. }
  143. return false;
  144. },
  145. getDaysInOneMonth : function (){
  146. var d = new Date(this.cYear, this.cMonth, 0);
  147. return d.getDate();
  148. },
  149. getDay : function (){
  150. var d = new Date(this.cYear, this.cMonth - 1, 0);
  151. return d.getDay();
  152. },
  153. selectDate : function(e){
  154. this.currentDayIn = e.detail.value;
  155. this.initTime();
  156. this.getSchedulesIn();
  157. this.$emit('selectDate', e.detail.value);
  158. },
  159. chooseDate: function (sedDate) {
  160. this.currentDayIn = sedDate;
  161. this.getSchedulesIn();
  162. this.$emit('chooseDate', sedDate);
  163. },
  164. getSchedulesIn : function (){
  165. var res = [];
  166. for(let i = 0; i < this.hours.length; i++){
  167. var ctime = this.currentDayIn + ' ' + this.hours[i] + ':00';
  168. res.push([]);
  169. for(let ii = 0; ii < this.schedules.length; ii++){
  170. if(this.schedules[ii].datetime == ctime){
  171. res[i].push(this.schedules[ii]);
  172. }
  173. }
  174. }
  175. this.schedulesIn = res;
  176. },
  177. scheduleTap : function (e) {
  178. var id = e.currentTarget.dataset.id;
  179. this.$emit('scheduleTap', id);
  180. },
  181. gotoToday : function(){
  182. var dateObj = new Date();
  183. this.cYear = Number(dateObj.getFullYear());
  184. this.cMonth = Number(dateObj.getMonth() + 1);
  185. this.cMonthStr = this.cMonth < 10 ? '0' + this.cMonth : this.cMonth;
  186. this.cDay = dateObj.getDate();
  187. this.cDay = this.cDay < 10 ? '0' + this.cDay : this.cDay;
  188. this.currentDayIn = this.cYear + '-' + this.cMonthStr + '-' + this.cDay;
  189. this.changeMonth();
  190. this.getSchedulesIn();
  191. this.$emit('gotoToday', this.currentDayIn);
  192. }
  193. }
  194. }
  195. </script>
  196. <style scoped>
  197. .gui-schedule-wrap{width:690rpx;}
  198. .gui-schedule-header-date{height:88rpx; line-height:88rpx; color:#2B2E3D; font-size:32rpx;}
  199. .gui-schedule-7item{width:98rpx; margin-bottom:22rpx; position:relative;}
  200. .gui-schedule-weeks{width:98rpx; height:88rpx; font-size:26rpx; line-height:88rpx; text-align:center;}
  201. .gui-date-ditems{width:82rpx; height:82rpx; border-radius:80rpx;}
  202. .gui-d-current-txt{color:#FFFFFF !important;}
  203. .gui-date-day{height:32rpx; line-height:32rpx; text-align:center; font-size:28rpx;}
  204. .gui-date-nl{height:24rpx; line-height:26rpx; color:#888888; font-size:20rpx; text-align:center;}
  205. .gui-schedule-line{height:20rpx; border-color:#F8F8F8;}
  206. .gui-schedule-time-list{margin-top:20rpx;}
  207. .gui-schedule-timer{width:88rpx; font-size:22rpx; line-height:36rpx;}
  208. .gui-schedule-body{width:200rpx; flex:1; border-color:#F8F8F8; margin-top:15rpx;}
  209. .gui-schedules{padding:10rpx; line-height:30rpx; font-size:22rpx; margin-top:15rpx; border-radius:8rpx;}
  210. .gui-schedule-time-list-wrap{padding:20rpx;}
  211. .gui-schedule-today{line-height:50rpx; height:50rpx; font-size:22rpx; color:#828282; padding-left:20rpx; padding-right:20rpx; border-color:#F1F2F3;}
  212. .gui-schedule-point{width:18rpx; height:18rpx; border-radius:10rpx; background-color:#FF0036; position:absolute; right:6rpx; top:6rpx;}
  213. </style>