<template>
  <div class="app-container">
    <el-form label-width="100px">
      <el-row>
        <el-col :span="5">
          <el-form-item label="关键字搜索">
            <el-input v-model="KEYWORDS" placeholder="搜索关键字" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <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
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        :reserve-selection="true"
        type="selection"
        width="55"
        align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="OUTSOURCED_NAME" label="重点工程名称" show-overflow-tooltip />
      <el-table-column prop="STARTTIME" label="工期" show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.STARTTIME }} -- {{ row.ENDTIME }}
        </template>
      </el-table-column>
      <el-table-column prop="DEPARTMENT_NAME" label="监管部门" show-overflow-tooltip >
        <template slot-scope="{row}">
          <span v-if="row.Q_DEPARTMENT_NAME"> {{ row.Q_DEPARTMENT_NAME }} </span>
          <span v-else>{{ row.DEPARTMENT_NAME }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主管部门" show-overflow-tooltip >
        <template slot-scope="{row}">
          <span v-if="row.Q_COMPETENT_DEPT_NAME"> {{ row.Q_COMPETENT_DEPT_NAME }} </span>
          <span v-else>{{ row.MANAGER_DEPARTMENT_NAME }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="UNITS_NAME" label="施工相关方" width="250" show-overflow-tooltip />
      <el-table-column prop="VIDEO_COUNT" label="视频个数" />
      <el-table-column prop="STATE" label="状态">
        <template slot-scope="{row}">
          <span v-if="row.STATE == 1">进行中</span>
          <span v-if="row.STATE == 2">已结束</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100">
        <template slot-scope="{row}">
          <el-button type="success" icon="el-icon-view" size="mini" @click="goDetail(row)">查看</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>
</div></template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      },
      total: 0,
      KEYWORDS: '',
      varList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getRowKey(row) {
      return row.OUTSOURCED_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.getQuery()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/outsourced/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 查看
    goDetail(row) {
      this.$parent.OUTSOURCED_ID = row.OUTSOURCED_ID
      this.$parent.UNITS_ID = row.UNITS_ID
      this.$parent.STATE = row.STATE
      this.$parent.activeName = 'videoList'
    }
  }
}

</script>
<style lang="sass" scoped>
  .table-qrcode
    text-align: center
    padding-top: 20px
    width: 100%
    .filter-container
      position: relative
      .filter-flot
        position: absolute
        right: 0
        top: 0
    .uploader
      width: 570px
      display: flex
      align-items: center
    .el-form-item__content
      line-height: 1
</style>

