leave.js
10 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import {
listLeaveApplication,
getLeaveApplication,
delLeaveApplication,
addLeaveApplication,
updateLeaveApplication,
exportLeaveApplication
} from "@/api/office/leaveApplication";
import Editor from '@/components/ZcEditor';
import leaveApplicationInfo from '@/views/office/leaveApplication/leaveApplicationInfo';
import {getDict} from "@/api/dict";
import h5Page from '@/views/h5/Pagination';
import h5Info from "@/views/h5/leaveApplication/leaveApplicationInfo";
import {getBase64} from "@/api/business/threestep";
export default {
name: "LeaveApplication",
components: {Editor, leaveApplicationInfo,h5Page,h5Info},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 请假申请表格数据
leaveApplicationList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
applicant: null,
deptName: null,
positionId: null,
birthdate: null,
phone: null,
type: null,
status: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
type: [
{required: true, message: '必填', trigger: 'change'},
],
beginDate: [
{required: true, message: '必填', trigger: 'change'},
],
endDate: [
{required: true, message: '必填', trigger: 'change'},
],
phone: [
{required: true, message: '必填', trigger: 'change'},
{
pattern: /^1(3|4|5|7|8|9)\d{9}$/,
message: '手机号格式错误',
trigger: 'change'
}
],
numberDays: [
{required: true, message: '必填', trigger: 'change'},
{
pattern: /^(0|[1-9]\d*)(\.5)?$/,
message: '只能为整数或者0.5',
trigger: 'change'
},
{
pattern: /^(?!0+(\.0+)?$)\d+(\.\d+)?$/,
message: '不能为0',
trigger: 'change'
}
]
},
openInfo: false,
idInfo: null,
fileEntityList:[],
depts:[],
slide1: []
};
},
watch: {
fileEntityList(value) {
this.slide1 = []
if (this.fileEntityList.length != 0) {
this.fileEntityList.map(item => {
if (item.name.indexOf(".jpg") > -1 || item.name.indexOf(".png") > -1 || item.name.indexOf(".jpeg") > -1 || item.name.indexOf(".jpg") > -1) {
if(item.raw!=null){
this.slide1.push({
src: URL.createObjectURL(item.raw),
msrc: URL.createObjectURL(item.raw),
alt: item.uid,
w: 1920,
h: 1080
});
}else{
this.slide1.push({
src: process.env.VUE_APP_BASE_API + item.url,
msrc: process.env.VUE_APP_BASE_API + item.url,
w: 1920,
h: 1080
});
}
}
})
}
}
},
created() {
let dep = {type:"CSUserDepartmentType"};
getDict(dep).then(res=>{
this.depts = res.result;
});
this.getList();
},
methods: {
/** 查询请假申请列表 */
getList() {
this.loading = true;
listLeaveApplication(this.queryParams).then(response => {
this.leaveApplicationList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.openInfo = false;
this.reset();
},
// 表单重置
reset() {
this.fileEntityList = [];
this.form = {
id: null,
applicant: null,
deptName: null,
positionId: null,
workDate: null,
birthdate: null,
phone: null,
type: null,
beginDate: null,
endDate: null,
numberDays: null,
content: null,
status: 0,
createTime: null,
createBy: null,
updateTime: null,
updateBy: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 查看按钮操作 */
handleInfo(row) {
this.reset();
this.idInfo = row.id+"";
this.title = "请假申请详情";
this.openInfo = true;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加请假申请";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getLeaveApplication(id).then(response => {
this.form = response.data.leaveApplication;
let files = JSON.stringify(response.data.uploadFiles);
this.fileEntityList = JSON.parse(files.replaceAll("filePath", "url").replaceAll("fileName", "name"))
this.open = true;
this.title = "修改请假申请";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
let formData = new FormData();
let form = this.form;
//去掉params属性
delete form.params;
formData.append('fileList', null);
//将新增的文件放入formData
this.fileEntityList.forEach(item => {
if(item.id==null){
formData.append('fileList', item.raw)
}
})
if (this.form.id != null) {
formData.append("leaveApplication", JSON.stringify(form));
formData.append("uploadFilesList", null);
this.fileEntityList.forEach(item => {
delete item.params;
if(item != "null" && item != null){
formData.append('uploadFilesList', JSON.stringify(item).replaceAll("url", "filePath").replaceAll("name", "fileName"));
}
})
updateLeaveApplication(formData).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
for (let key in form) {
formData.append(key, form[key] == null ? "" : form[key])
}
addLeaveApplication(formData).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除请假申请编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function () {
return delLeaveApplication(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有请假申请数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function () {
return exportLeaveApplication(queryParams);
}).then(response => {
this.download(response.message);
})
},
/**
* 文件改变时,限制文件上传格式和大小
* 文件格式只能为docx/xlsx/xls/ppt/doc/pdf/png/jpeg/png/jpg
* 大小不超过5M
* */
fileChange(file, fileList) {
let count = 0;
for (let i = 0; i < fileList.length; i++) {
// console.log(fileList.length)
// console.log(this.fileEntityList[i].name+"111"+file.name)
if (fileList[i].name == file.name) {
count++;
if (count == 2) {
this.$message({
message: '已存在此文件!',
type: 'warning'
});
for (let j = fileList.length; j > 0; j--) {
//如果存在此文件,去除新选择的重复文件
if (fileList[j - 1].name == file.name) {
fileList.splice(j - 1, 1);
i--;
return false;
}
}
}
}
}
let fileType = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
//格式符合后判断大小
if ("docx,xlsx,xls,ppt,doc,pdf,png,jpeg,png,jpg".indexOf(fileType) != -1) {
let max5M = file.size / 1024 / 1024 < 5;
if (!max5M) {
this.$message({
message: '上传文件大小不得超过5M!',
type: 'warning'
});
fileList = fileList.splice(fileList.length - 1, 1);
} else {
//符合条件后进行添加
this.fileEntityList = fileList
}
} else {
this.$message({
message: '上传文件只能是 docx、xlsx、xls、ppt、doc、pdf、png、jpeg、png、jpg格式!',
type: 'warning'
});
fileList = fileList.splice(fileList.length - 1, 1);
}
},
// 删除文件
handleDeleteFile(index) {
this.fileEntityList.splice(index, 1);
this.slide1.splice(index, 1);
},
/** 文件下载 */
downloadFA(row) {
let name = row.name;
let url = row.url;
const a = document.createElement('a')
a.setAttribute('download', name)
a.setAttribute('target', '_blank')
a.setAttribute('href', process.env.VUE_APP_BASE_API + url);
a.click()
},
}
};