index.vue
7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<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>