<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="keyword" placeholder="请输入关键字" class="filter-item"/>
      <el-select clearable v-model="state" placeholder="请选择待办状态">
        <el-option
          v-for="item in stateList"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-select clearable v-model="type" placeholder="请选择类型">
        <el-option
          v-for="item in typeList"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <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>
      <el-button v-permission="'HY_deletes'" type="primary" class="filter-item" icon="el-icon-delete" @click="btn_deletes">批量删除</el-button>
      <el-button v-permission="'HY_operation'" type="primary" class="filter-item"  @click="btn_operation">批量操作</el-button>
      <el-button v-permission="'HY_import'" type="primary" class="filter-item"  @click="btn_import">导入</el-button>
    </div>

    <el-table v-loading="loading" :data="dataLists" border stripe @selection-change="changeSelects">
      <el-table-column type="selection" width="40" fixed></el-table-column>
      <el-table-column type="index" label="编号" align="center" fixed width="80"/>
      <el-table-column label="类型" align="center" min-width="">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.F_Type==0">日程</el-tag>
          <el-tag v-else>待联系人</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="F_Name" label="标题" align="center" min-width=""/>
      <el-table-column prop="F_Content" label="内容" align="center" min-width=""/>
      <el-table-column prop="F_PeopleName" label="待联系人" align="center" min-width=""/>
      <el-table-column prop="F_Tel" label="待联系人电话" align="center" min-width=""/>
      <el-table-column label="是否提醒" align="center" min-width="">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.F_IsRemind==0">否</el-tag>
          <el-tag v-else>是</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="F_Remindertime" label="提醒时间" align="center" min-width=""/>
      <el-table-column prop="F_CreateUser" label="创建人" align="center" min-width=""/>
      <el-table-column prop="F_CreateTime" label="创建时间" align="center" min-width=""/>
      <el-table-column label="状态" align="center" min-width="">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.F_State==0">未完成</el-tag>
          <el-tag v-else>已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="220" 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.toString())">编辑</el-button>
          <el-button v-permission="'HY_detail'" size="mini" plain type="primary" @click="btn_detail(scope.row.F_ID.toString())">详情</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 { getTodoList,deleteTodo } from '@/api/todoManagement/todoList'
import addOrEdit from './addOrEdit'
import detail from './detail'
import operation from './operation'
import importFile from './importFile'
import { pickerOptions } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'BlackList',
  components: {
    Pagination
  },
  data() {
    return {
      loading: false,
      keyword: '',
      state: '',
      type: '',
      searchDate: '',
      pickerOptions,
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], //选中的id
      stateList: [
        {
          value:0,
          label:'未完成',
        },
        {
          value:1,
          label:'已完成',
        },
      ], // 待办状态数据
      typeList: [
        {
          value:0,
          label:'日程',
        },
        {
          value:1,
          label:'待联系人',
        },
      ], // 类型数据
    }
  },
  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, // 每页几条信息
          keyword: this.keyword.trim(),
          state:this.state,
          type:this.type,
        }
        getTodoList(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.rows.Totals
            this.dataLists = response.rows.Rows
          }
        })
        resolve()
      })
    },
    btn_import() {
      this.$layer.iframe({
        content: {
          content: importFile, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: 0 } // props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ["40%", "380px"],
        shadeClose: false,
        title: "导入待办信息"
      });
    },
    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: ['40%', '60%'],
        title: '添加待办信息'
      })
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId }// props
        },
        area: ['40%', '60%'],
        title: '编辑待办信息'
      })
    },
    btn_detail(editId) {
      this.$layer.iframe({
        content: {
          content: detail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'rowid': editId }// props
        },
        area: ['70%', '60%'],
        title: '待办信息详情'
      })
    },
    btn_delete(editId) {
      this.$confirm('您确定要将此待办信息删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteTodo(editId).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    //批量删除
    btn_deletes(){
      if(this.selectedId.length==0){
        this.$message('请选择一个选项')
        return
      }else{
          this.$confirm('您确定要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteTodo(this.selectedId).then(response => {
            if (response.state.toLowerCase() === 'success') {
              this.getList()
              this.$message.success('删除成功!')
            }
          })
        }).catch(() => {
          this.$message.info('已取消删除')
        })
      }
      
    },
    //批量完成
    btn_operation(){
      if(this.selectedId.length==0){
        this.$message('请选择一个选项')
        return
      }else{
        this.$layer.iframe({
          content: {
            content: operation, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: { 'rowid': this.selectedId }// props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
          },
          area: ['40%', '30%'],
          title: '待办状态修改'
        })
      }
    },
    changeSelects(val) {
      const ids = []
      this.multipleSelection = val
      for (let i=0; i<this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].F_ID)
      }
      this.selectedId = ids;
    },
  }
}
</script>

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

</style>
