index.vue 7.51 KB
<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
            <el-form-item label="月份" prop="dateValue">
                <el-date-picker v-model="queryParams.dateValue" type="month" placeholder="选择月" value-format="yyyy-MM"
                    @keyup.enter.native="handleQuery">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 日历 -->
        <div class="custom-calendar">
            <el-calendar v-model="value" v-if="isShow">
                <template slot="dateCell" slot-scope="{ data }">
                    <div style="position: relative;">
                        <p :class="data.isSelected ? 'is-selected' : ''" class="dayshow">
                            {{ data.day.split("-").slice(2).join("-") }}
                        </p>
                        <div v-if="Scheduling[+data.day.split('-').slice(2).join('-') - 1] && data.day.split('-')[1] == queryParams.dateValue.split('-')[1]"
                            class="arrange"
                            :class="Scheduling[+data.day.split('-').slice(2).join('-') - 1].workday == 0 ? 'pink' : 'blue'"
                            style="">{{
                                Scheduling[+data.day.split("-").slice(2).join("-") - 1].workday == 0
                                    ?
                                    '休' : '班'
                            }}</div>
                    </div>
                </template>
            </el-calendar>
        </div>
        <!-- 修改 -->
        <el-dialog :title="dayWork.days" :visible.sync="dialogUserVisible">
            <el-form :model="dayWork" ref="form" label-width='100px'>
                <el-form-item label="工作日调整" prop="constractId">
                    <el-select style="width: 360px" v-model="dayWork.workday" filterable placeholder="请选择">
                        <el-option v-for="item in isWork" :key="item.value" :label="item.name" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogUserVisible = false">取 消</el-button>
                <el-button type="primary" @click="changeState">确 定</el-button>
            </span>
        </el-dialog>


    </div>
</template>

<script>
import { workList, changeDay } from "@/api/config/workday";
import { watch } from "vue-demi";
let moment = require("moment");

export default {
    name: "Workday",
    data() {
        return {
            queryParams: {
                dateValue: '',
            },
            isShow: false,
            Scheduling: [],//排班
            value: new Date(),
            dialogUserVisible: false,
            dayWork: {
                days: '',
                workday: 0,
                worktime: '',
            },
            isWork: [
                {
                    name: '班',
                    value: 1,
                },
                {
                    name: '休',
                    value: 0,
                },
            ],
        }
    },
    watch: {
        value(val, oldVal) {
            if (
                val &&
                moment(val).format("YYYY-MM-DD") == moment().format("YYYY-MM-DD")
            ) {
                // console.log("点击了‘今天’按钮");
                this.calendarChange();
                this.dialogUserVisible = true;
            } else if (
                val &&
                moment(val).toDate() < moment(oldVal).startOf("month").toDate()
            ) {
                // console.log("点击了‘上个月’按钮");
                this.dialogUserVisible = false;
                // 获取列表
                const formattedDate = this.formatDateString(val);
                this.queryParams.dateValue = formattedDate.slice(0, 7);
                this.getList();
            } else if (
                val &&
                moment(val).toDate() > moment(oldVal).endOf("month").toDate()
            ) {
                // console.log("点击了‘下个月’按钮");
                this.dialogUserVisible = false;
                // 获取列表
                const formattedDate = this.formatDateString(val);
                this.queryParams.dateValue = formattedDate.slice(0, 7);
                this.getList();
            } else {
                // console.log("点击了" + moment(val).format("YYYY-MM") + "的按钮");
                this.calendarChange();
                this.dialogUserVisible = true;
            }
        },
    },
    created() {
        this.getMonth();
        this.getList();
    },
    methods: {
        getMonth() {
            const date = new Date();
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以要 +1
            const currentYearMonth = `${year}-${month}`;
            this.queryParams.dateValue = currentYearMonth;
        },
        getList() {
            this.isShow = false;
            this.Scheduling = [];
            workList({ month: this.queryParams.dateValue }).then((res) => {
                this.$nextTick(() => {
                    this.Scheduling = res.data;
                    this.isShow = true;
                })
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.isShow = false;
            // YY-MM转换标准时间
            this.value = new Date(Date.parse(new Date(this.queryParams.dateValue)))
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.getMonth();
            this.handleQuery();
        },
        calendarChange() {
            // 处理格式
            const formattedDate = this.formatDateString(this.value);
            this.dayWork.days = formattedDate;
        },
        formatDateString(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            return `${year}-${month}-${day}`;
        },
        // 更改工作日
        changeState() {
            changeDay(this.dayWork).then((res) => {
                this.dialogUserVisible = false;
                this.getList();
                this.$notify({
                    title: '成功',
                    message: '修改成功',
                    type: 'success'
                });
            })
        },
    },

}
</script>
<style scoped>
.is-selected {
    color: #1989FA;
}

.custom-calendar {
    width: 1700px;
    margin: 0 auto;
}

.custom-calendar /deep/ .el-calendar-table .el-calendar-day {
    height: 125px;

}

.pink {
    /* color: #eb3333; */
    background-color: #ef7777;
}

.blue {
    /* color: #025caa; */
    background-color: #69a2d4;
}

.dayshow {
    font-size: 30px;
    font-weight: bold;
    text-align: center;
    line-height: 48px;
}

.arrange {
    position: absolute;
    right: 0;
    top: -30px;
    width: 26px;
    height: 26px;
    text-align: center;
    line-height: 26px;
    color: white;
    border-radius: 5px;
}

/* ::v-deep .el-calendar__header {
    display: none;
} */
</style>