<template>
  <el-card>
    <el-row style="padding: 10px 20px;background-color:#F5F5F5">
      <el-col :span="3">
        <div style="font-size: 14px">人员状态：</div>
        <el-select v-model="occupation" class="select12" placeholder="请选择">
          <el-option
            v-for="item in occupations"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-col>
      <el-col :span="3">
        <div style="font-size: 14px">工单号：</div>
        <el-input v-model="orderNumber" class="input11"/>
      </el-col>
      <el-col :span="3">
        <div style="font-size: 14px">班次：</div>
        <el-select v-model="className" class="select12" placeholder="请选择班次">
          <el-option
            v-for="item in classNames"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-col>
      <el-col :span="2">
        <el-button type="text" icon="el-icon-search" style="margin-left: 10px;margin-top:15px;font-size: 26px" @click="pageCurrent = 1,searchTable()"/>
      </el-col>
      <el-col :span="3">
        <el-button size="mini" style="width: 80px;height: 40px;padding-left: 10px;margin-top:18px" class="button11" @click="statusFreed()">紧急释放</el-button>
      </el-col>
      <el-col :span="9">
        <div style="font-size: 14px">导出月度工作量：</div>
        <el-date-picker
          v-model="month"
          value-format="yyyy-MM-dd"
          type="month"
          placeholder="选择月"/>
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          style="font-size: 16px;height: 40px;margin-left: 10px"
          @click="Upload()">导出</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="tableData"
      :header-cell-style="tableHeader"
      :cell-style="tableCell"
      :cell-class-name="arrangeTableCell"
      :row-class-name="getRowClass"
      element-loading-text="数据加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.2)"
      tooltip-effect="dark"
      height="700px"
      style="width: 100%;"
      @selection-change="selectionChange"
      @expand-change="searchTablePlus">
      <el-table-column type="expand">
        <!-- 内置表格 -->
        <template slot-scope="props">
          <el-table
            :data="props.row.tableData2"
            :header-cell-style="tableHeader1"
            :cell-style="tableCell1"
            style="width: 60%;">
            <el-table-column align="left" prop="orderNum" label="工单号" min-width="60">
              <span slot-scope="props">
                <el-tag color="rgb(153,153,153)" size="mini" type="info" style="cursor: pointer">{{ props.row.维修工单号 }}</el-tag>
              </span>
            </el-table-column>
            <el-table-column align="left" prop="EquipmentName" label="设备名称" min-width="120">
              <span slot-scope="props">
                {{ props.row.设备名称 }}
              </span>
            </el-table-column>
            <el-table-column align="left" prop="state" label="状态" min-width="50">
              <span slot-scope="props">
                <el-tag v-if="props.row.维修工单状态代码 === 1 || props.row.维修工单状态代码 === 2" color="rgb(227,0,21)" type="info" size="mini" >{{ props.row.维修工单状态名称 }}</el-tag>
                <el-tag v-if="props.row.维修工单状态代码 === 4" color="rgb(0,142,207)" type="info" size="mini" >{{ props.row.维修工单状态名称 }}</el-tag>
                <el-tag v-if="props.row.维修工单状态代码 === 3" color="rgb(255,165,0)" type="info" size="mini" >{{ props.row.维修工单状态名称 }}</el-tag>
              </span>
            </el-table-column>
            <el-table-column align="left" prop="description" label="故障类别" min-width="50">
              <span slot-scope="props">
                {{ props.row.故障名称 }}
              </span>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="80"/>
      <el-table-column align="left" label="姓名" min-width="90">
        <span slot-scope="scope">
          {{ scope.row.姓名 }}
        </span>
      </el-table-column>
      <el-table-column align="left" label="维修班组" min-width="90">
        <span slot-scope="scope">
          {{ scope.row.班组 }}
        </span>
      </el-table-column>
      <el-table-column align="left" label="出勤" min-width="90">
        <template slot-scope="scope">
          <span v-if="scope.row.人员状态 === '上班'" style="font-size: 20px">√</span>
        </template>
      </el-table-column>
      <el-table-column align="left" label="人员状态" min-width="90">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.安排状态" color="#409eff" type="info" size="mini" >工作</el-tag>
          <el-tag v-else color="#909399" type="info" size="mini">休闲</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="left" label="是否应急" min-width="90">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.安排状态" color="rgb(227,0,21)" type="info" size="mini">是</el-tag>
          <el-tag v-else color="rgb(115,168,57)" type="info" size="mini">否</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <!--    <div class="block" style="margin-top: 10px;">-->
    <!--      <el-pagination-->
    <!--        v-if="!loading"-->
    <!--        :current-page="pageCurrent"-->
    <!--        :page-sizes="[100, 200, 300, 400]"-->
    <!--        :page-size="pageSize"-->
    <!--        :total="total"-->
    <!--        layout="total, sizes, prev, pager, next, jumper"-->
    <!--        @size-change="handleSizeChange"-->
    <!--        @current-change="handleCurrentChange"/>-->
    <!--    </div>-->
  </el-card>
</template>

<script>
import { ExecDatabase } from '@/main'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      multipleSelection: [],
      month: '',
      occupation: '1',
      occupations: [{
        value: '1',
        label: '全部'
      }, {
        value: '2',
        label: '工作'
      }, {
        value: '3',
        label: '休闲'
      }],
      orderNumber: '',
      orderNumber_check: 0,
      className: '2',
      classNames: [{
        value: '1',
        label: '所有班次'
      }, {
        value: '2',
        label: '当前班次'
      }],
      loading: false,
      tableData: [],
      expends: [],
      value: '',
      tableData1: [],
      disabled: false,
      total: 0, // 总条数
      pageSize: 10000, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id',
      'token',
      'cname'
    ])
  },
  created() {
    this.searchTable()
  },
  methods: {
    Upload() {
      if (!this.month) { this.$message.error('请选择月份导出') } else {
        var param = []
        param[0] = ['月份', this.month]
        var Data = this.CreateData('2001', '维修工单_月度统计_导出', param)
        this.exportExcel_NPOI(Data)
      }
    },
    // 查询
    searchTable() {
      this.loading = true
      this.tableData = []
      if (this.orderNumber) { this.orderNumber_check = 1 } else { this.orderNumber_check = 0 }
      var param = []
      param[0] = ['班次名称', this.className]
      param[1] = ['是否被占用', this.occupation]
      param[2] = ['维修工单号', this.orderNumber]
      param[3] = ['维修工单号_check', this.orderNumber_check]
      param[4] = ['PageSize', this.pageSize]
      param[5] = ['PageCurrent', this.pageCurrent]
      param[6] = ['PageCount', '1111', 'int', '1']
      param[7] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', '基础数据_班组人员状态_查询', param)
      ExecDatabase(Data).then(response => {
        response.data.result.map(v => {
          this.tableData.push({
            人员代码: v.人员代码,
            姓名: v.姓名,
            维修工单代码: v.维修工单代码,
            班组: v.班组,
            人员状态: v.人员状态,
            安排状态: v.安排代码,
            被应急维护占用: v.安排代码,
            维修工单号: v.维修工单号,
            维修工单状态名称: v.维修工单状态名称,
            维修工单状态代码: v.维修工单状态代码,
            设备名称: v.设备名称,
            故障名称: v.故障名称
          })
        })
        this.loading = false
        this.total = parseInt(response.data.output[0].ItemCount)
      })
    },
    // 子表格条件隐藏
    getRowClass(row) {
      if (row.row.安排状态 === null) { // 判断当前行是否有子数据
        return 'row-expand-cover'
      }
    },
    // 多选框条件隐藏
    arrangeTableCell(row) {
      if (row.row.安排状态 === null && row.columnIndex === 1) {
        return 'myCell'
      }
    },
    selectionChange(val) {
      this.multipleSelection = val
    },
    statusFreed() {
      for (let i = 0; i < this.multipleSelection.length; i++) {
        var param = []
        param[0] = ['安排代码', this.multipleSelection[i].安排状态]
        param[1] = ['维修工单代码', this.multipleSelection[i].维修工单代码]
        param[2] = ['用户', this.cname]
        var Data = this.CreateData('12', '维修工单_维修人员_状态释放', param)
        ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '信息编辑成功',
              type: 'success'
            })
            this.searchTable()
          } else {
            this.$message.error('信息编辑失败')
          }
        })
      }
    },
    // 修改table的样式
    tableHeader() {
      return 'background-color: rgb(250, 250, 250);' +
        'border-bottom: 3px rgb(170, 170, 170) solid;' +
        'color: rgb(35, 35, 35);' +
        'font-weight: 5000;' +
        'padding: 15px 10px'
    },
    tableCell() {
      return 'border-color: #E8E8E8;padding: 10px 0px 8px 0px'
    },
    searchTablePlus(row, expandedRows) {
      if (expandedRows.length !== 0) {
        row.tableData2 = [{
          维修工单号: row.维修工单号,
          维修工单状态名称: row.维修工单状态名称,
          维修工单状态代码: row.维修工单状态代码,
          设备名称: row.设备名称,
          故障名称: row.故障名称,
          是否停机: row.是否停机
        }]
      }
    },
    // 修改table1 header的背景色、边框底色
    tableHeader1() {
      return 'border-color: #B8B8B8;border-bottom-width:3px;background-color: #70db93;color: #505050;font-weight: 5000;'
    },
    // 修改table1的边框底色
    tableCell1() {
      return 'border-color: #E8E8E8;'
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>

<style scoped>
>>>.select12 .el-input__inner {
  width: 180px;
}
>>>.input11 .el-input__inner {
  width: 180px;
  height: 50px;
}
  >>>.row-expand-cover .el-table__expand-column .cell {
    display: none;
  }
>>>.myCell .el-checkbox__input {
  display: none
}
</style>
