<template>
|
<div class="app-container">
|
<!--工具栏-->
|
<div class="head-container">
|
<div>
|
<el-select v-model="query.userId" filterable clearable placeholder="申请人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in users"
|
:key="item.id"
|
:label="item.nickName"
|
:value="item.id"
|
/>
|
</el-select>
|
<el-select v-model="query.approvalUserId" filterable clearable placeholder="审批者" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in users"
|
:key="item.id"
|
:label="item.nickName"
|
:value="item.id"
|
/>
|
</el-select>
|
<el-select v-model="query.outOfOfficeType" filterable clearable placeholder="外出类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in dict[dictGoOutTypr]"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
<el-select v-model="query.approvalStatus" filterable clearable placeholder="审批状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in dict[dictApprovalStart]"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
<el-date-picker
|
v-model="query.outStartTime"
|
type="daterange"
|
clearable
|
class="date-item"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
placeholder="选择日期时间"
|
range-separator=" : "
|
start-placeholder="开始时间"
|
end-placeholder="开始时间"
|
/>
|
<el-date-picker
|
v-model="query.outEndTime"
|
type="daterange"
|
clearable
|
class="date-item"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
placeholder="选择日期时间"
|
range-separator=" : "
|
start-placeholder="结束时间"
|
end-placeholder="结束时间"
|
/>
|
<rrOperation />
|
</div>
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<crudOperation :permission="permission" />
|
<!--表单组件-->
|
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
|
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
|
<el-form-item label="申请人" prop="userId">
|
<el-select v-model="form.userId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="disabledUser(form)">
|
<el-option
|
v-for="item in users"
|
:key="item.id"
|
:label="item.nickName"
|
:value="item.id"
|
:disabled="!item.enabled"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="审批者" prop="approvalUserId">
|
<el-select v-model="form.approvalUserId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn">
|
<el-option
|
v-for="item in approvalUsers"
|
:key="item.id"
|
:label="item.nickName"
|
:value="item.id"
|
:disabled="!item.enabled"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="外出类型" prop="outOfOfficeType">
|
<el-select v-model="form.outOfOfficeType" filterable clearable placeholder="请选择" style="width: 340px;">
|
<el-option
|
v-for="item in dict[dictGoOutTypr]"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="外出开始时间" prop="outStartTime">
|
<el-date-picker
|
v-model="form.outStartTime"
|
:type="'datetime'"
|
placeholder="选择日期时间"
|
style="width: 340px;"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
align="right"
|
:picker-options="{
|
disabledDate(time) {
|
return form.outEndTime ? time.getTime() > new Date(form.outEndTime).getTime() - 8.64e7 : false;
|
}
|
}"
|
:default-time="$store.state.user.user.sysRostering.workStartTime + ':00'"
|
:disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn"
|
@change="checkTime"
|
/>
|
</el-form-item>
|
<el-form-item label="外出结束时间" prop="outEndTime">
|
<el-date-picker
|
v-model="form.outEndTime"
|
:type="'datetime'"
|
placeholder="选择日期时间"
|
style="width: 340px;"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
align="right"
|
:picker-options="{
|
disabledDate(time) {
|
return form.outStartTime ? time.getTime() < new Date(form.outStartTime).getTime() - 8.64e7 : false;
|
}
|
}"
|
:default-time="$store.state.user.user.sysRostering.workEndTime + ':00'"
|
:disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn"
|
@change="checkTime"
|
/>
|
</el-form-item>
|
<el-form-item label="外出时长" prop="outDuration">
|
<el-input v-model="form.outDuration" disabled style="width: 340px;">
|
<template slot="append">{{ dict.label[dictLeaveTimeType][form.durationUnit] }}</template>
|
</el-input>
|
</el-form-item>
|
<el-form-item label="外出原因">
|
<el-input v-model="form.outReason" type="textarea" rows="3" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
|
</el-form-item>
|
<el-form-item label="审批说明">
|
<el-input v-model="form.approvalDescription" type="textarea" rows="3" style="width: 340px;" disabled />
|
</el-form-item>
|
<el-form-item label="备注">
|
<el-input v-model="form.remarks" type="textarea" rows="3" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="text" @click="crud.cancelCU">取消</el-button>
|
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
|
</div>
|
</el-dialog>
|
<!--审核表单-->
|
<el-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="makeUpCardVisible" title="外出审批" width="500px">
|
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
|
<el-form-item label="申请人">
|
{{ form.userName }}
|
</el-form-item>
|
<el-form-item label="外出类型">
|
{{ dict.label[dictGoOutTypr][form.outOfOfficeType] }}
|
</el-form-item>
|
<el-form-item label="外出开始时间">
|
{{ form.outStartTime }}
|
</el-form-item>
|
<el-form-item label="外出结束时间">
|
{{ form.outEndTime }}
|
</el-form-item>
|
<el-form-item label="外出时长">
|
{{ form.outDuration + '(' + dict.label[dictLeaveTimeType][form.durationUnit] + ')' }}
|
</el-form-item>
|
<el-form-item label="外出原因">
|
{{ form.outReason }}
|
</el-form-item>
|
<el-form-item v-if="form.approvalStatus === dictGoOutReturn" label="退回原因" prop="approvalDescription">
|
<div style="color: red;">*审核退回需要填写退回原因,请填写后再次点击审核退回</div>
|
<el-input v-model="form.approvalDescription" type="textarea" :rows="3" style="width: 340px;" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="danger" style="margin-right: 10px;" @click="approveFunction(1,form)">审核退回</el-button>
|
<el-button v-if="form.approvalStatus !== dictGoOutReturn" :loading="successLoading" type="success" @click="approveFunction(2,form)">审核通过</el-button>
|
</div>
|
</el-dialog>
|
<!--表格渲染-->
|
<el-table ref="table" v-loading="crud.loading" :data="crud.data" row-key="id" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
<el-table-column type="selection" width="55" />
|
<el-table-column prop="userName" label="申请人" min-width="100" fixed="left" show-overflow-tooltip>
|
<template slot-scope="scope">
|
<el-tag>{{ scope.row.userName }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="appUserName" label="审批者" min-width="100" fixed="left" show-overflow-tooltip>
|
<template slot-scope="scope">
|
<el-tag>{{ scope.row.appUserName }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="outStartTime" label="外出开始时间" min-width="140" show-overflow-tooltip />
|
<el-table-column prop="outEndTime" label="外出结束时间" min-width="140" show-overflow-tooltip />
|
<el-table-column prop="outDuration" label="外出时长" min-width="80" show-overflow-tooltip>
|
<template slot-scope="scope">
|
{{ scope.row.outDuration + '(' + dict.label[dictLeaveTimeType][scope.row.durationUnit] + ')' }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="outOfOfficeType" label="外出类型" min-width="80" show-overflow-tooltip>
|
<template slot-scope="scope">
|
<el-tag>{{ dict.label[dictGoOutTypr][scope.row.outOfOfficeType] }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="outReason" label="外出原因" min-width="140" show-overflow-tooltip />
|
<el-table-column prop="approvalStatus" label="审批状态" min-width="80" show-overflow-tooltip>
|
<template slot-scope="scope">
|
<el-tag v-if="scope.row.approvalStatus === dictGoOutAppRev" type="warning">{{ dict.label[dictApprovalStart][scope.row.approvalStatus] }}</el-tag>
|
<el-tag v-if="scope.row.approvalStatus === dictGoOutAgree" type="success">{{ dict.label[dictApprovalStart][scope.row.approvalStatus] }}</el-tag>
|
<el-tag v-if="scope.row.approvalStatus === dictGoOutReturn" type="danger">{{ dict.label[dictApprovalStart][scope.row.approvalStatus] }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="approvalDescription" label="审批说明" min-width="140" show-overflow-tooltip />
|
<el-table-column prop="remarks" label="备注" min-width="140" show-overflow-tooltip />
|
<el-table-column prop="createTime" label="创建时间" min-width="140" show-overflow-tooltip />
|
<el-table-column v-if="checkPer(['admin','attendanceGoOut:approve'])" label="审核操作" width="180px" align="center" fixed="right">
|
<template slot-scope="scope">
|
<el-button
|
v-if="scope.row.approvalUserId === $store.state.user.user.id"
|
v-permission="permission.approve"
|
:loading="crud.status.cu === 2"
|
size="mini"
|
type="primary"
|
icon="el-icon-s-check"
|
:disabled="scope.row.approvalStatus === dictGoOutAppRev ? false : true"
|
@click="toApprove(scope.row)"
|
>审核
|
</el-button>
|
<el-popover
|
:ref="`popover_${scope.row.id}`"
|
width="200"
|
>
|
<p>确定撤销该记录?</p>
|
<div style="text-align: right; margin: 0">
|
<el-button size="mini" type="primary" @click="canel(scope.row)">取消</el-button>
|
<el-button :loading="successLoading" type="primary" size="mini" @click="revoke(scope.row)">确定</el-button>
|
</div>
|
<el-button
|
v-if="scope.row.approvalUserId === $store.state.user.user.id"
|
slot="reference"
|
v-permission="permission.approve"
|
type="danger"
|
icon="el-icon-edit-outline"
|
size="mini"
|
:disabled="scope.row.approvalStatus === dictGoOutAppRev ? true : false"
|
>撤销
|
</el-button>
|
</el-popover>
|
</template>
|
</el-table-column>
|
<el-table-column v-if="checkPer(['admin','attendanceGoOut:edit','attendanceGoOut:del'])" label="操作" width="150px" align="center" fixed="right">
|
<template slot-scope="scope">
|
<udOperation
|
:data="scope.row"
|
:permission="permission"
|
/>
|
</template>
|
</el-table-column>
|
</el-table>
|
<!--分页组件-->
|
<pagination />
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import crudAttendanceGoOut from '@/api/attendance/attendanceGoOut'
|
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
import rrOperation from '@crud/RR.operation'
|
import { mapGetters } from 'vuex'
|
import crudUser from '@/api/system/user'
|
import crudOperation from '@crud/CRUD.operation'
|
import udOperation from '@crud/UD.operation'
|
import pagination from '@crud/Pagination'
|
import constant from '@/utils/constant'
|
|
const defaultForm = { id: null, userId: null, approvalUserId: null, outStartTime: null, outEndTime: null, outDuration: null, durationUnit: null, outOfOfficeType: null, outReason: null, approvalStatus: null, approvalDescription: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
|
export default {
|
name: 'AttendanceGoOut',
|
components: { pagination, crudOperation, rrOperation, udOperation },
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
cruds() {
|
return CRUD({ title: '外出记录', url: 'api/attendanceGoOut', idField: 'id', sort: 'outStartTime,desc', crudMethod: { ...crudAttendanceGoOut }})
|
},
|
// 数据字典
|
dicts: [constant.LEAVE_TIME_TYPE, constant.GO_OUT_TYPE, constant.GO_OUT_APPROVE_STATUS],
|
data() {
|
return {
|
permission: {
|
add: ['admin', 'attendanceGoOut:add'],
|
edit: ['admin', 'attendanceGoOut:edit'],
|
del: ['admin', 'attendanceGoOut:del'],
|
download: ['admin', 'attendanceGoOut:download'],
|
approve: ['admin', 'attendanceGoOut:approve']
|
},
|
rules: {
|
userId: [
|
{ required: true, message: '申请人不能为空', trigger: 'change' }
|
],
|
approvalUserId: [
|
{ required: true, message: '审批者不能为空', trigger: 'change' }
|
],
|
outStartTime: [
|
{ required: true, message: '外出开始时间不能为空', trigger: 'change' }
|
],
|
outEndTime: [
|
{ required: true, message: '外出结束时间不能为空', trigger: 'change' }
|
],
|
outDuration: [
|
{ required: true, message: '外出时长不能为空', trigger: 'blur' }
|
],
|
durationUnit: [
|
{ required: true, message: '时长单位不能为空', trigger: 'change' }
|
],
|
outOfOfficeType: [
|
{ required: true, message: '外出类型不能为空', trigger: 'change' }
|
],
|
approvalStatus: [
|
{ required: true, message: '审批状态不能为空', trigger: 'change' }
|
],
|
approvalDescription: [
|
{ required: true, message: '审批说明不能为空', trigger: 'blur' }
|
]
|
},
|
users: [],
|
approvalUsers: [],
|
dictLeaveTimeType: constant.LEAVE_TIME_TYPE,
|
dictLeaveTimeTypeHour: constant.LEAVE_TIME_TYPE_HOUR,
|
dictGoOutTypr: constant.GO_OUT_TYPE,
|
dictApprovalStart: constant.GO_OUT_APPROVE_STATUS,
|
dictGoOutAppRev: constant.GO_OUT_APPROVE_STATUS_REVIEWED,
|
dictGoOutAgree: constant.GO_OUT_APPROVE_STATUS_AGREE,
|
dictGoOutReturn: constant.GO_OUT_APPROVE_STATUS_REFUSE,
|
makeUpCardVisible: false,
|
successLoading: false,
|
userRolesLevelMin: null,
|
// 角色级别:普通用户
|
roleLevelOrdinary: constant.ROLE_LEVEL_ORDINARY,
|
// 角色级别: 总经理
|
roleLevelGenerl: constant.ROLE_LEVEL_GENERAL }
|
},
|
computed: {
|
...mapGetters([
|
'user'
|
])
|
},
|
created() {
|
this.getUsers()
|
this.getApprovalUsers()
|
},
|
methods: {
|
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
[CRUD.HOOK.beforeRefresh]() {
|
// 用户角色级别数组
|
const userRolesLevel = this.user.roles.map(({ level }) => level)
|
// 用户最大角色级别
|
this.userRolesLevelMin = Math.min(...userRolesLevel)
|
return true
|
},
|
// 钩子:新建 - 之前
|
[CRUD.HOOK.beforeToAdd]() {
|
// 判断用户最大角色级别是否大于总经理角色:赋值
|
if (this.userRolesLevelMin > this.roleLevelGenerl) {
|
// 表单赋值
|
this.form.userId = this.user.id
|
}
|
},
|
// 禁用
|
disabledUser(data) {
|
if (this.userRolesLevelMin > this.roleLevelGenerl) {
|
return true
|
}
|
if (data.approvalStatus !== null && data.approvalStatus === this.dictGoOutAgree || data.approvalStatus === this.dictGoOutReturn) {
|
return true
|
}
|
},
|
// 查询员工
|
getUsers() {
|
crudUser.getAll().then(res => {
|
this.users = res
|
})
|
},
|
// 查询审核人
|
getApprovalUsers() {
|
crudUser.getApprovalUsers().then(res => {
|
this.approvalUsers = res
|
})
|
},
|
// 计算时长
|
checkTime() {
|
this.form.durationUnit = this.dictLeaveTimeTypeHour
|
var data = JSON.stringify({
|
'outStartTime': this.form.outStartTime,
|
'outEndTime': this.form.outEndTime
|
})
|
crudAttendanceGoOut.getRemainingTime(data).then(res => {
|
this.form.outDuration = res
|
})
|
},
|
// 审批页面赋值
|
toApprove(data, Number) {
|
if (Number !== '1') {
|
this.makeUpCardVisible = true
|
}
|
this.form.id = data.id
|
this.form.userId = data.userId
|
this.form.userName = data.userName
|
this.form.outOfOfficeType = data.outOfOfficeType
|
this.form.outStartTime = data.outStartTime
|
this.form.outEndTime = data.outEndTime
|
this.form.outDuration = data.outDuration
|
this.form.durationUnit = data.durationUnit
|
this.form.approvalStatus = data.approvalStatus
|
this.form.outReason = data.outReason
|
this.form.remarks = data.remarks
|
},
|
// 审核提交功能
|
approveFunction(Number, data) {
|
this.form.userId = data.userId
|
const msg = Number === 2 ? '通过' : '拒绝'
|
this.$refs['form'].validate(valid => {
|
if (!valid) {
|
return
|
}
|
// 判断通过状态
|
if (Number === 2) {
|
this.form.approvalStatus = this.dictGoOutAgree
|
} else {
|
// 退回改状态显示退回原因
|
this.form.approvalStatus = this.dictGoOutReturn
|
if (this.form.approvalDescription == null) {
|
return
|
}
|
}
|
this.successLoading = true
|
crudAttendanceGoOut.approve(this.form).then(res => {
|
this.crud.refresh()
|
this.makeUpCardVisible = false
|
this.successLoading = false
|
this.$message({
|
type: 'success',
|
message: '审核' + msg + '成功'
|
})
|
}).catch(() => {
|
this.makeUpCardVisible = false
|
this.successLoading = false
|
})
|
if (this.$refs['form']) {
|
this.$refs['form'].resetFields()
|
}
|
})
|
},
|
// 撤消功能
|
revoke(data) {
|
this.toApprove(data, '1')
|
this.form.approvalStatus = this.dictGoOutAppRev
|
this.successLoading = true
|
crudAttendanceGoOut.approve(this.form).then(res => {
|
this.crud.refresh()
|
this.successLoading = false
|
this.$message({ type: 'success', message: '撤销成功' })
|
this.$refs[`popover_${data.id}`].showPopper = false
|
}).catch((error) => {
|
this.$message({ type: 'error', message: error.response.data.message })
|
})
|
if (this.$refs['form']) {
|
this.$refs['form'].resetFields()
|
}
|
this.crud.cancelCU()
|
},
|
// 关闭
|
closeCard() {
|
if (this.$refs['form']) {
|
this.$refs['form'].resetFields()
|
}
|
this.crud.cancelCU()
|
this.makeUpCardVisible = false
|
},
|
// 取消
|
canel(data) {
|
this.$refs[`popover_${data.id}`].showPopper = false
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.form-item {
|
width: 100%;
|
display: flex;
|
margin-bottom: 20px;
|
}
|
.form-item-label {
|
width: 20%;
|
display: flex;
|
padding-left: 20px;
|
}
|
.form-item-value {
|
width: 80%;
|
display: flex;
|
padding-left: 25px;
|
padding-right: 25px;
|
}
|
</style>
|