Explorar o código

考勤功能-限制考勤查询日期不能选择今天及以后

zhonghuizhen hai 1 ano
pai
achega
ffae516e4e

+ 29 - 4
src/views/business/attendance/attendanceDetails.vue

@@ -17,6 +17,19 @@
             @sort-change="handleSortChange"
             @pagination-change="handlePaginationChange"
         >
+            <template slot="time">
+                <el-date-picker
+                    v-model="daterRange"
+                    size="mini"
+                    type="daterange"
+                    :picker-options="pickerOptions"
+                    range-separator="至"
+                    start-placeholder="开始日期"
+                    end-placeholder="结束日期"
+                    align="right"
+                    value-format="yyyy-MM-dd"
+                />
+            </template>
             <!-- 自定义多级表头 -->
             <template #prepend-column>
                 <el-table-column key="userName" prop="userName" label="姓名" width="80">
@@ -107,6 +120,15 @@ export default {
                 limit: 15
             },
             sorts: {},
+            daterRange: [],
+            pickerOptions: {
+                disabledDate (time) {
+                    const today = new Date()
+                    today.setHours(0, 0, 0, 0)
+                    // 禁用今天及未来的日期
+                    return time.getTime() >= today.getTime()
+                }
+            },
             listConfig: {
                 toolbars: [
                     { key: 'search', icon: 'ibps-icon-search', label: '查询', type: 'primary' },
@@ -123,7 +145,7 @@ export default {
                         { prop: 'Q^pai_ban_ming_chen^SL', label: '排班名称' },
                         { prop: 'Q^ban_ci_ming_^SL', label: '班次名称' },
                         { prop: 'Q^ban_ci_bie_ming_^SL', label: '班次别名' },
-                        { prop: ['Q^ri_qi_^DL', 'Q^ri_qi_^DG'], label: '日期范围', fieldType: 'daterange' }
+                        { prop: '', label: '日期范围', fieldType: 'slot', slotName: 'time' }
                     ]
                 },
                 columns: []
@@ -147,7 +169,7 @@ export default {
                     item.userName = this.getUserLabel(item.yong_hu_id_)
                     item.deptName = this.getDeptLabel(item.bu_men_)
                 })
-                this.pagination.totalCount = this.listData[0].total_count
+                this.pagination.totalCount = this.listData[0]?.total_count
             }).finally(() => {
                 this.loading = false
             })
@@ -167,17 +189,19 @@ export default {
             const { first, second } = this.$store.getters.level || {}
             const searchParam = this.$refs['crud'] ? this.$refs['crud'].getSearcFormData() : {}
             searchParam['Q^di_dian_^S'] = second || first
+            searchParam['Q^ri_qi_^DGT'] = this.$common.getDateNow()
             return ActionUtils.formatParams(searchParam, this.pagination, this.sorts)
         },
         getSearchSql () {
             const params = this.getSearchFormData()
             const { first, second } = this.$store.getters.level || {}
-            let sql = `select t.*, (select COUNT(*) FROM t_attendance_detail WHERE di_dian_ = '${second || first}') AS total_count FROM t_attendance_detail t`
+            let sql = `select t.*, (select COUNT(*) FROM t_attendance_detail WHERE di_dian_ = '${second || first}' and ri_qi_ < '${this.$common.getDateNow()}') AS total_count FROM t_attendance_detail t`
             // 定义操作符映射
             const operatorMap = {
                 'S': '=',
                 'SL': 'LIKE',
                 'DG': '<=',
+                'DGT': '<',
                 'DL': '>='
             }
             // 如果有查询条件,构建 WHERE 子句
@@ -203,7 +227,8 @@ export default {
                 })
 
                 if (conditions.length > 0) {
-                    sql += ' WHERE ' + conditions.join(' AND ')
+                    const wherestr = ' WHERE ' + conditions.join(' AND ')
+                    sql = `select t.*, (select COUNT(*) FROM t_attendance_detail ${wherestr} ) AS total_count FROM t_attendance_detail t ${wherestr} `
                 }
             }
             // 添加分页

+ 27 - 21
src/views/business/attendance/attendanceOverview.vue

@@ -99,6 +99,12 @@ export default {
             },
             sorts: {},
             daterRange: [],
+            pickerOptions: {
+                disabledDate (time) {
+                    // 禁用今天及以后的日期(time 是当前遍历的日期)
+                    return time.getTime() >= Date.now()
+                }
+            },
             listConfig: {
                 toolbars: [
                     { key: 'search', icon: 'ibps-icon-search', label: '查询', type: 'primary' },
@@ -136,7 +142,7 @@ export default {
                     item.userName = this.getUserLabel(item.yong_hu_id_)
                     item.deptName = this.getDeptLabel(item.bu_men_)
                 })
-                this.pagination.totalCount = this.listData[0].total_count
+                this.pagination.totalCount = this.listData[0]?.total_count
             }).finally(() => {
                 this.loading = false
             })
@@ -213,30 +219,30 @@ export default {
                                 SUM(CASE WHEN da_ka_shi_jian_2_ IS NOT NULL AND da_ka_shi_jian_2_ != '' THEN 1 ELSE 0 END) AS da_ka_ci_shu_,
                                 SUM(ban_ci_shi_chang_) AS total_ban_ci_shi_chang,
                                 SUM(gong_zuo_shi_chan) AS total_gong_zuo_shi_chan,
-                                SUM(CASE WHEN zhuang_tai_1_ = '迟到' THEN 1 ELSE 0 END) + 
-                                SUM(CASE WHEN zhuang_tai_2_ = '迟到' THEN 1 ELSE 0 END) AS chi_dao_ci_shu,
-                                SUM(CASE WHEN zhuang_tai_1_ = '缺勤' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
-                                SUM(CASE WHEN zhuang_tai_2_ = '缺勤' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) AS que_qin_ci_shu,
+                                SUM(CASE WHEN zhuang_tai_1_ = '异常' THEN 1 ELSE 0 END) + 
+                                SUM(CASE WHEN zhuang_tai_2_ = '异常' THEN 1 ELSE 0 END) AS chi_dao_ci_shu,
+                                SUM(CASE WHEN zhuang_tai_1_ = '' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
+                                SUM(CASE WHEN zhuang_tai_2_ = '' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) AS que_qin_ci_shu,
                                 CASE 
-                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '迟到' THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '迟到' THEN 1 ELSE 0 END) > 0 
-                                        AND SUM(CASE WHEN zhuang_tai_1_ = '缺勤' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
-                                            SUM(CASE WHEN zhuang_tai_2_ = '缺勤' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) > 0 
+                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '异常' THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '异常' THEN 1 ELSE 0 END) > 0 
+                                        AND SUM(CASE WHEN zhuang_tai_1_ = '' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
+                                            SUM(CASE WHEN zhuang_tai_2_ = '' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) > 0 
                                     THEN CONCAT('迟到', 
-                                        SUM(CASE WHEN zhuang_tai_1_ = '迟到' THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '迟到' THEN 1 ELSE 0 END), '次,缺勤',
-                                        SUM(CASE WHEN zhuang_tai_1_ = '缺勤' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '缺勤' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END), '次')
-                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '迟到' THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '迟到' THEN 1 ELSE 0 END) > 0 
+                                        SUM(CASE WHEN zhuang_tai_1_ = '异常' THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '异常' THEN 1 ELSE 0 END), '次,缺勤',
+                                        SUM(CASE WHEN zhuang_tai_1_ = '' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END), '次')
+                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '异常' THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '异常' THEN 1 ELSE 0 END) > 0 
                                     THEN CONCAT('迟到', 
-                                        SUM(CASE WHEN zhuang_tai_1_ = '迟到' THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '迟到' THEN 1 ELSE 0 END), '次')
-                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '缺勤' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '缺勤' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) > 0 
+                                        SUM(CASE WHEN zhuang_tai_1_ = '异常' THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '异常' THEN 1 ELSE 0 END), '次')
+                                    WHEN SUM(CASE WHEN zhuang_tai_1_ = '' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END) > 0 
                                     THEN CONCAT('缺勤', 
-                                        SUM(CASE WHEN zhuang_tai_1_ = '缺勤' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
-                                        SUM(CASE WHEN zhuang_tai_2_ = '缺勤' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END), '次')
+                                        SUM(CASE WHEN zhuang_tai_1_ = '' OR zhuang_tai_1_ IS NULL THEN 1 ELSE 0 END) + 
+                                        SUM(CASE WHEN zhuang_tai_2_ = '' OR zhuang_tai_2_ IS NULL THEN 1 ELSE 0 END), '次')
                                     ELSE '正常'
                                 END AS kao_qin_zhuang_tai
                             FROM 

+ 7 - 1
src/views/business/attendance/attendanceStatistics.vue

@@ -127,6 +127,12 @@ export default {
             },
             sorts: {},
             daterRange: [],
+            pickerOptions: {
+                disabledDate (time) {
+                    // 禁用今天及以后的日期(time 是当前遍历的日期)
+                    return time.getTime() >= Date.now()
+                }
+            },
             listConfig: {
                 toolbars: [
                     { key: 'search', icon: 'ibps-icon-search', label: '查询', type: 'primary' },
@@ -164,7 +170,7 @@ export default {
                     item.userName = this.getUserLabel(item.yong_hu_id_)
                     item.deptName = this.getDeptLabel(item.bu_men_)
                 })
-                this.pagination.totalCount = this.listData[0].total_count
+                this.pagination.totalCount = this.listData[0]?.total_count
             }).finally(() => {
                 this.loading = false
             })

+ 30 - 5
src/views/business/attendance/personAttendanceDetails.vue

@@ -17,6 +17,19 @@
             @sort-change="handleSortChange"
             @pagination-change="handlePaginationChange"
         >
+            <template slot="time">
+                <el-date-picker
+                    v-model="daterRange"
+                    size="mini"
+                    type="daterange"
+                    :picker-options="pickerOptions"
+                    range-separator="至"
+                    start-placeholder="开始日期"
+                    end-placeholder="结束日期"
+                    align="right"
+                    value-format="yyyy-MM-dd"
+                />
+            </template>
             <!-- 自定义多级表头 -->
             <template #prepend-column>
                 <el-table-column key="userName" prop="userName" label="姓名" width="80">
@@ -107,6 +120,15 @@ export default {
                 limit: 15
             },
             sorts: {},
+            daterRange: [],
+            pickerOptions: {
+                disabledDate (time) {
+                    const today = new Date()
+                    today.setHours(0, 0, 0, 0)
+                    // 禁用今天及未来的日期
+                    return time.getTime() >= today.getTime()
+                }
+            },
             listConfig: {
                 toolbars: [
                     { key: 'search', icon: 'ibps-icon-search', label: '查询', type: 'primary' },
@@ -116,7 +138,7 @@ export default {
                     labelWidth: 80,
                     forms: [
                         { prop: 'Q^kao_qin_zhuang_ta^SL', label: '考勤状态', fieldType: 'select', options: [{ value: '正常', label: '正常' }, { value: '异常', label: '异常' }] },
-                        { prop: ['Q^ri_qi_^DL', 'Q^ri_qi_^DG'], label: '日期范围', fieldType: 'daterange' },
+                        { prop: '', label: '日期范围', fieldType: 'slot', slotName: 'time' },
                         { prop: 'Q^ban_ci_ming_^SL', label: '班次名称' },
                         { prop: 'Q^ban_ci_bie_ming_^SL', label: '班次别名' },
                         { prop: 'Q^pai_ban_ming_chen^SL', label: '排班名称' }
@@ -144,7 +166,7 @@ export default {
                     item.userName = this.getUserLabel(item.yong_hu_id_)
                     item.deptName = this.getDeptLabel(item.bu_men_)
                 })
-                this.pagination.totalCount = this.listData[0].total_count
+                this.pagination.totalCount = this.listData[0]?.total_count || 0
             }).finally(() => {
                 this.loading = false
             })
@@ -164,19 +186,21 @@ export default {
             const { first, second } = this.$store.getters.level || {}
             const searchParam = this.$refs['crud'] ? this.$refs['crud'].getSearcFormData() : {}
             searchParam['Q^di_dian_^S'] = second || first
+            searchParam['Q^ri_qi_^DGT'] = this.$common.getDateNow()
             // 筛选当前用户数据
             searchParam['Q^yong_hu_id_^S'] = this.$store.getters.userId
             return ActionUtils.formatParams(searchParam, this.pagination, this.sorts)
         },
         getSearchSql () {
             const { first, second } = this.$store.getters.level || {}
-            let sql = `select t.*, (select COUNT(*) FROM t_attendance_detail WHERE di_dian_ = '${second || first}' AND yong_hu_id_ = '${this.$store.getters.userId}' ) AS total_count FROM t_attendance_detail t `
+            let sql = `select t.*, (select COUNT(*) FROM t_attendance_detail WHERE di_dian_ = '${second || first}' AND yong_hu_id_ = '${this.$store.getters.userId}' and ri_qi_ < '${this.$common.getDateNow()}' ) AS total_count FROM t_attendance_detail t `
             const params = this.getSearchFormData()
             // 定义操作符映射
             const operatorMap = {
                 'S': '=',
                 'SL': 'LIKE',
                 'DG': '<=',
+                'DGT': '<',
                 'DL': '>='
             }
             // 如果有查询条件,构建 WHERE 子句
@@ -200,9 +224,10 @@ export default {
                         }
                     }
                 })
-
+                debugger
                 if (conditions.length > 0) {
-                    sql += ' WHERE ' + conditions.join(' AND ')
+                    const wherestr = ' WHERE ' + conditions.join(' AND ')
+                    sql = `select t.*, (select COUNT(*) FROM t_attendance_detail ${wherestr} ) AS total_count FROM t_attendance_detail t ${wherestr} `
                 }
             }
             // 添加分页

+ 3 - 55
src/views/system/dashboard/components/util.js

@@ -729,65 +729,13 @@ export function buildComponent (name, column, preview, vm) {
                         this.$message.warning('考勤数据异常!')
                         return
                     }
+                    debugger
                     // 更新打卡请求
-                    attendanceDetailClockIn(attendance.id_).then(() => {
+                    attendanceDetailClockIn({ id: attendance.id_ }).then(() => {
                         this.$message.success('打卡成功!')
                     }).catch(() => {
-                        this.$message.warning('打卡失败')
+                        // this.$message.warning('打卡失败')
                     })
-                    /*
-                    // 获取当前时间
-                    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 < attendance.ban_ci_jie_shu_) { // 上班打卡
-                        if (!attendance.da_ka_shi_jian_1_) {
-                            attendance.da_ka_shi_jian_1_ = dakashijian
-                            attendance.zhuang_tai_1_ = time < attendance.ban_ci_kai_shi_ ? '正常' : '迟到'
-                            if (attendance.zhuang_tai_1_ === '迟到') {
-                                attendance.chi_dao_shi_chang = this.getTimeDifferenceInMinutes(attendance.ban_ci_kai_shi_, time)
-                                attendance.kao_qin_zhuang_ta = '异常' // 总考勤状态设置为异常
-                            }
-                        } else {
-                            this.$message.warning('该班次上班已打卡!')
-                            return
-                        }
-                    } else { // 下班打卡
-                        // 在班次结束时间后初始点击打卡按钮,视作下班打卡,再次点击打卡按钮则更新下班打卡时间并提示更新打卡时间成功
-                        if (attendance.da_ka_shi_jian_2_) {
-                            str = '已更新下班打卡!'
-                        }
-                        attendance.da_ka_shi_jian_2_ = dakashijian
-                        attendance.zhuang_tai_2_ = '正常'
-                    }
-                    const tableName = ' t_attendance_detail'
-                    const updateParams = {
-                        tableName,
-                        updList: [
-                            {
-                                where: {
-                                    id_: attendance.id_
-                                },
-                                param: {
-                                    da_ka_shi_jian_1_: attendance.da_ka_shi_jian_1_,
-                                    zhuang_tai_1_: attendance.zhuang_tai_1_,
-                                    da_ka_shi_jian_2_: attendance.da_ka_shi_jian_2_,
-                                    zhuang_tai_2_: attendance.zhuang_tai_2_,
-                                    kao_qin_zhuang_ta: attendance.kao_qin_zhuang_ta,
-                                    chi_dao_shi_chang: attendance.chi_dao_shi_chang
-                                }
-                            }
-                        ]
-                    }
-                    this.$common.request('update', updateParams).then(() => {
-                        this.$message.success(str)
-                    })
-                */
                 },
                 getTimeDifferenceInMinutes (startTimeStr, endTimeStr) { // 时间相减分钟数
                     const startTime = new Date(startTimeStr)

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

@@ -758,73 +758,12 @@ export default {
             this.$common.request('sql', sql).then(res => {
                 const data = res.variables.data[0] || {}
                 // 更新打卡请求
-                attendanceDetailClockIn(data.id_).then(() => {
+                attendanceDetailClockIn({ id: data.id_ }).then(() => {
                     this.$message.success('打卡成功!')
                 }).catch(() => {
-                    this.$message.warning('打卡失败')
+                    // this.$message.warning('打卡失败')
                 })
             })
-            /*
-            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)