<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="keyword" placeholder="请输入关键字" class="filter-item"/>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
      <el-button v-permission="'HY_add'" type="primary" class="filter-item" icon="el-icon-plus" @click="btn_add">添加</el-button>
    </div>

    <el-table v-loading="loading" :data="dataLists" border stripe>
      <el-table-column type="index" label="编号" align="center" fixed width="80"/>
      <el-table-column prop="F_DeptName" label="部门名称" align="center" min-width=""/>
      <el-table-column prop="F_Tasker" label="任务人" align="center" min-width=""/>
      <el-table-column prop="F_Money" label="目标金额" align="center" min-width=""/>
      <el-table-column prop="F_Money" label="任务进度" align="center" min-width="">
          <template slot-scope="scope">
              <el-progress :percentage="scope.row.F_Taskprogress"></el-progress>
          </template>
      </el-table-column>
      <el-table-column prop="F_StartTime" label="任务开始时间" align="center" min-width=""/>
      <el-table-column prop="F_EndTime" label="任务结束时间" align="center" min-width=""/>
      <el-table-column label="任务类型" align="center" min-width="">
          <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.F_Type==0">日任务</el-tag>
              <el-tag type="info" v-else-if="scope.row.F_Type==1">周任务</el-tag>
              <el-tag  v-else-if="scope.row.F_Type==2">月任务</el-tag>
          </template>
      </el-table-column>
      <el-table-column prop="F_Des" label="描述说明" align="center" min-width=""/>
      <el-table-column label="操作" width="160" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_edit'" size="mini" plain type="primary" @click="btn_edit(scope.row.F_Id)">编辑</el-button>
          <el-button v-permission="'HY_delete'" size="mini" plain type="danger" @click="btn_delete(scope.row.F_Id.toString)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList" />
  </div>
</template>

<script>

import { getPositionLists, deletePosition } from '@/api/systemSetup/sysSetting/positionManagement'
import { getTaskLists } from '@/api/taskManagement/taskManagement'
import addOrEdit from './addOrEdit'
import { pickerOptions } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'BlackList',
  components: {
    Pagination
  },
  data() {
    return {
      loading: false,
      keyword: '',
      searchDate: '',
      pickerOptions,
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [] // 列表数据
    }
  },
  created() {
    this.getList()
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.getList()
      }
    }
  },
  methods: {
    getList() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // 第几页
          pagesize: this.pageParams.pagesize, // 每页几条信息
          key: this.keyword,
        }
        getTaskLists(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.total
            this.dataLists = response.rows
          }
        })
        resolve()
      })
    },
    btn_search() {
      this.pageParams.pageindex = 1
      this.getList()
    },
    btn_add() {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': '' }// props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ['70%', '60%'],
        title: '添加任务信息'
      })
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId }// props
        },
        area: ['70%', '60%'],
        title: '编辑任务信息'
      })
    },
    btn_delete(editId) {
      this.$confirm('您确定要将此任务信息删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePosition(editId).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
