index.vue
9.6 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
<template>
<div class="flow-form" v-loading="loading">
<div class="com-title">
<h1>补卡申请</h1>
<span class="number">单据号:{{ dataForm.billNo }}</span>
</div>
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="110px" :disabled="setting.readonly">
<el-row>
<el-col v-if="judgeShow('flowTitle')" :span="12">
<el-form-item label="流程标题" prop="flowTitle">
<el-input v-model="dataForm.flowTitle" placeholder="流程标题" :disabled="judgeWrite('flowTitle')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('flowUrgent')" :span="12">
<el-form-item label="紧急程度" prop="flowUrgent">
<el-select v-model="dataForm.flowUrgent" placeholder="选择紧急程度" :disabled="judgeWrite('flowUrgent')">
<el-option v-for="item in flowUrgentOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col v-if="judgeShow('applyUser')" :span="12">
<el-form-item label="申请人员" prop="applyUser">
<el-input v-model="dataForm.applyUser" readonly :disabled="judgeWrite('applyUser')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('applyDate')" :span="12">
<el-form-item label="申请日期" prop="applyDate">
<el-date-picker v-model="dataForm.applyDate" type="date" value-format="timestamp" format="yyyy-MM-dd"
:editable="false" readonly :disabled="judgeWrite('applyDate')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('applyDept')" :span="12">
<el-form-item label="申请部门" prop="applyDept">
<el-input v-model="dataForm.applyDept" readonly :disabled="judgeWrite('applyDept')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('applyPost')" :span="12">
<el-form-item label="申请职位" prop="applyPost">
<el-input v-model="dataForm.applyPost" readonly :disabled="judgeWrite('applyPost')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('punchTargetsJson')" :span="24">
<el-form-item label="补卡日期">
<span class="el-text-muted">近 3 个自然日(不含当日)未打满卡的日期;勾选需补的上班/下班卡(可同时选)。审批通过后按考勤组标准时间写入。</span>
<el-table v-loading="candidateLoading" :data="punchRows" border size="small"
style="width:100%;margin-top:8px;">
<el-table-column prop="date" label="日期" width="120" />
<el-table-column prop="statusText" label="当前状态" min-width="100" />
<el-table-column label="补上班卡" width="100" align="center">
<template slot-scope="scope">
<el-checkbox v-model="scope.row._in" :disabled="setting.readonly || !scope.row.missingPunchIn" />
</template>
</el-table-column>
<el-table-column label="补下班卡" width="100" align="center">
<template slot-scope="scope">
<el-checkbox v-model="scope.row._out" :disabled="setting.readonly || !scope.row.missingPunchOut" />
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-col>
<el-col v-if="judgeShow('applyReason')" :span="24">
<el-form-item label="补卡原因" prop="applyReason">
<el-input v-model="dataForm.applyReason" type="textarea" :rows="3" placeholder="请说明补卡原因"
:disabled="judgeWrite('applyReason')" />
</el-form-item>
</el-col>
<el-col v-if="judgeShow('fileJson')" :span="24">
<el-form-item label="相关附件" prop="fileJson">
<NCC-UploadFz v-model="fileList" type="workFlow" :disabled="judgeWrite('fileJson')" />
</el-form-item>
</el-col>
</el-row>
</el-form>
</div>
</template>
<script>
import comMixin from '../../workFlowForm/mixin'
import { Info, Create, Update } from '@/api/workFlow/workFlowForm'
import { getPunchApplyCandidates } from '@/api/extend/attendanceRecord'
export default {
name: 'AttendancePunchApplyForm',
mixins: [comMixin],
data() {
return {
billEnCode: 'WF_AttendancePunchApplyNo',
formApiKey: 'attendancePunchApply',
candidateLoading: false,
punchRows: [],
dataForm: {
id: '',
flowId: '',
billNo: '',
flowTitle: '',
flowUrgent: 1,
applyUser: '',
applyDate: '',
applyDept: '',
applyPost: '',
punchTargetsJson: '[]',
applyReason: '',
fileJson: '',
description: ''
},
dataRule: {
flowTitle: [{ required: true, message: '流程标题不能为空', trigger: 'blur' }],
flowUrgent: [{ required: true, message: '紧急程度不能为空', trigger: 'change' }],
applyReason: [{ required: true, message: '补卡原因不能为空', trigger: 'blur' }]
}
}
},
methods: {
syncPunchJson() {
const arr = (this.punchRows || []).filter(r => r._in || r._out).map(r => ({
date: r.date,
punchIn: !!r._in,
punchOut: !!r._out
}))
this.dataForm.punchTargetsJson = JSON.stringify(arr)
},
selfInit() {
this.dataForm.applyDate = new Date().getTime()
this.dataForm.flowTitle = this.userInfo.userName + '的补卡申请'
this.dataForm.applyUser = this.userInfo.userName + '/' + this.userInfo.userAccount
this.dataForm.applyDept = this.userInfo.organizeName
if (this.userInfo.positionIds && this.userInfo.positionIds.length) {
this.dataForm.applyPost = this.userInfo.positionIds.map(o => o.name).join(',')
}
this.loadPunchCandidates('[]')
},
loadPunchCandidates(savedPunchJson) {
this.candidateLoading = true
const saved = savedPunchJson !== undefined ? savedPunchJson : (this.dataForm.punchTargetsJson || '[]')
let parsed = []
try {
parsed = JSON.parse(saved || '[]') || []
} catch (e) {
parsed = []
}
const readonly = !!(this.setting && this.setting.readonly)
return getPunchApplyCandidates({}).then(res => {
const list = res.data || []
this.punchRows = list.map(x => ({
date: x.date,
statusText: x.statusText,
missingPunchIn: x.missingPunchIn,
missingPunchOut: x.missingPunchOut,
_in: false,
_out: false
}))
if (parsed.length) {
parsed.forEach(p => {
if (!p || !p.date) return
const row = this.punchRows.find(r => r.date === p.date)
if (row) {
if (readonly) {
row._in = !!p.punchIn
row._out = !!p.punchOut
} else {
row._in = !!p.punchIn && row.missingPunchIn
row._out = !!p.punchOut && row.missingPunchOut
}
}
})
}
// 已保存的日期若已超出「当前近 3 日候选」窗口(如历史单回看),仍展示申请时勾选的补卡日
const seen = new Set(this.punchRows.map(r => r.date))
parsed.forEach(p => {
if (!p || !p.date || seen.has(p.date)) return
if (!p.punchIn && !p.punchOut) return
seen.add(p.date)
this.punchRows.push({
date: p.date,
statusText: '申请已选日期',
missingPunchIn: !!p.punchIn,
missingPunchOut: !!p.punchOut,
_in: !!p.punchIn,
_out: !!p.punchOut
})
})
this.punchRows.sort((a, b) => String(b.date).localeCompare(String(a.date)))
this.syncPunchJson()
}).finally(() => {
this.candidateLoading = false
})
},
selfGetInfo() {
Info(this.formApiKey, this.setting.id).then(res => {
this.dataForm = res.data
if (res.data.fileJson) {
this.fileList = JSON.parse(res.data.fileJson)
}
const savedJson = this.dataForm.punchTargetsJson
this.loadPunchCandidates(savedJson).then(() => {
this.$emit('setPageLoad')
})
})
},
exist() {
this.syncPunchJson()
const ok = (this.punchRows || []).some(r => r._in || r._out)
if (!ok) {
this.$message.warning('请至少勾选一天的上班卡或下班卡')
return false
}
return true
},
selfSubmit() {
this.syncPunchJson()
this.dataForm.status = this.eventType === 'submit' ? 0 : 1
if (this.eventType === 'save') return this.selfHandleRequest()
this.$confirm('确定提交补卡申请?审批通过后将按考勤组标准时间自动写入打卡。', '提示', { type: 'warning' }).then(() => {
this.selfHandleRequest()
}).catch(() => { })
},
selfHandleRequest() {
this.syncPunchJson()
if (!this.dataForm.id) delete this.dataForm.id
if (this.eventType === 'save') this.$emit('setLoad', true)
const formMethod = this.dataForm.id ? Update : Create
formMethod(this.formApiKey, this.dataForm).then(res => {
this.$message({
message: res.msg, type: 'success', duration: 1500, onClose: () => {
if (this.eventType === 'save') this.$emit('setLoad', false)
this.$emit('close', true)
}
})
}).catch(() => {
if (this.eventType === 'save') this.$emit('setLoad', false)
})
}
}
}
</script>
<style scoped>
.el-text-muted {
color: #909399;
font-size: 12px;
}
</style>