| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <template>
- <div class="calendarBar">
- <vc-date-picker
- ref="Calendar"
- class="calendar"
- v-model="date"
- :disabled-dates='disabledDates'
- @transition-start="queryMoth"
- :attributes='attrs'
- @dayclick="onDayClick"></vc-date-picker>
- <ul>
- <li v-for="v in legend" :key="v.type">
- {{v.type}}
- <span :style="{background:v.color}"></span>
- </li>
- </ul>
- </div>
- </template>
- <script>
- import {workTimeList} from "@/views/menu/workTime/api";
- import dayjs from "dayjs";
- export default {
- props:{
- orgId: null,
- },
- data() {
- let date = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
- return {
- legend:[
- // {
- // type:'不可配置',
- // color:'#4a5568',
- // },
- {
- type:'营业',
- color:'#2f855a',
- },
- {
- type:'歇业',
- color:'#b7791f',
- },
- {
- type:'未配置',
- color:'#c53030',
- }
- ],
- date: null,
- attrs: [],
- disabledDates:{
- end: date
- }
- };
- },
- computed:{
- disabledDate(time) {
- const date = new Date();
- date.setTime(date.getTime()- 3600 * 1000 * 24 );
- return time.getTime() < date;
- },
- },
- watch:{
- //监听机构id初始化
- orgId:{
- handler(val){
- if(val){
- this.initData();
- }
- },
- immediate:true,
- },
- },
- methods:{
- //复制到全月
- copyMouth(formDate){
- let arr = [];
- this.attrs.forEach(v=>{
- v.customData.isEnable = formDate.isEnable;
- v.customData.openTime = formDate.openTime;
- v.customData.closeTime = formDate.closeTime;
- v.customData.workTime = formDate.workTime;
- v.customData.workOffTime = formDate.workOffTime;
- v.customData.isDuty = formDate.isDuty;
- arr.push(v.customData);
- });
- this.$toast.success('复制成功,请点击提交');
- this.$emit('copy',arr);
- },
- //初始化数据
- initData(){
- let date = dayjs(new Date()).format('YYYY-MM-DD hh:mm:ss');
- let data = {
- month:date,
- orgId:this.orgId,
- }
- this.getWorkTimeList(data);
- },
- // 获取月份
- queryMoth(){
- /** 这几段代码是为了获取组件中翻页的月份,即当前月*/
- let Calendar = this.$refs.Calendar;
- let year = Calendar.$refs.calendar.pages[0].year;
- let month = Calendar.$refs.calendar.pages[0].month;
- let date = `${year}-${month}-1 00:00:00`;
- let data = {
- month:date,
- orgId:this.orgId,
- }
- this.getWorkTimeList(data);
- },
- //获取工作时间列表
- getWorkTimeList(data){
- workTimeList(data).then(res=>{
- let list = res.data.map(v=>{
- if(v.ymdDate == dayjs( new Date()).format('YYYY-MM-DD')){
- this.$emit('change',v)
- }
- return{
- key:v.id,
- customData: v,
- highlight: {
- color: v.isEnable == 1 ? 'green' : v.isEnable == 0 ? 'yellow' : v.isEnable == null ? 'red' : 'indigo',
- fillMode: 'outline',
- },
- dates: dayjs(v.ymdDate).format('YYYY-MM-DD'),
- }
- });
- this.attrs = list;
- this.date = new Date();
- })
- },
- //点击日期
- onDayClick(day){
- let dayInfo = {};
- day.attributes.forEach(v=>{
- if(v.key != 'select-drag'){
- dayInfo = JSON.parse(JSON.stringify(v.customData));
- dayInfo.isDisabled = !!day.isDisabled;
- }
- })
- this.$emit('change',dayInfo)
- },
- }
- }
- </script>
- <style lang="scss">
- .calendarBar{
- .calendar {
- border: none;
- width: 100%;
- }
- .vc-day{
- margin: 10px 0;
- }
- }
- </style>
- <style lang="scss" scoped>
- .calendarBar {
- width: 100%;
- background-color: #fff;
- box-sizing: border-box;
- .calendarBarTitle {
- font-size: 25px;
- font-weight: 500;
- color: #333333;
- }
- >ul{
- height:80px;
- display: flex;
- justify-content: space-around;
- li{
- display: flex;
- align-items: center;
- >span{
- display: inline-block;
- width: 25px;
- height: 25px;
- margin-left: 10px;
- border-radius: 50%;
- }
- }
- }
- }
- </style>
|