<template>
  <div class="ele-body">
    <el-card shadow="never">
      <useSearch @search="reload" ></useSearch>
      <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:status="{ row }">
          {{ dict.enabled[row.status] }}
        </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="确定要删除此排班吗？" v-if="row.status == 0" @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>


          <el-popconfirm class="ele-action" title="确定要发布此排班？" @confirm="issue(row)" v-if="row.status == 0">
            <template v-slot:reference>
              <el-link type="primary" :underline="false">
                发布
              </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,
  teamqueueUpdate
} from '@/api/workforceManagement/schedule';
import useSearch from './components/use-search'
export default {
  components: {
    SchedulingGroup,
    useSearch
  },
  data() {
    return {
      columns: [
        {
          width: 45,
          type: 'index',
          columnKey: 'index',
          align: 'center',
          fixed: 'left'
        },
        {
          prop: 'name',
          label: '排班组名称'
        },
        {
          label: '总人数',
          prop: 'totalPersonNumber'
        },
        {
          label: '创建人',
          prop: 'createUserName'
        },
        {
          label: '状态',
          prop: 'status',
          slot: 'status',
        },

        {
          label: '创建时间',
          prop: 'createTime'
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 300,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,
          fixed: 'right'
        }
      ],
      dict: {
        enabled: {
          1: '发布',
          0: '草稿'
        },
      }
    };
  },
  methods: {
    datasource({ page, where, limit }) {
      let data = teamqueuepage({
        ...where,
        pageNum: page,
        size: limit
      });
      console.log(data);
      return data;
    },

    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({ where: where });
    },

    // 按人排班
    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();
        })

    },
    done() {
      this.$refs.table.reload({
        page: 1
      });
    },
    openclass() {
      this.$refs.setclasses.open();
    },

    issue(row) {
      let param = {
        id: row.id,
        status: 1
      }
      teamqueueUpdate(param).then((msg) => {
        this.$message.success(message);
        this.done();
      }).catch((e) => {
        this.$message.error(e.message);
      });
    },
  }
};
</script>
