ShiftRuleManager.vue
8.47 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<template>
<div class="fullheight">
<ht-table
@load="loadData"
@row-click="rowClick"
:data="data"
:pageResult="pageResult"
:selection="true"
quick-search-props="key,name"
:show-export="false"
:show-custom-column="false"
ref="htTable"
@selection-change="handleSelectionChange"
>
<template v-slot:toolbar>
<el-button-group>
<el-button size="small" @click="edit()" icon="el-icon-plus" type="primary">添加</el-button>
<ht-delete-button :url="deleteUrl" :htTable="$refs.htTable" style="margin-left:10;" :disabled="isDisabled">删除</ht-delete-button>
</el-button-group>
</template>
<template>
<ht-table-column type="index" width="50" align="center" label="序号" />
<ht-table-column prop="name" label="名称" :sortable="true" :show-tooltip="true">
<template slot-scope="scope">
<el-link type="primary" @click="edit(scope.row.id)" title="编辑详情">{{scope.row.name}}</el-link>
</template>
</ht-table-column>
<ht-table-column prop="key" label="key" :sortable="true" :show-tooltip="true"/>
<ht-table-column prop="desc" label="描述" :show-tooltip="true"/>
<ht-table-column label="操作">
<template slot-scope="scope">
<el-button @click="setUser(scope.row.id)" type="text">设置用户</el-button>
</template>
</ht-table-column>
</template>
</ht-table>
<el-dialog
width="60%"
:title="title"
:visible="dialogVisible"
:before-close="handleClose"
:close-on-click-modal="false "
:append-to-body="true">
<el-form data-vv-scope="editForm">
<ht-form-item label="名称">
<ht-input
v-model="shiftRule.name"
:maxlength="20"
show-word-limit
:validate="{ required: true,max:20 }"/>
</ht-form-item>
<ht-form-item label="key">
<ht-input
v-model="shiftRule.key"
:maxlength="20"
show-word-limit
:validate="{required: true,max:20,regex:{exp:'^[a-zA-Z][a-zA-Z0-9_]*$',message:'只能输入字母、数字、下划线,且以字母开头'}}"
v-pinyin="shiftRule.name"
:disabled="disabled"/>
</ht-form-item>
<ht-form-item label="描述">
<ht-input
type="textarea"
:cols="50"
:rows="5"
:maxlength="200"
show-word-limit
v-model="shiftRule.desc"/>
</ht-form-item>
<ht-form-item label="节假日">
<ht-select
v-model="shiftRule.holidayId"
:options="holidays"
:props="{key:'id',value:'name'}"
clearable/>
</ht-form-item>
<ht-form-item label="规则">
<el-tooltip placement="top" content="休息日为24小时">
<i class="el-icon-warning"></i>
</el-tooltip>
<el-table
:data="rules"
border>
<el-table-column prop="date" :formatter="weekFormat" label="日期"/>
<el-table-column label="类型" >
<template slot-scope="scope">
<ht-select style="width:160px"
v-model="scope.row.type"
:options="[{key:0,value:'休息日'},{key: 1,value: '工作日'}]"
@change="change(scope.row)"/>
</template>
</el-table-column>
<el-table-column label="上班时间" width="250">
<template slot-scope="scope">
<el-time-picker
:disabled="scope.row.type===0"
v-model="scope.row.startTime"
placeholder="任意时间点"
value-format="HH:mm:ss">
</el-time-picker>
</template>
</el-table-column>
<el-table-column label="下班时间" width="250">
<template slot-scope="scope">
<el-time-picker
:disabled="scope.row.type===0"
v-model="scope.row.endTime"
placeholder="任意时间点"
:min-time="scope.row.startTime"
value-format="HH:mm:ss">
</el-time-picker>
</template>
</el-table-column>
</el-table>
</ht-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<ht-submit-button
:url="saveUrl"
:model="shiftRule"
scope-name="editForm"
@before-save-data="beforeSaveData"
@after-save-data="afterSaveData">保 存</ht-submit-button>
</div>
</el-dialog>
<shift-user-manager ref="shiftUserManager"/>
</div>
</template>
<script>
import uc from "@/api/uc.js";
import ShiftUserManager from "./ShiftUserManager";
export default {
name: "shift-rule-manager",
components: {
ShiftUserManager
},
data() {
return {
data: [],
pageResult: {
page: 1,
pageSize: 10,
total: 0
},
deleteUrl: window.context.uc + "/uc/shiftRule/v1/remove",
saveUrl: window.context.uc + "/uc/shiftRule/v1/save",
title: "编辑轮班规则",
dialogVisible: false,
shiftRule: {
name: "",
key: "",
desc: "",
holidayId: ""
},
rules: [],
weeks: ["日","一","二","三","四","五","六"],
selectId: "",
userId: "",
holidays: [],
disabled: false,
isDisabled:true, //按钮的禁用
selectedList:[]
}
},
watch: {
// 监听选中下
selectedList:{
handler(val){
this.isDisabled = val.length < 1 ? true : false
},
deep:true
}
},
mounted() {
this.getHolidays();
},
methods: {
handleSelectionChange(selection){
this.selectedList = selection
},
rowClick(row, column, event){
this.$refs.htTable.$refs.htTable.toggleRowSelection(row);
},
loadData(param, cb){
uc.ruleList(param).then(data => {
this.data = data.rows;
this.pageResult = {
page: data.page,
pageSize: data.pageSize,
total: data.total
}
}).finally(() => {
cb && cb();
})
},
edit(id){
this.dialogVisible = true;
if (id){
this.title = "编辑轮班规则";
this.disabled = true;
uc.getRule(id).then(data => {
this.shiftRule = data;
this.rules = JSON.parse(data.rule);
});
}else{
this.title = "新增轮班规则";
this.disabled = false;
this.shiftRule = {
name: "",
key: "",
desc: "",
holidayId:""
}
this.rules = [];
for (let i=0;i<7;i++){
this.rules.push({
date: i,
type: 1,
startTime: "",
endTime: ""
})
}
}
},
handleClose(){
this.dialogVisible = false;
},
beforeSaveData(){
this.shiftRule.rule = JSON.stringify(this.rules);
},
afterSaveData() {
this.dialogVisible = false;
this.$refs.htTable.load();
},
weekFormat(row){
return "星期" + this.weeks[row.date];
},
setUser(id){
this.$refs.shiftUserManager.openDialog(id);
},
getHolidays(){
uc.holidayList({}).then(data => {
this.holidays = data.rows;
})
},
change(row){
if (row.type===0){
this.$set(row,"startTime","00:00:00");
this.$set(row,"endTime","00:00:00");
}
}
}
}
</script>
<style lang="scss" scoped>
/deep/.el-dialog__wrapper {
overflow: unset !important;
}
/deep/.el-dialog__body {
height: calc(100% - 190px);
overflow-y: auto;
}
/deep/.el-dialog {
height: 90%;
min-height: 400px;
margin-top: 3vh !important;
}
/deep/.el-dialog__body .selector-table {
height: 100% !important;
}
/deep/.el-dialog .el-dialog__body .select-tree-div {
height: calc(100% - 60px);
min-height: unset;
}
@media (max-height: 960px) {
/deep/.el-dialog__body .el-container {
height: 100% !important;
}
}
</style>