<template>
  <div class="app-container">
        
        <div style="margin-top:6px">
        <el-button type="primary" icon="el-icon-plus" @click="handleCreate">新增</el-button>
        </div>
        <el-table v-loading="listLoading"
                  :data="evaluationitem.results"
                  style="width: 100%;margin-top:10px;"
                  border
                  fit
                  stripe
                  highlight-current-row
                  max-height="600">
          <el-table-column type="index" width="50" />
          <el-table-column label="名称">
            <template slot-scope="scope">
              {{ scope.row.name }}
            </template>
          </el-table-column>
          <el-table-column label="认证领域">
            <template slot-scope="scope">
              {{ scope.row.cert_field.name}}
            </template>
          </el-table-column>


          <el-table-column label="上传日期">
            <template slot-scope="scope">
              <span>{{ scope.row.create_time }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary"
                         size="small"
                         :disabled="!checkPermission(['evaluationitem_update'])"
                         @click="handleUpdate(scope)">编辑</el-button>
              <!-- <el-button
        type="primary"
        size="small"
        :disabled="!checkPermission(['implementrule_update'])"
        @click="handleUpate(scope)"
      >单元划分</el-button> -->
              <el-button type="danger"
                         size="small"
                         :disabled="!checkPermission(['evaluationitem_delete'])"
                         @click="handleDelete(scope)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="evaluationitem.count>0"
          :total="evaluationitem.count"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.page_size"
          @pagination="getList"
        />
  </div>
</template>
<script>
  import { getEvaluationItemList, deleteEvaluationItem } from "@/api/evaluationitem";

import Pagination from "@/components/Pagination"
import checkPermission from '@/utils/permission'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { genTree } from '../../utils'
export default {
  components: { Pagination, Treeselect },
  data() {
    return {
      evaluationitem: {count:0},
      listLoading: true,
      listQuery: {
        page: 1,
        page_size: 20
      },
      typeOptions: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermission,
    getList() {
      this.listLoading = true;
      getEvaluationItemList(this.listQuery).then(response => {
        if (response.data) {
          this.evaluationitem = response.data
        }
        this.listLoading = false
      });
    },
    
    resetFilter() {
      this.listQuery = {
        page: 1,
        page_size: 20
      }
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleCreate() {
      this.$router.push({path:"/certset/evaluationitem/create"})
    },
    handleUpdate(scope) {
      this.$router.push({path:"/certset/evaluationitem/update",query:{id:scope.row.id}})
    },
   handleDelete(scope) {
      this.$confirm('确定删除本条数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteEvaluationItem(scope.row.id).then(res=>{
        this.$message.success('删除成功')
              this.getList()
    })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    
},
  
  }
};
</script>
