<!--  -->
<template>
    <div class="assessment">
      <div class="assessment-form">
        <el-form ref="form" inline :model="form" >
          <div>
            <el-form-item >
              <el-select  size="small"  v-model="form.cycleType" placeholder="请选择" style="width:100px">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item >
              <el-input @change="handleChange" @keyup.enter="handleChange"   size="small"  clearable prefix-icon="el-icon-search" v-model="form.name" placeholder="搜索考核名称"></el-input>
            </el-form-item>
          </div>
          <div>
            <el-form-item >
              <el-button type="primary"  size="small"  @click="handlePush">发起考核</el-button>
            </el-form-item>
            <!-- <el-form-item >
              <el-button  size="small"  >导入历史绩效</el-button>
            </el-form-item> -->
          </div>
        </el-form>
      </div>
      <div class="assessment-table">
        <el-table
        :header-cell-style="{background:'#F5F7FA'}"
        @row-click='handleSelectClick'
        :data="tableData"
        style="width: 100%">
        <el-table-column
          fixed
          prop="name"
          label="考核名称">
        </el-table-column>
        <el-table-column
          prop="cycleTime"
          label="时间周期">
        </el-table-column>
        <el-table-column
          prop="joinNum"
          label="参与人数">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="120">
          <template slot-scope="scope">
            <el-button
               @click="handlePush(scope.row.id)"
              type="text"
              size="small">
              查 看
            </el-button>
            <el-button
              @click="handleDelete(scope.row.id)"
              type="text"
              size="small">
              删 除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer">
        <el-pagination
            small
            @current-change="handleChangePage"
            layout="prev, pager, next"
            :page-size.sync='params.pageSize'
            :current-page.sync='params.currPage'
            :total="params.totalCount">
          </el-pagination>
      </div>
      </div>
    </div>
</template>

<script>
import {apiGetAssessList, apiDeleteAssessList} from '@/api/assessment'
console.log('apiGetAssessList: ', apiGetAssessList)
export default {
  components: {
  },
  data () {
    return {
      params: {
        'currPage': 1,
        'pageSize': 5
      },
      show: false,
      options: [ {
        value: '',
        label: '全部'
      }, {
        value: 0,
        label: '月度'
      },
      {
        value: 1,
        label: '自定义'
      }
      ],
      form: {
        cycleType: ''
      },
      tableData: [{
        date: '2016-05-03',
        name: '2020年01月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年02月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年03月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年01月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年01月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年01月绩效考核',
        number: '10'
      }, {
        date: '2016-05-03',
        name: '2020年01月绩效考核',
        number: '10'
      }]
    }
  },
  computed: {},
  beforeMount () {},
  mounted () {
    this.form.value = this.options[0].value
    this.handleGetData()
  },
  methods: {
    async handleDelete (item) {
      try {
        await apiDeleteAssessList({assessId: item})
        this.handleGetData()
        this.$message({
          message: '成功',
          type: 'success'
        })
      } catch (error) {
        this.$message.error(error.msg)
      }
    },
    handleChange (value) {
      this.params.currPage = 1
      console.log(' this.form: ', this.form)
      this.handleGetData(Object.assign({}, this.form, this.params))
    },
    handlePush (id) {
      this.$router.push({name: 'assessment-stepList', query: {id: 10}})
    },
    async handleGetData (parmas = this.params) {
      try {
        let res = await apiGetAssessList(parmas)
        res = res.data
        this.tableData = res.list
        this.params.totalCount = res.totalCount
        this.params.currPage = res.currPage
      } catch (error) {
        console.log('error: ', error)
      }
    },
    handleChangePage (value) {
      this.params.currPage = value
      this.handleGetData()
    },
    handleRight () {
      this.show = true
    },
    handleSelectClick (row, column, event) {
      console.log('event: ', event)
      console.log('column: ', column)
      console.log('row: ', row)
    },
    handleToHome (i) {
      this.$router.push({name: i})
    },
    deleteRow (index, rows) {
      rows.splice(index, 1)
    }
  },
  watch: {
    'form.cycleType' (n, o) {
      this.handleChange()
    }
  }

}

</script>

<style lang='less' scoped>
.assessment{

  .footer{
    text-align: right;
    margin: 20px 0 0 0;
  }
  .el-form{
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  &-form{
    padding: 4px 0;
  }

  &-table{
    background: #fff;
    padding: 20px;
    border: 1px solid @borderColor;
  }
}
</style>
<style lang="less">
  .el-table__row{
    cursor:pointer;
  }
</style>
