<template>
  <div class="app-container">
        <div>
          <el-select
            v-model="listQuery.cert_type"
            placeholder="认证类型"
            clearable
            style="width: 200px"
            class="filter-item"
            @change="handleFilter"
          >
            <el-option
              v-for="item in enabledOptions"
              :key="item.key"
              :label="item.display_name"
              :value="item.key"
            />
          </el-select>
          <el-input
            v-model="listQuery.search"
            placeholder="规则名称/编号"
            style="width: 300px;"
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
          <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >搜索</el-button>
          <el-button
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            icon="el-icon-refresh-left"
            @click="resetFilter"
          >刷新重置</el-button>
        </div>
        <div style="margin-top:6px">
        <el-button type="primary" icon="el-icon-plus" @click="handleCreate">新增</el-button>
        </div>
        <el-table
          v-loading="listLoading"
          :data="ruleList.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 align="header-center" label="编号">
            <template slot-scope="scope">{{ scope.row.code }}</template>
          </el-table-column>
          <el-table-column align="center" label="名称">
            <template slot-scope="scope">{{ scope.row.name }}</template>
          </el-table-column>
          <el-table-column align="center" label="所属认证类型">
            <template slot-scope="scope">{{ scope.row.cert_type }}</template>
          </el-table-column>
          <el-table-column align="header-center" label="产品领域">
            <template slot-scope="scope">{{ scope.row.pv_scope.fullname }}</template>
          </el-table-column>
          <el-table-column align="header-center" label="产品分类">
            <template slot-scope="scope">{{ scope.row.pv_class.fullname }}</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 align="center" label="操作" width="260px">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            :disabled="!checkPermission(['implementrule_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(['implementrule_delete'])"
            @click="handleDelete(scope)"
          >删除</el-button>
        </template>
                </el-table-column>
        </el-table>

        <pagination
          v-show="ruleList.count>0"
          :total="ruleList.count"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.page_size"
          @pagination="getList"
        />
  </div>
</template>
<script>
import { getImplementRuleList } from "@/api/implementrule"
import Pagination from "@/components/Pagination"
import checkPermission from '@/utils/permission'
export default {
  components: { Pagination },
  data() {
    return {
      ruleList: {count:0},
      listLoading: true,
      listQuery: {
        page: 1,
        page_size: 20
      },
      enabledOptions: [
        { key: "pv", display_name: "自愿性产品认证" },
        { key: "ccc", display_name: "强制性产品认证" },
        { key: "sys", display_name: "管理体系认证" },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermission,
    getList() {
      this.listLoading = true;
      getImplementRuleList(this.listQuery).then(response => {
        if (response.data) {
          this.ruleList = response.data.results
        }
        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/implementrule/create"})
    },
    handleUpdate(scope) {
      this.$router.push({path:"/certset/implementrule/update",query:{id:scope.row.id}})
    },
  }
};
</script>
