attendance-group-table.vue 4.15 KB
<template>
  <el-card class="setting-card" shadow="never">
    <div slot="header" class="card-header">
      <span>考勤分组设置</span>
      <el-button type="primary" size="mini" icon="el-icon-plus" @click="addRow">新增分组</el-button>
    </div>
    <NCC-table :data="value" border size="mini" height="260">
      <el-table-column label="分组名称" min-width="150" align="left">
        <template slot-scope="scope">
          <el-input v-model="scope.row.groupName" placeholder="例如:门店组" />
        </template>
      </el-table-column>
      <el-table-column label="上班时间" min-width="130" align="left">
        <template slot-scope="scope">
          <el-time-picker
            v-model="scope.row.workStartTime"
            value-format="HH:mm"
            format="HH:mm"
            placeholder="09:00"
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="下班时间" min-width="130" align="left">
        <template slot-scope="scope">
          <el-time-picker
            v-model="scope.row.workEndTime"
            value-format="HH:mm"
            format="HH:mm"
            placeholder="19:00"
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="月应休天数" min-width="120" align="left">
        <template slot-scope="scope">
          <el-input-number v-model="scope.row.monthlyRestDays" :min="0" :precision="0" controls-position="right" style="width: 100%" />
        </template>
      </el-table-column>
      <el-table-column label="是否启用" width="100" align="left">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.isEnabled" :active-value="1" :inactive-value="0" />
        </template>
      </el-table-column>
      <el-table-column label="备注" min-width="180" align="left">
        <template slot-scope="scope">
          <el-input v-model="scope.row.remark" placeholder="无" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="left">
        <template slot-scope="scope">
          <el-button type="text" @click="showUsers(scope.row)">成员详情</el-button>
          <el-popconfirm
            title="确认删除当前配置吗?"
            confirm-button-text="确认删除"
            cancel-button-text="取消"
            @confirm="removeRow(scope.$index)"
          >
            <el-button slot="reference" type="text" class="danger-text">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </NCC-table>
    <div class="table-tip">分组成员请到“用户管理-编辑用户”中单独指定考勤分组,也可以在这里查看分组成员详情。</div>
    <el-empty v-if="!value.length" :image-size="56" description="暂无考勤分组配置" />
    <attendance-group-user-dialog ref="userDialog" />
  </el-card>
</template>

<script>
import AttendanceGroupUserDialog from './attendance-group-user-dialog'

export default {
  name: 'AttendanceGroupTable',
  components: {
    AttendanceGroupUserDialog
  },
  props: {
    value: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    addRow() {
      this.$emit('input', [
        ...this.value,
        {
          groupName: '',
          workStartTime: '09:00',
          workEndTime: '19:00',
          monthlyRestDays: 4,
          isEnabled: 1,
          remark: ''
        }
      ])
    },
    removeRow(index) {
      const list = this.value.slice()
      list.splice(index, 1)
      this.$emit('input', list)
    },
    showUsers(row) {
      if (!row.id) {
        this.$message.warning('请先保存分组设置后再查看成员详情')
        return
      }
      this.$refs.userDialog.init(row)
    }
  }
}
</script>

<style lang="scss" scoped>
.setting-card {
  border-radius: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.table-tip {
  margin-top: 8px;
  color: #909399;
  font-size: 12px;
}

.danger-text {
  color: #f56c6c;
}

::v-deep .el-card__header {
  padding: 12px 16px;
}

::v-deep .el-card__body {
  padding: 12px 14px;
}
</style>