<template>
  <basic-container class="list">
    <div class="flexBetween">
      <el-button
        type="primary"
        size="mini"
        class="el-icon-plus"
        @click="pushRouter()"
      >新增</el-button>
      <el-select
        v-model="value"
        filterable
        placeholder="请选择"
        @change="projectChange"
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.projectName"
          :value="item.id"
        >
        </el-option>
      </el-select>
    </div>

    <el-table
      class="martop20"
      :data="tableData"
      header-color='red'
      style="width: 100%"
    >
      <el-table-column
        type="index"
        label="序号"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        label="证书所有者"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="address"
        label="证书ID"
      >
      </el-table-column>
      <el-table-column
        prop="address"
        label="证书类型"
      >
      </el-table-column>
      <el-table-column
        prop="address"
        label="注册"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="register(scope.row)"
          >注册</el-button>
          <el-button
            type="text"
            disabled
          >已注册</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text">编辑</el-button>
          <el-button
            type="text"
            @click="deleteList(scope.row)"
            style="color:rgba(240, 99, 10, 1);"
          >删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      style="float:right"
      background
      class="martop20 marbottom20"
      layout="prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="pageindex"
      :page-size="pagesize"
    >
    </el-pagination>
  </basic-container>
</template>

<script>
import { queryProjectList, listpage, goRegister } from "@/api/certificate/list";

export default {
  data () {
    return {
      value: '',
      options: [],
      tableData: [{}],
      total: 0,
      pageindex: 1,
      pagesize: 20,
    }
  },
  methods: {
    //#region 页码
    handleSizeChange (val) {
      this.pagesize = val
      this.listpage()
    },
    handleCurrentChange (val) {
      this.pageindex = val
      this.listpage()
    },
    //#endregion

    //#region 列表接口
    projectChange () {
      this.listpage()
    },
    register () {//注册按钮

    },
    deleteList () {//删除按钮

    },
    async queryProjectList () {//获取所有项目
      const { data: res } = await queryProjectList()
      console.log(res);
      if (res.code == 200) {
        this.options = res.data
      }
    },
    async listpage () {//分页获取证书列表数据
      const { data: res } = await listpage({
        current: this.pageindex,
        size: this.pagesize,
        projectId: this.value,
      })
      console.log(res);
      if (res.code == 200) {
        this.tableData = res.data.records
        this.total = res.data.total
      }
    },
    async goRegister () {//注册
      const { data: res } = await goRegister({ id: '' })
    },
    //#endregion
  },
  created () {
    // this.queryProjectList()
    this.listpage()
  },
}
</script>


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