index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="calendarBar">
  3. <vc-date-picker
  4. ref="Calendar"
  5. class="calendar"
  6. v-model="date"
  7. :disabled-dates='disabledDates'
  8. @transition-start="queryMoth"
  9. :attributes='attrs'
  10. @dayclick="onDayClick"></vc-date-picker>
  11. <ul>
  12. <li v-for="v in legend" :key="v.type">
  13. {{v.type}}
  14. <span :style="{background:v.color}"></span>
  15. </li>
  16. </ul>
  17. </div>
  18. </template>
  19. <script>
  20. import {workTimeList} from "@/views/menu/workTime/api";
  21. import dayjs from "dayjs";
  22. export default {
  23. props:{
  24. orgId: null,
  25. },
  26. data() {
  27. let date = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
  28. return {
  29. legend:[
  30. // {
  31. // type:'不可配置',
  32. // color:'#4a5568',
  33. // },
  34. {
  35. type:'营业',
  36. color:'#2f855a',
  37. },
  38. {
  39. type:'歇业',
  40. color:'#b7791f',
  41. },
  42. {
  43. type:'未配置',
  44. color:'#c53030',
  45. }
  46. ],
  47. date: null,
  48. attrs: [],
  49. disabledDates:{
  50. end: date
  51. }
  52. };
  53. },
  54. computed:{
  55. disabledDate(time) {
  56. const date = new Date();
  57. date.setTime(date.getTime()- 3600 * 1000 * 24 );
  58. return time.getTime() < date;
  59. },
  60. },
  61. watch:{
  62. //监听机构id初始化
  63. orgId:{
  64. handler(val){
  65. if(val){
  66. this.initData();
  67. }
  68. },
  69. immediate:true,
  70. },
  71. },
  72. methods:{
  73. //复制到全月
  74. copyMouth(formDate){
  75. let arr = [];
  76. this.attrs.forEach(v=>{
  77. v.customData.isEnable = formDate.isEnable;
  78. v.customData.openTime = formDate.openTime;
  79. v.customData.closeTime = formDate.closeTime;
  80. v.customData.workTime = formDate.workTime;
  81. v.customData.workOffTime = formDate.workOffTime;
  82. v.customData.isDuty = formDate.isDuty;
  83. arr.push(v.customData);
  84. });
  85. this.$toast.success('复制成功,请点击提交');
  86. this.$emit('copy',arr);
  87. },
  88. //初始化数据
  89. initData(){
  90. let date = dayjs(new Date()).format('YYYY-MM-DD hh:mm:ss');
  91. let data = {
  92. month:date,
  93. orgId:this.orgId,
  94. }
  95. this.getWorkTimeList(data);
  96. },
  97. // 获取月份
  98. queryMoth(){
  99. /** 这几段代码是为了获取组件中翻页的月份,即当前月*/
  100. let Calendar = this.$refs.Calendar;
  101. let year = Calendar.$refs.calendar.pages[0].year;
  102. let month = Calendar.$refs.calendar.pages[0].month;
  103. let date = `${year}-${month}-1 00:00:00`;
  104. let data = {
  105. month:date,
  106. orgId:this.orgId,
  107. }
  108. this.getWorkTimeList(data);
  109. },
  110. //获取工作时间列表
  111. getWorkTimeList(data){
  112. workTimeList(data).then(res=>{
  113. let list = res.data.map(v=>{
  114. if(v.ymdDate == dayjs( new Date()).format('YYYY-MM-DD')){
  115. this.$emit('change',v)
  116. }
  117. return{
  118. key:v.id,
  119. customData: v,
  120. highlight: {
  121. color: v.isEnable == 1 ? 'green' : v.isEnable == 0 ? 'yellow' : v.isEnable == null ? 'red' : 'indigo',
  122. fillMode: 'outline',
  123. },
  124. dates: dayjs(v.ymdDate).format('YYYY-MM-DD'),
  125. }
  126. });
  127. this.attrs = list;
  128. this.date = new Date();
  129. })
  130. },
  131. //点击日期
  132. onDayClick(day){
  133. let dayInfo = {};
  134. day.attributes.forEach(v=>{
  135. if(v.key != 'select-drag'){
  136. dayInfo = JSON.parse(JSON.stringify(v.customData));
  137. dayInfo.isDisabled = !!day.isDisabled;
  138. }
  139. })
  140. this.$emit('change',dayInfo)
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .calendarBar{
  147. .calendar {
  148. border: none;
  149. width: 100%;
  150. }
  151. .vc-day{
  152. margin: 10px 0;
  153. }
  154. }
  155. </style>
  156. <style lang="scss" scoped>
  157. .calendarBar {
  158. width: 100%;
  159. background-color: #fff;
  160. box-sizing: border-box;
  161. .calendarBarTitle {
  162. font-size: 25px;
  163. font-weight: 500;
  164. color: #333333;
  165. }
  166. >ul{
  167. height:80px;
  168. display: flex;
  169. justify-content: space-around;
  170. li{
  171. display: flex;
  172. align-items: center;
  173. >span{
  174. display: inline-block;
  175. width: 25px;
  176. height: 25px;
  177. margin-left: 10px;
  178. border-radius: 50%;
  179. }
  180. }
  181. }
  182. }
  183. </style>