<template>
  <div class="ele-body">
    <el-card shadow="never">
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="systemRoleTable18"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openAdd('add')"
          >
            新建
          </el-button>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="SchedulingGroupPeople(row)"
          >
            按人排班
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="bpb(row)"
          >
            按班排班
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此角色吗？"
            @confirm="remove(row)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <SchedulingGroup ref="SchedulingGroup"></SchedulingGroup>
  </div>
</template>
<script>
  import SchedulingGroup from './components/SchedulingGroup.vue';
  import {
    teamqueuepage,
    deleteteamtime
  } from '@/api/workforceManagement/schedule';
  export default {
    components: {
      SchedulingGroup
    },
    data () {
      return {
        columns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed:'left'
          },
          {
            prop: 'name',
            label: '排班组名称'
          },
          {
            label: '总人数',
            prop: 'totalPersonNumber'
          },
          {
            label: '创建人',
            prop: 'createUserName'
          },
          {
            label: '创建时间',
            prop: 'createTime'
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 260,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true,
            fixed:'right'
          }
        ],
        dict: {
          enabled: {
            1: '生效',
            0: '未生效'
          },
          groupId: []
        }
      };
    },
    methods: {
      datasource ({ page, where, limit }) {
        let data = teamqueuepage({
          ...where,
          pageNum: page,
          size: limit
        });
        console.log(data);
        return data;
      },
      // 按人排班
      SchedulingGroupPeople (row) {
        this.$router.push({
          path: '/workforceManagement/schedule/detail',
          query: {
            type: 'edit',
            id: row.id
          }
        });
      },
      // 按班排班
      bpb (row) {
        this.$router.push({
          path: '/workforceManagement/schedule/detail',
          query: {
            type: 'edit',
            id: row.id,
            isSchedule: '1'
          }
        });
      },
      // 排版组
      openAdd () {
        this.$refs.SchedulingGroup.open();
      },
      remove (row) {
        let par = [row.id];
        deleteteamtime(par)
          .then((message) => {
            this.$message.success(message);
            this.done();
          })
          .catch((e) => {
            this.$message.error(e.message);
          });
      },
      done () {
        this.$refs.table.reload({
          page: 1
        });
      },
      openclass () {
        this.$refs.setclasses.open();
      }
    }
  };
</script>
