<template>
  <div class="app-container">
    <el-form label-width="100px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="相关方名称">
            <el-input v-model="XGF_NAME" placeholder="相关方名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="委托时间">
            <el-date-picker
              v-model="dates"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              style="width: 100%;"
            />
          </el-form-item>
        </el-col>
        <!--        <el-col :span="6">-->
        <!--          <el-form-item label="申请状态">-->
        <!--            <el-select v-model="AUDIT_STATUS" placeholder="请选择申请状态" clearable >-->
        <!--              <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />-->
        <!--            </el-select>-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
              搜索
            </el-button>
            <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table ref="multipleTable" :data="varList" :header-cell-style="{'font-weight': 'bold','color': '#000'}" tooltip-effect="dark" border fit highlight-current-row>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="RELEVANT_UNIT_NAME" label="相关方单位名称" />
      <el-table-column prop="CREATTIME" label="申请时间" />
      <el-table-column prop="SUPERVISION_DEPARTMENT_NAME" label="安全监督部" />
      <el-table-column prop="SUPERVISION_USER_NAME" label="安全监督部人员" />
      <el-table-column prop="MAIN_DEPARTMENT_NAME" label="主管部门" />
      <el-table-column prop="MANAGER_USER_NAME" label="主管部门人员" />
      <el-table-column prop="TERRITORIALITY_DEPARTMENT_NAME" label="属地管理部门" />
      <el-table-column prop="TERRITORIALITY_USER_NAME" label="属地管理部门人员" />
      <el-table-column prop="TRAIN_DATE" label="申请年份" >
        <template slot-scope="{row}">
          {{ new Date(row.CREATTIME).getFullYear() }}
        </template>
      </el-table-column>
      <el-table-column prop="AUDIT_STATUS" label="申请状态" >
        <template slot-scope="{row}">
          <span v-if="row.AUDIT_STATUS === 0">待审核</span>
          <span v-if="row.AUDIT_STATUS === 1">审核中</span>
          <span v-if="row.AUDIT_STATUS === 2">待培训</span>
          <span v-if="row.AUDIT_STATUS === 3">已完成</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button v-if="(row.AUDIT_STATUS === 1 || row.AUDIT_STATUS === 0 ) && (row.MANAGER_USER_ID == USER_ID && row.managerCount != row.USER_COUNT ) || (row.TERRITORIALITY_USER_ID == USER_ID && row.territorialityCount != row.USER_COUNT ) " type="success" icon="el-icon-edit" size="mini" @click="handleAudit(row.TRAININGBATCH_ID)">审核</el-button>
          <el-button v-else type="primary" icon="el-icon-edit" size="mini" @click="handleShow(row.TRAININGBATCH_ID)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>

    <users ref="users" @getResult="getList"/>
    <audit ref="audit" @finish="getQuery"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import users from './users'
import audit from './audit'
export default {
  components: { Pagination, Treeselect, users, audit },
  directives: { waves },
  data() {
    return {
      USER_ID: JSON.parse(sessionStorage.getItem('user')).USER_ID,
      listQuery: {
        page: 1,
        limit: 20
      },
      total: 0,
      varList: [],
      XGF_NAME: '',
      dates: [],
      statusList: [{ value: 0, label: '股份公司待审核' }, { value: 1, label: '分公司待审核' }, { value: 2, label: '培训中' }, { value: 3, label: '培训完成' }, { value: -1, label: '股份公司审核未通过' }, { value: -2, label: '分公司审核未通过' }],
      AUDIT_STATUS: ''
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.listQuery = {
        page: 1,
        limit: 20
      }
      this.getList()
    },
    goKeyReset() {
      this.dates = []
      this.XGF_NAME = ''
      this.AUDIT_STATUS = ''
      this.getQuery()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/flowTrain/batchList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          XGF_NAME_REG: this.XGF_NAME,
          ENTRUST_STARTTIME: this.dates[0],
          ENTRUST_ENDTIME: this.dates[1],
          AUDIT_STATUS: this.AUDIT_STATUS,
          TYPE: 2,
          USER_ID: JSON.parse(sessionStorage.getItem('user')).USER_ID
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
      })
        .catch((e) => {
          this.listLoading = false
        })
    },

    handleAudit(id) {
      this.$refs.users.init(id, '1')
    },

    handleShow(id) {
      this.$refs.users.init(id, '0')
    }
  }
}
</script>

