basicSalaryDialog.vue 8.76 KB
<!-- 基本工资明细 -->
<template>
  <div class="basic-dialog">
    <d2-dialog
        title="考勤明细"
        :is-visible="visible"
        noCancel
        :isShowFooter="false"
        width="720px"
        @closeDialog="handleConfirm"
        @confirmDialog="handleConfirm"
      >
      <div class="top-box">
        <div class="item">本月应出勤天数:{{ staticData.requiredAttendanceDays }}天</div>
        <div class="item">实际出勤天数:{{ staticData.actualAttendanceDays }}</div>
      </div>
      <div class="content">
        <el-tabs v-model="activeName">
          <el-tab-pane
            v-for="item in tabList"
            :key="item.id"
            :label="item.label"
            :name="item.id"
          >
            <el-table
              v-if="item.tableData.length"
              :data="item.tableData"
              max-height="470px"
              class="table_class"
              border
              :header-cell-style="{
                'text-align': 'center',
                'background-color': '#fafafa'
              }"
              show-summary
              :summary-method="getSummaries"
              style="width: 100%"
            >
              <el-table-column
                type="index"
                align="center"
                label="序号"
                width="80"
              />
              <el-table-column
                :prop="'attendanceType'"
                align="center"
                label="考勤类型"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.attendanceType || '-' }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :prop="'clockInDate'"
                align="center"
                label="考勤日期"
              />
              <el-table-column
                :prop="'deductionDays'"
                align="center"
                :label="activeName != '2' ? '扣减天数' : '考勤天数'"
              />
            </el-table>
            <div class="empty-box" v-else>
              <img src="@/assets/empty.png">
              <div class="empty-text">暂无记录</div>
            </div>
          </el-tab-pane>
        </el-tabs>
        
      </div>
    </d2-dialog>
  </div>
</template>

<script>
import BigNumber from 'bignumber.js'
import { getStaffAttendanceDetailAPI } from '@api/resident.js'
import { isEmpty } from '../util.js'
export default {
  name: 'BasicSalaryDialog',
  data() {
    return {
      isEmpty,
      activeName: '0',
      tabList: [{
        label: '扣减天数',
        id: '0',
        tableData: []
      }, {
        label: '着装异常',
        id: '1',
        tableData: []
      }, {
        label: '法定节假日加班',
        id: '2',
        tableData: []
      }],
      staticData: {}
    }
  },
  props: {
    basicVisible: {
      type: Boolean,
      default: false
    },
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  computed: {
    visible: {
      get() {
        return this.basicVisible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'basicVisible' })
      }
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    // 处理请求接口日期传参
    getMonthStartEndWithTime(monthStr) {
      const [year, month] = monthStr.split('-').map(Number)
      const firstDay = new Date(year, month - 1, 1, 0, 0, 0)
      const firstDayStr = this.formatDateTime(firstDay)
      const lastDay = new Date(year, month, 0, 23, 59, 59)
      const lastDayStr = this.formatDateTime(lastDay)
      return {
        firstDay: firstDayStr,
        lastDay: lastDayStr
      }
    },
    formatDateTime(date) {
      const y = date.getFullYear();
      const m = String(date.getMonth() + 1).padStart(2, '0');
      const d = String(date.getDate()).padStart(2, '0');
      const hh = String(date.getHours()).padStart(2, '0');
      const mm = String(date.getMinutes()).padStart(2, '0');
      const ss = String(date.getSeconds()).padStart(2, '0');
      return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    },
    getDetail() {
      let { firstDay, lastDay } = this.getMonthStartEndWithTime(this.detailInfo?.salaryMonth)
      let params = {
        pageSize: 9999,
        currentPage: 1,
        staffPhone: this.detailInfo?.staffPhone,
        commitTimeStart: firstDay,
        commitTimeEnd:  lastDay
      }
      getStaffAttendanceDetailAPI(params).then(res => {
        res?.exceptionInfoList?.forEach(val => {
          val?.exceptionDetailList?.forEach(v => {
            v.attendanceType = `${!this.isEmpty(v.attendanceType) ? v.attendanceType : ''}${!this.isEmpty(v.exceptionState) ? v.exceptionState : ''}`
          })
        })
        // 实际出勤天数大于等于应出勤天数,显示满勤
        if (Number(res?.actualAttendanceDays) >= Number(res?.requiredAttendanceDays)) {
          res.actualAttendanceDays = '满勤'
        } else {
          res.actualAttendanceDays = `${res?.actualAttendanceDays}天`
        }
        this.tabList = this.categorizeData(res?.exceptionInfoList, [1, 2, 3, 4])
        this.staticData = res || {}
      })
    },
    // 处理返回数据
    categorizeData(originalData, typeGroups) {
      const result = this.tabList
      originalData?.forEach(item => {
        const detailList = item?.exceptionDetailList || []
        // 扣减天数
        if (typeGroups?.includes(item.exceptionType)) {
          this.processAndPushData(detailList, result[0].tableData, '-')
        // 着装异常
        } else if (item.exceptionType === 5) {
          this.processAndPushData(detailList, result[1].tableData, '-')
        // 加班
        } else if (item.exceptionType === 6) {
          this.processAndPushData(detailList, result[2].tableData, '+')
        }
      })
      return result
    },
    processAndPushData(sourceData, targetArray, prefix) {
      sourceData.forEach(item => {
        const days = Number(item.deductionDays)
          targetArray.push({
            ...item,
            deductionDays: isNaN(days) ? item.deductionDays : `${prefix}${Math.abs(days)}`
          })
      })
    },
    // 表格底部累加
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = this.activeName == '2' ? '加班天数合计' : '扣减天数合计'
          column.align = "is-left"
          column.colSpan = 3
          return
        }

        if (index === 1) {
          const numberList = this.tabList[Number(this.activeName)]?.tableData.map((item) => !isNaN(item.deductionDays) ? item.deductionDays : 0)
          const total = (numberList.length
              ? numberList.reduce((preVal, curVal) => {
                  return `${new BigNumber(preVal || 0).plus(new BigNumber(curVal || 0)).toNumber()}`
                })
              : "0")
              sums[index] = `${this.activeName == '2' && total > 0 ? '+' : ''}${Number(total)}天`
        }
      })
      return sums
    },
    handleConfirm() {
      this.$emit('dialogClose')
    }
  }
}
</script>
<style lang="scss" scoped>
.basic-dialog{
  ::v-deep .el-dialog__header {
    color: #333333;
    font-family: PingFangSC-Medium;
    font-size: 20px;
    font-weight: 600;
    border-bottom: 1px solid #e6e6e6;
  }
  ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #666;
    font-weight: 600;
    font-size: 20px;
  }
  .top-box {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    .item {
      width: 50%;
    }
  }
  .content {
    ::v-deep .el-tabs__header {
      position: relative;
      .el-tabs__nav-scroll{
        background: transparent;
        padding: 0;
        overflow: hidden;
        
        .el-tabs__nav {
          background: transparent;
          height: auto;
          border-radius: 0;
          margin-left: 0;
          padding: 0;
          .el-tabs__active-bar {
            display: inline-block !important;
          }
          .el-tabs__item {
            height: 40px;
            line-height: 40px;
            padding: 0 10px;
          }
          .el-tabs__item.is-active {
            color: #2A58AD;
            font-weight: 600;
            background: transparent;
            border: none;
          }
        }
      }
    }
  }
  
  .table_class {
    margin-top: 10px !important;
    max-height: calc(68vh - 130px);
    overflow-y: auto;
    ::v-deep .el-table__row{
      height: 48px;
      td {
        text-align: center;
      }
    }
    ::v-deep .el-table__footer-wrapper .has-gutter{
      height: 48px;
    }
  }
  .empty-box {
    text-align: center;
    padding-bottom: 80px;
    img {
      width: 64px;
      height: 40px;
      margin-top: 100px;
    }
    .empty-text {
      font-size: 14px;
      color: #999999;
    }
  }
}
</style>