<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="评价人" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入评价人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['evaluateDetails:details:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['evaluateDetails:details:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['evaluateDetails:details:remove']"
        >删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" align="center" :index="indexMethod" width="50"/>
      <el-table-column label="评价人" align="center" min-width="80" prop="userId"/>
      <el-table-column label="正样本数" align="center" min-width="80" prop="justSqmple"/>
      <el-table-column label="负样本数" align="center" min-width="80" prop="loseSample"/>
      <el-table-column label="TP数量" align="center" min-width="80" prop="tpNum"/>
      <el-table-column label="TN数量" align="center" min-width="80" prop="tnNum"/>
      <el-table-column label="FP数量" align="center" min-width="80" prop="fpNum"/>
      <el-table-column label="FN数量" align="center" min-width="80" prop="fnNum"/>
      <el-table-column label="准确率" align="center" min-width="80" prop="accuracyRate"/>
      <el-table-column label="召回率" align="center" min-width="80" prop="recallRate"/>
      <el-table-column label="精确率" align="center" min-width="80" prop="accurateRate"/>
      <el-table-column label="F1分数" align="center" min-width="80" prop="fgrade"/>
      <el-table-column label="评价时间" align="center" prop="evaluteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.evaluteTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['evaluateDetails:details:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['evaluateDetails:details:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <add-evaluate-details :title="title" :get-list="getList" :open="open" :evaluate-id="evaluateId"
                          :evaluate-detail-id="id"
                          @dialog-cancel="handleCancel"
    />
  </div>
</template>

<script>
import { listDetails, delDetails } from '@/api/dataCenter/evaluateDetails'
import addEvaluateDetails from './addEvaluateDetails.vue'

export default {
  name: 'Details',
  components: { addEvaluateDetails },
  data() {
    return {
      evaluateId: null,
      id: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 模型评价详情表格数据
      detailsList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  created() {
    this.evaluateId = Number(this.$route.params && this.$route.params.evaluateId)
    this.getList()
  },
  methods: {
    indexMethod(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
    },
    /** 查询模型评价详情列表 */
    getList() {
      this.loading = true
      this.queryParams.evaluateId = this.evaluateId
      listDetails(this.queryParams).then(response => {
        this.detailsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.title = '添加'
      this.id = null
      this.open = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.title = '修改'
      this.id = row.id || this.ids[0]
      this.open = true
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除数据项？').then(function() {
        return delDetails(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    handleCancel() {
      this.open = false
    }
  }
}
</script>
