Эх сурвалжийг харах

考勤功能:修复首页打卡无法响应

zhonghuizhen 1 жил өмнө
parent
commit
2217631ce0

+ 67 - 0
src/views/business/attendance/dakaDialog.vue

@@ -0,0 +1,67 @@
+<template>
+    <el-dialog
+        :visible.sync="visible"
+        title="选择打卡班次"
+        width="400px"
+        @close="handleClose">
+        <div class="schedule-dialog">
+            <el-radio-group v-model="selectedValue">
+                <el-radio
+                    v-for="schedule in schedules"
+                    :key="schedule"
+                    :label="schedule"
+                    style="display: block; margin: 10px 0;">
+                    {{ schedule }}
+                </el-radio>
+            </el-radio-group>
+        </div>
+        <span slot="footer" class="dialog-footer">
+            <el-button @click="visible = false">取消</el-button>
+            <el-button type="primary" @click="handleConfirm">确定</el-button>
+        </span>
+    </el-dialog>
+</template>
+<script>
+export default {
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        schedules: {
+            type: Array,
+            default: () => []
+        }
+    },
+    data () {
+        return {
+            selectedValue: ''
+        }
+    },
+    watch: {
+        schedules (newVal) {
+            if (newVal) {
+                this.selectedValue = newVal
+            }
+        }
+    },
+    methods: {
+        handleConfirm () {
+            if (!this.selectedValue) {
+                this.$message.warning('请选择一个班次')
+                return
+            }
+            this.$emit('confirm', this.selectedValue)
+            this.visible = false
+        },
+        handleClose () {
+            this.$emit('close')
+        }
+    }
+}
+</script>
+<style scoped>
+  .schedule-dialog {
+    padding: 0 10px;
+  }
+</style>

+ 1 - 1
src/views/business/attendance/makeUpEdit.vue

@@ -94,7 +94,7 @@ import { queryAttendanceDetail, saveAttendanceReissue } from '@/api/business/att
 import IbpsAttachment from '@/business/platform/file/attachment/selector'
 import IbpsAttachment from '@/business/platform/file/attachment/selector'
 import ActionUtils from '@/utils/action'
 import ActionUtils from '@/utils/action'
 export default {
 export default {
-    name: 'makeupedit',
+    // name: 'makeupedit',
     components: {
     components: {
         IbpsAttachment
         IbpsAttachment
     },
     },

+ 10 - 60
src/views/system/dashboard/components/util.js

@@ -596,7 +596,7 @@ export function buildComponent (name, column, preview, vm) {
                 getTodaySchedule () { // 获取今日班次
                 getTodaySchedule () { // 获取今日班次
                     const { first, second } = this.$store.getters.level || {}
                     const { first, second } = this.$store.getters.level || {}
                     const today = this.$common.getDateNow()
                     const today = this.$common.getDateNow()
-                    const sql = `select a.*, b.start_date_, b.end_date_ from t_schedule_detail a, t_schedule b where a.parent_id_ = b.id_ and b.di_dian_ = '${second || first}' and a.user_id_ = '${this.userId}' and b.status_ = '已发布'`
+                    const sql = `select a.*, b.start_date_, b.end_date_, b.config_, b.id_ as pai_ban_id_ from t_schedule_detail a, t_schedule b where a.parent_id_ = b.id_ and b.di_dian_ = '${second || first}' and a.user_id_ = '${this.userId}' and b.status_ = '已发布'`
                     return new Promise((resolve, reject) => {
                     return new Promise((resolve, reject) => {
                         this.$common.request('sql', sql).then((res) => {
                         this.$common.request('sql', sql).then((res) => {
                             const { data = [] } = res.variables || {}
                             const { data = [] } = res.variables || {}
@@ -604,6 +604,9 @@ export function buildComponent (name, column, preview, vm) {
                             data.forEach(item => {
                             data.forEach(item => {
                                 const days = this.getDays(item.start_date_, today)
                                 const days = this.getDays(item.start_date_, today)
                                 const shift = item[`d${days}_`]
                                 const shift = item[`d${days}_`]
+                                const config = item.config_ ? JSON.parse(item.config_) : {}
+                                const { scheduleShift } = config
+                                this.scheduleShift = scheduleShift
                                 if (shift) {
                                 if (shift) {
                                     const shiftList = shift.split(',')
                                     const shiftList = shift.split(',')
                                     todaySchedule = shiftList // 返回今日班次
                                     todaySchedule = shiftList // 返回今日班次
@@ -713,7 +716,7 @@ export function buildComponent (name, column, preview, vm) {
                 },
                 },
                 showDaKaBtn (targetDay) { // 判断是否展示打卡按钮,当前日期则展示
                 showDaKaBtn (targetDay) { // 判断是否展示打卡按钮,当前日期则展示
                     const today = this.$common.getDateNow()
                     const today = this.$common.getDateNow()
-                    if (targetDay == today) {
+                    if (targetDay === today) {
                         return true
                         return true
                     } else {
                     } else {
                         return false
                         return false
@@ -738,7 +741,7 @@ export function buildComponent (name, column, preview, vm) {
                         if (!attendance.da_ka_shi_jian_1_) {
                         if (!attendance.da_ka_shi_jian_1_) {
                             attendance.da_ka_shi_jian_1_ = dakashijian
                             attendance.da_ka_shi_jian_1_ = dakashijian
                             attendance.zhuang_tai_1_ = time < attendance.ban_ci_kai_shi_ ? '正常' : '迟到'
                             attendance.zhuang_tai_1_ = time < attendance.ban_ci_kai_shi_ ? '正常' : '迟到'
-                            if (attendance.zhuang_tai_1_ == '迟到') {
+                            if (attendance.zhuang_tai_1_ === '迟到') {
                                 attendance.chi_dao_shi_chang = this.getTimeDifferenceInMinutes(attendance.ban_ci_kai_shi_, time)
                                 attendance.chi_dao_shi_chang = this.getTimeDifferenceInMinutes(attendance.ban_ci_kai_shi_, time)
                                 attendance.kao_qin_zhuang_ta = '异常' // 总考勤状态设置为异常
                                 attendance.kao_qin_zhuang_ta = '异常' // 总考勤状态设置为异常
                             }
                             }
@@ -789,64 +792,11 @@ export function buildComponent (name, column, preview, vm) {
                 handleClockFromTab (todaySchedule) {
                 handleClockFromTab (todaySchedule) {
                     const today = this.$common.getDateNow()
                     const today = this.$common.getDateNow()
                     // 当天仅有一个班次
                     // 当天仅有一个班次
-                    if (todaySchedule.length == 1) {
-                        const scheduleObj = this.scheduleData.filter(item => item.start == today && item.alias == todaySchedule[0])
-                        const attendance = scheduleObj.attendance
-                        this.handleClock(attendance)
+                    if (todaySchedule.length === 1) {
+                        this.$emit('dakaSingle', todaySchedule[0])
+                        return
                     } else {
                     } else {
-                        let scheduleArr = []
-                        for (let i = 0; i < todaySchedule.length; i++) {
-                            const currentSchedule = todaySchedule[i]
-                            const filtered = this.scheduleData.filter(item => item.start === today && item.alias === currentSchedule)
-                            scheduleArr = scheduleArr.concat(filtered)
-                        }
-                        const h = this.$createElement
-                        const self = this
-                        this.$msgbox({
-                            title: '选择打卡班次',
-                            message: h('div', null, [
-                                h('p', { style: 'margin-bottom: 15px;' }, '请选择一个班次打卡'),
-                                h('el-radio-group', {
-                                    model: {
-                                        value: self.tempSelectedValue,
-                                        callback: (value) => {
-                                            self.tempSelectedValue = value
-                                        }
-                                    }
-                                }, scheduleArr.map(schedule =>
-                                    h('el-radio', {
-                                        props: {
-                                            label: schedule.alias,
-                                            key: schedule.alias
-                                        },
-                                        style: 'display: block; margin: 10px 0;'
-                                    }, schedule.alias))
-                                )
-                            ]),
-                            showCancelButton: true,
-                            confirmButtonText: '确定',
-                            cancelButtonText: '取消',
-                            beforeClose: (action, instance, done) => {
-                                if (action === 'confirm') {
-                                    if (!this.tempSelectedValue) {
-                                        this.$message.warning('请选择一个班次')
-                                        return false
-                                    }
-                                    done()
-                                } else {
-                                    done()
-                                }
-                            }
-                        }).then(() => {
-                            const scheduleObj = this.scheduleData.find(item => 
-                                item.start === today && item.alias === this.tempSelectedValue
-                            )
-                            if (scheduleObj?.attendance) {
-                                this.handleClock(scheduleObj.attendance)
-                            }
-                        }).catch(() => {
-                            // 用户取消操作
-                        })
+                        this.$emit('action-event', 'daka', todaySchedule)
                     }
                     }
                 },
                 },
                 async showMySchedule () {
                 async showMySchedule () {

+ 84 - 2
src/views/system/homepage/index.vue

@@ -144,6 +144,12 @@
             @closeBuKaDialog="handleClose"
             @closeBuKaDialog="handleClose"
             @open="handleOpen"
             @open="handleOpen"
         />
         />
+        <daka-dialog
+            :visible.sync="dakaDialogVisible"
+            :schedules="dakaArr"
+            @confirm="handleDakaConfirm"
+            @close="dakaDialogVisible = false"
+        />
     </ibps-container>
     </ibps-container>
 </template>
 </template>
 
 
@@ -172,6 +178,7 @@ import { markReadCalendar } from '@/api/detection/newHomeApi'
 import CalendarAlert from '@/views/system/dashboard/components/calendar-alert.vue'
 import CalendarAlert from '@/views/system/dashboard/components/calendar-alert.vue'
 import mySchedule from './components/mySchedule.vue'
 import mySchedule from './components/mySchedule.vue'
 import makeUpEdit from '@/views/business/attendance/makeUpEdit.vue'
 import makeUpEdit from '@/views/business/attendance/makeUpEdit.vue'
+import dakaDialog from '@/views/business/attendance/dakaDialog.vue'
 
 
 const _import = require('@/utils/util.import.' + process.env.NODE_ENV)
 const _import = require('@/utils/util.import.' + process.env.NODE_ENV)
 export default {
 export default {
@@ -187,7 +194,8 @@ export default {
         CalendarAlert,
         CalendarAlert,
         mySchedule,
         mySchedule,
         banciDialog,
         banciDialog,
-        makeUpEdit: makeUpEdit
+        makeUpEdit,
+        dakaDialog
     },
     },
     data () {
     data () {
         return {
         return {
@@ -247,7 +255,10 @@ export default {
             banciInfo: {},
             banciInfo: {},
             banciDialogVisible: false,
             banciDialogVisible: false,
             bukaInfo: {},
             bukaInfo: {},
-            makeUpEditVisible: false
+            makeUpEditVisible: false,
+            dakaDialogVisible: false,
+            dakaArr: [],
+            tempSelectedValue: ''
         }
         }
     },
     },
     computed: {
     computed: {
@@ -395,6 +406,9 @@ export default {
                 case 'mySchedule':
                 case 'mySchedule':
                     this.handleMySchedule(params)
                     this.handleMySchedule(params)
                     break
                     break
+                case 'daka':
+                    this.handleDakaDialog(params)
+                    break
                 default:
                 default:
                     break
                     break
             }
             }
@@ -734,6 +748,74 @@ export default {
         handleMySchedule (data) {
         handleMySchedule (data) {
             this.scheduleConfig = data
             this.scheduleConfig = data
             this.$refs.schedule.openDialog()
             this.$refs.schedule.openDialog()
+        },
+        dakaSingle (selectedValue) {
+            const today = this.$common.getDateNow()
+            const { first, second } = this.$store.getters.level || {}
+            // 查询该班次对应的考勤数据
+            const sql = `select a.* FROM t_attendance_detail a JOIN t_schedule b ON a.pai_ban_id_ = b.id_ AND b.status_ = '已发布' WHERE a.di_dian_ = '${second || first}' AND a.ri_qi_ = '${today}' AND a.yong_hu_id_ = '${this.$store.getters.userId}' and a.ban_ci_bie_ming_ = '${selectedValue}' `
+            this.$common.request('sql', sql).then(res => {
+                const data = res.variables.data[0] || {}
+                // 获取当前时间
+                const currentDate = new Date()
+                const hours = currentDate.getHours()
+                const minutes = currentDate.getMinutes()
+                const dakashijian = `${hours}:${minutes}`
+                const time = this.$common.getDateNow() + ' ' + dakashijian
+                let str = '打卡成功!'
+                // 在班次结束时间前初次点击打卡按钮,视作上班打卡,自动判定状态为正常或迟到(迟到需记录迟到时长);再次点击打卡按钮提示已打卡
+                if (time < data.ban_ci_jie_shu_) { // 上班打卡
+                    if (!data.da_ka_shi_jian_1_) {
+                        data.da_ka_shi_jian_1_ = dakashijian
+                        data.zhuang_tai_1_ = time < data.ban_ci_kai_shi_ ? '正常' : '迟到'
+                        if (data.zhuang_tai_1_ === '迟到') {
+                            data.chi_dao_shi_chang = this.getTimeDifferenceInMinutes(data.ban_ci_kai_shi_, time)
+                            data.kao_qin_zhuang_ta = '异常' // 总考勤状态设置为异常
+                        }
+                    } else {
+                        this.$message.warning('该班次上班已打卡!')
+                        return
+                    }
+                } else { // 下班打卡
+                    // 在班次结束时间后初始点击打卡按钮,视作下班打卡,再次点击打卡按钮则更新下班打卡时间并提示更新打卡时间成功
+                    if (data.da_ka_shi_jian_2_) {
+                        str = '已更新下班打卡!'
+                    }
+                    data.da_ka_shi_jian_2_ = dakashijian
+                    data.zhuang_tai_2_ = '正常'
+                }
+                // 更新打卡请求
+                const tableName = ' t_attendance_detail'
+                const updateParams = {
+                    tableName,
+                    updList: [
+                        {
+                            where: {
+                                id_: data.id_
+                            },
+                            param: {
+                                da_ka_shi_jian_1_: data.da_ka_shi_jian_1_,
+                                zhuang_tai_1_: data.zhuang_tai_1_,
+                                da_ka_shi_jian_2_: data.da_ka_shi_jian_2_,
+                                zhuang_tai_2_: data.zhuang_tai_2_,
+                                kao_qin_zhuang_ta: data.kao_qin_zhuang_ta,
+                                chi_dao_shi_chang: data.chi_dao_shi_chang
+                            }
+                        }
+                    ]
+                }
+                this.$common.request('update', updateParams).then(() => {
+                    this.$message.success(str)
+                })
+            }).catch(() => {
+            })
+        },
+        handleDakaConfirm (selectedValue) {
+            this.dakaSingle(selectedValue)
+        },
+        handleDakaDialog (data) {
+            this.dakaArr = data
+            this.dakaDialogVisible = true
         }
         }
     }
     }
 }
 }