<template>
  <div id="aiLib w-full" style="width:100%">
    <div class="page-header">
      <div class="page-title">
        <el-button icon="el-icon-back" size="mini" style="font-size: 20px; color: #000;" type="text" @click="toBack" ></el-button>
        <el-divider direction="vertical"></el-divider>
        ai数据库
        <el-select v-model="aiTypeVal" @change="getNowAiLib" placeholder="请选择ai类型">
          <el-option
            v-for="item in aiTypeArr"
            :key="item.val"
            :label="item.text"
            :value="item.val"
            :disabled="item.disabled">
          </el-option>
        </el-select>
        <el-button icon="el-icon-search" type="primary" :loading="isLoading">搜索</el-button>
      </div>
      <div class="page-header-btn">
      </div>
    </div>
    <el-table :data="libList" style="width: 100%;font-size: 12px;" :height="winHeight" header-row-class-name="table-header">
      <el-table-column prop="libraryId" label="id" ></el-table-column>
      <el-table-column prop="libraryName" label="数据库名称" min-width="160"></el-table-column>
      <el-table-column prop="version" label="数据库版本号" ></el-table-column>
      <el-table-column prop="arithmetic" label="对应算法" ></el-table-column>
      <el-table-column prop="total" label="id" ></el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button size="medium" @click="editLibHandle(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="float: right"
      @size-change="handleSizeChange"
      @current-change="currentChange"
      :current-page="currentPage"
      :page-size="count"
      :page-sizes="[15, 25, 35, 50]"
      layout="total, sizes, prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import {toNumber} from "@/until/typeTool";
import aiMap from "@/map/ai";

export default {
  name: "AiLib",
  data(){return {
    isLoading: false,
    aiTypes: aiMap.aiTypes,
    aiTypeArr: aiMap.getAITypeArr(),
    triggerTypes: aiMap.triggerTypes,
    triggerTypeArr: aiMap.getTriggerTypeArr(),
    aiTypeVal: 0,
    arithmetic: this.$route.params.arithmetic,
    libList: [],
    currentPage: 1,
    count: 15,
    total: 1,

  }},
  methods:{
    toBack(){
      this.$router.back();
      if (this.deviceId === "" ) {
        this.beforeUrl = "/deviceList"
      }
    },
    getNowAiLib(){
      this.nowAiLib = this.aiLibList.filter(aiLib=>toNumber(aiLib.libraryId)===toNumber(this.aiTypeVal));
      this.libraryId = 0;
      this.triggerType = this.triggerTypes.unlimited;
    },
    searchLibList(){

    },
    /**
     * 编辑lib数据
     * @param row
     */
    editLibHandle(row){
      this.$router.push(`/libEdit/${row.libraryId}`);
    },
    currentChange: function (val) {
      this.currentPage = val;
      this.searchLibList();
    },
    handleSizeChange: function (val) {
      this.count = val;
      this.searchLibList();
    },
  }
}
</script>

<style scoped>

</style>
