<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <search-bar
      :formConfigs="formConfig"
      ref="searchBarForm"
      @headBtnClick="buttonClick"
    />
    <!-- 列表 -->
    <base-table
      :page="queryParams.pageNo"
      :limit="queryParams.pageSize"
      :table-props="tableProps"
      :table-data="list"
      :max-height="tableH"
    >
      <method-btn
        v-if="tableBtn.length"
        slot="handleBtn"
        :width="160"
        label="操作"
        :method-list="tableBtn"
        @clickBtn="handleClick"
      />
    </base-table>
    <pagination
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
    <!-- 查看生产情况 -->
    <team-production-detail v-if='paramVisible' ref='schedulingMonitoringDetail'/>
  </div>
</template>
<script>
import { groupTeamSchedulingPage } from '@/api/monitoring/teamProduction'
import { parseTime } from '@/utils/ruoyi'
import TeamProductionDetail from './components/teamProductionDetail'
const tableProps = [
  {
    prop: 'createTime',
    label: '排班创建时间',
    filter: parseTime
  },
  {
    prop: 'startDay',
    label: '上班日期'
  },
  {
    prop: 'startTime',
    label: '上班时间',
    filter: parseTime
  },
  {
    prop: 'endTime',
    label: '下班时间',
    filter: parseTime
  },
  {
    prop: 'classesName',
    label: '班次名称'
  },
  {
    prop: 'teamName',
    label: '班组名称'
  }
]
const tableBtn = [
  {
    type: 'viewDetail',
    btnName: '查看生产情况'
  }
]
export default {
  name: 'GroupTeamScheduling',
  data() {
    return {
      formConfig: [
        {
          type: 'select',
          label: '班次信息',
          selectOptions: [],
          param: 'classesId'
        },
        {
          type: 'input',
          label: '班组信息',
          placeholder: '班组信息',
          param: 'teamName'
        },
        {
          type: 'datePicker',
          label: '上班日期',
          dateType: 'date',
          format: 'yyyy-MM-dd HH:mm:ss',
          valueFormat: "timestamp",
          param: 'startDay',
          defaultSelect: '',
          width: 200
        },
        {
          type: 'button',
          btnName: '查询',
          name: 'search',
          color: 'primary'
        }
      ],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 20,
        classesId: '',
        teamName: '',
        startDay: ''
      },
      tableProps,
      tableBtn,
      list: [],
      tableH: this.tableHeight(220),
      total: 0,
      paramVisible: false
    }
  },
  components: { TeamProductionDetail },
  mounted() {
    window.addEventListener('resize', () => {
      this.tableH = this.tableHeight(220)
    })
    this.getList()
  },
  methods: {
    buttonClick(val) {
      this.queryParams.pageNo = 1;
      this.queryParams.cnName = val.cnName
      this.getList()
    },
    getList() {
      groupTeamSchedulingPage().then(res => {
        console.log(res)
        this.list = res.data.list || []
        this.total = res.data.total || 0
      })
    },
    getGroupClass() {
      
    },
    handleClick(val) {
      console.log(val)
      this.paramVisible = true
      this.$nextTick(() => {
        this.$refs.schedulingMonitoringDetail.init(val.data)
      })
    }
  }
}
</script>