<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="assemblyAccession">
        <el-input
          v-model="queryParams.assemblyAccession"
          placeholder="请输入唯一注册号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参考基因组类型" prop="refseqCategory">
        <el-input
          v-model="queryParams.refseqCategory"
          placeholder="请输入参考基因组类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类号" prop="taxid">
        <el-input
          v-model="queryParams.taxid"
          placeholder="请输入分类号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="种分类号" prop="speciesTaxid">
        <el-input
          v-model="queryParams.speciesTaxid"
          placeholder="请输入种分类号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生物名称" prop="organismName">
        <el-input
          v-model="queryParams.organismName"
          placeholder="请输入生物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="亚种名称" prop="infraspecificName">
        <el-input
          v-model="queryParams.infraspecificName"
          placeholder="请输入亚种名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类类型" prop="isolate">
        <el-input
          v-model="queryParams.isolate"
          placeholder="请输入分类类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拼装级别" prop="assemblyLevel">
        <el-input
          v-model="queryParams.assemblyLevel"
          placeholder="请输入拼装级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基因组级别" prop="genomeRep">
        <el-input
          v-model="queryParams.genomeRep"
          placeholder="请输入基因组级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="seq_rel_date" prop="seqRelDate">
        <el-date-picker clearable
          v-model="queryParams.seqRelDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择seq_rel_date">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="ASM编号" prop="asmName">
        <el-input
          v-model="queryParams.asmName"
          placeholder="请输入ASM编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="gbrs_paired_asm" prop="gbrsPairedAsm">
        <el-input
          v-model="queryParams.gbrsPairedAsm"
          placeholder="请输入gbrs_paired_asm"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="paired_asm_comp" prop="pairedAsmComp">
        <el-input
          v-model="queryParams.pairedAsmComp"
          placeholder="请输入paired_asm_comp"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源地址" prop="ftpPath">
        <el-input
          v-model="queryParams.ftpPath"
          placeholder="请输入来源地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="excluded_from_refseq" prop="excludedFromRefseq">
        <el-input
          v-model="queryParams.excludedFromRefseq"
          placeholder="请输入excluded_from_refseq"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="病源类型" prop="group">
        <el-input
          v-model="queryParams.group"
          placeholder="请输入病源类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基因组大小" prop="genomeSize">
        <el-input
          v-model="queryParams.genomeSize"
          placeholder="请输入基因组大小"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基因组大小" prop="genomeSizeUngapped">
        <el-input
          v-model="queryParams.genomeSizeUngapped"
          placeholder="请输入基因组大小"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="GC比例" prop="gcPercent">
        <el-input
          v-model="queryParams.gcPercent"
          placeholder="请输入GC比例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="replicon_count" prop="repliconCount">
        <el-input
          v-model="queryParams.repliconCount"
          placeholder="请输入replicon_count"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="scaffold_count" prop="scaffoldCount">
        <el-input
          v-model="queryParams.scaffoldCount"
          placeholder="请输入scaffold_count"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="contig_count" prop="contigCount">
        <el-input
          v-model="queryParams.contigCount"
          placeholder="请输入contig_count"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总基因数" prop="totalGeneCount">
        <el-input
          v-model="queryParams.totalGeneCount"
          placeholder="请输入总基因数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="翻译蛋白基因数" prop="proteinCodingGeneCount">
        <el-input
          v-model="queryParams.proteinCodingGeneCount"
          placeholder="请输入翻译蛋白基因数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="非编码基因数" prop="nonCodingGeneCount">
        <el-input
          v-model="queryParams.nonCodingGeneCount"
          placeholder="请输入非编码基因数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文名" prop="nameCn">
        <el-input
          v-model="queryParams.nameCn"
          placeholder="请输入中文名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序列来源" prop="seqSource">
        <el-input
          v-model="queryParams.seqSource"
          placeholder="请输入序列来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="解释来源" prop="express">
        <el-input
          v-model="queryParams.express"
          placeholder="请输入解释来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件路径" prop="filePath">
        <el-input
          v-model="queryParams.filePath"
          placeholder="请输入文件路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点突变耐药基因" prop="dtpnyjy">
        <el-input
          v-model="queryParams.dtpnyjy"
          placeholder="请输入点突变耐药基因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点突变耐药基因说明" prop="dtpnyjyExpress">
        <el-input
          v-model="queryParams.dtpnyjyExpress"
          placeholder="请输入点突变耐药基因说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="耐药基因" prop="nyjy">
        <el-input
          v-model="queryParams.nyjy"
          placeholder="请输入耐药基因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="耐药基因说明" prop="nyjyExpress">
        <el-input
          v-model="queryParams.nyjyExpress"
          placeholder="请输入耐药基因说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毒力基因" prop="dljy">
        <el-input
          v-model="queryParams.dljy"
          placeholder="请输入毒力基因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毒力基因说明" prop="dljyExpress">
        <el-input
          v-model="queryParams.dljyExpress"
          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="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload"
          size="mini"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataBaseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="唯一注册号" align="center" prop="assemblyAccession" />
      <el-table-column label="参考基因组类型" align="center" prop="refseqCategory" />
      <el-table-column label="分类号" align="center" prop="taxid" />
      <el-table-column label="种分类号" align="center" prop="speciesTaxid" />
      <el-table-column label="生物名称" align="center" prop="organismName" />
      <el-table-column label="亚种名称" align="center" prop="infraspecificName" />
      <el-table-column label="分类类型" align="center" prop="isolate" />
      <el-table-column label="拼装级别" align="center" prop="assemblyLevel" />
      <el-table-column label="基因组级别" align="center" prop="genomeRep" />
      <el-table-column label="seq_rel_date" align="center" prop="seqRelDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.seqRelDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="ASM编号" align="center" prop="asmName" />
      <el-table-column label="gbrs_paired_asm" align="center" prop="gbrsPairedAsm" />
      <el-table-column label="paired_asm_comp" align="center" prop="pairedAsmComp" />
      <el-table-column label="来源地址" align="center" prop="ftpPath" />
      <el-table-column label="excluded_from_refseq" align="center" prop="excludedFromRefseq" />
      <el-table-column label="装配类型" align="center" prop="assemblyType" />
      <el-table-column label="病源类型" align="center" prop="group" />
      <el-table-column label="基因组大小" align="center" prop="genomeSize" />
      <el-table-column label="基因组大小" align="center" prop="genomeSizeUngapped" />
      <el-table-column label="GC比例" align="center" prop="gcPercent" />
      <el-table-column label="replicon_count" align="center" prop="repliconCount" />
      <el-table-column label="scaffold_count" align="center" prop="scaffoldCount" />
      <el-table-column label="contig_count" align="center" prop="contigCount" />
      <el-table-column label="总基因数" align="center" prop="totalGeneCount" />
      <el-table-column label="翻译蛋白基因数" align="center" prop="proteinCodingGeneCount" />
      <el-table-column label="非编码基因数" align="center" prop="nonCodingGeneCount" />
      <el-table-column label="中文名" align="center" prop="nameCn" />
      <el-table-column label="定义" align="center" prop="defined" />
      <el-table-column label="序列来源" align="center" prop="seqSource" />
      <el-table-column label="解释来源" align="center" prop="express" />
      <el-table-column label="文件路径" align="center" prop="filePath" />
      <el-table-column label="点突变耐药基因" align="center" prop="dtpnyjy" />
      <el-table-column label="点突变耐药基因说明" align="center" prop="dtpnyjyExpress" />
      <el-table-column label="耐药基因" align="center" prop="nyjy" />
      <el-table-column label="耐药基因说明" align="center" prop="nyjyExpress" />
      <el-table-column label="毒力基因" align="center" prop="dljy" />
      <el-table-column label="毒力基因说明" align="center" prop="dljyExpress" />
      <el-table-column label="备注" align="center" prop="remark" />
      <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-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['data:dataBase: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"
    />

    <!-- 添加或修改病原体管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="唯一注册号" prop="assemblyAccession">
          <el-input v-model="form.assemblyAccession" placeholder="请输入唯一注册号" />
        </el-form-item>
        <el-form-item label="参考基因组类型" prop="refseqCategory">
          <el-input v-model="form.refseqCategory" placeholder="请输入参考基因组类型" />
        </el-form-item>
        <el-form-item label="分类号" prop="taxid">
          <el-input v-model="form.taxid" placeholder="请输入分类号" />
        </el-form-item>
        <el-form-item label="种分类号" prop="speciesTaxid">
          <el-input v-model="form.speciesTaxid" placeholder="请输入种分类号" />
        </el-form-item>
        <el-form-item label="生物名称" prop="organismName">
          <el-input v-model="form.organismName" placeholder="请输入生物名称" />
        </el-form-item>
        <el-form-item label="亚种名称" prop="infraspecificName">
          <el-input v-model="form.infraspecificName" placeholder="请输入亚种名称" />
        </el-form-item>
        <el-form-item label="分类类型" prop="isolate">
          <el-input v-model="form.isolate" placeholder="请输入分类类型" />
        </el-form-item>
        <el-form-item label="拼装级别" prop="assemblyLevel">
          <el-input v-model="form.assemblyLevel" placeholder="请输入拼装级别" />
        </el-form-item>
        <el-form-item label="基因组级别" prop="genomeRep">
          <el-input v-model="form.genomeRep" placeholder="请输入基因组级别" />
        </el-form-item>
        <el-form-item label="seq_rel_date" prop="seqRelDate">
          <el-date-picker clearable
            v-model="form.seqRelDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择seq_rel_date">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="ASM编号" prop="asmName">
          <el-input v-model="form.asmName" placeholder="请输入ASM编号" />
        </el-form-item>
        <el-form-item label="gbrs_paired_asm" prop="gbrsPairedAsm">
          <el-input v-model="form.gbrsPairedAsm" placeholder="请输入gbrs_paired_asm" />
        </el-form-item>
        <el-form-item label="paired_asm_comp" prop="pairedAsmComp">
          <el-input v-model="form.pairedAsmComp" placeholder="请输入paired_asm_comp" />
        </el-form-item>
        <el-form-item label="来源地址" prop="ftpPath">
          <el-input v-model="form.ftpPath" placeholder="请输入来源地址" />
        </el-form-item>
        <el-form-item label="excluded_from_refseq" prop="excludedFromRefseq">
          <el-input v-model="form.excludedFromRefseq" placeholder="请输入excluded_from_refseq" />
        </el-form-item>
        <el-form-item label="病源类型" prop="group">
          <el-input v-model="form.group" placeholder="请输入病源类型" />
        </el-form-item>
        <el-form-item label="基因组大小" prop="genomeSize">
          <el-input v-model="form.genomeSize" placeholder="请输入基因组大小" />
        </el-form-item>
        <el-form-item label="基因组大小" prop="genomeSizeUngapped">
          <el-input v-model="form.genomeSizeUngapped" placeholder="请输入基因组大小" />
        </el-form-item>
        <el-form-item label="GC比例" prop="gcPercent">
          <el-input v-model="form.gcPercent" placeholder="请输入GC比例" />
        </el-form-item>
        <el-form-item label="replicon_count" prop="repliconCount">
          <el-input v-model="form.repliconCount" placeholder="请输入replicon_count" />
        </el-form-item>
        <el-form-item label="scaffold_count" prop="scaffoldCount">
          <el-input v-model="form.scaffoldCount" placeholder="请输入scaffold_count" />
        </el-form-item>
        <el-form-item label="contig_count" prop="contigCount">
          <el-input v-model="form.contigCount" placeholder="请输入contig_count" />
        </el-form-item>
        <el-form-item label="总基因数" prop="totalGeneCount">
          <el-input v-model="form.totalGeneCount" placeholder="请输入总基因数" />
        </el-form-item>
        <el-form-item label="翻译蛋白基因数" prop="proteinCodingGeneCount">
          <el-input v-model="form.proteinCodingGeneCount" placeholder="请输入翻译蛋白基因数" />
        </el-form-item>
        <el-form-item label="非编码基因数" prop="nonCodingGeneCount">
          <el-input v-model="form.nonCodingGeneCount" placeholder="请输入非编码基因数" />
        </el-form-item>
        <el-form-item label="中文名" prop="nameCn">
          <el-input v-model="form.nameCn" placeholder="请输入中文名" />
        </el-form-item>
        <el-form-item label="定义" prop="defined">
          <el-input v-model="form.defined" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="序列来源" prop="seqSource">
          <el-input v-model="form.seqSource" placeholder="请输入序列来源" />
        </el-form-item>
        <el-form-item label="解释来源" prop="express">
          <el-input v-model="form.express" placeholder="请输入解释来源" />
        </el-form-item>
        <el-form-item label="文件路径" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入文件路径" />
        </el-form-item>
        <el-form-item label="点突变耐药基因" prop="dtpnyjy">
          <el-input v-model="form.dtpnyjy" placeholder="请输入点突变耐药基因" />
        </el-form-item>
        <el-form-item label="点突变耐药基因说明" prop="dtpnyjyExpress">
          <el-input v-model="form.dtpnyjyExpress" placeholder="请输入点突变耐药基因说明" />
        </el-form-item>
        <el-form-item label="耐药基因" prop="nyjy">
          <el-input v-model="form.nyjy" placeholder="请输入耐药基因" />
        </el-form-item>
        <el-form-item label="耐药基因说明" prop="nyjyExpress">
          <el-input v-model="form.nyjyExpress" placeholder="请输入耐药基因说明" />
        </el-form-item>
        <el-form-item label="毒力基因" prop="dljy">
          <el-input v-model="form.dljy" placeholder="请输入毒力基因" />
        </el-form-item>
        <el-form-item label="毒力基因说明" prop="dljyExpress">
          <el-input v-model="form.dljyExpress" placeholder="请输入毒力基因说明" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDataBase, getDataBase, delDataBase, addDataBase, updateDataBase } from "@/api/data/dataBase"

export default {
  name: "DataBase",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 病原体管理表格数据
      dataBaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type:2,
        assemblyAccession: null,
        refseqCategory: null,
        taxid: null,
        speciesTaxid: null,
        organismName: null,
        infraspecificName: null,
        isolate: null,
        assemblyLevel: null,
        genomeRep: null,
        seqRelDate: null,
        asmName: null,
        gbrsPairedAsm: null,
        pairedAsmComp: null,
        ftpPath: null,
        excludedFromRefseq: null,
        assemblyType: null,
        group: null,
        genomeSize: null,
        genomeSizeUngapped: null,
        gcPercent: null,
        repliconCount: null,
        scaffoldCount: null,
        contigCount: null,
        totalGeneCount: null,
        proteinCodingGeneCount: null,
        nonCodingGeneCount: null,
        nameCn: null,
        defined: null,
        seqSource: null,
        express: null,
        filePath: null,
        dtpnyjy: null,
        dtpnyjyExpress: null,
        nyjy: null,
        nyjyExpress: null,
        dljy: null,
        dljyExpress: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询病原体管理列表 */
    getList() {
      this.loading = true
      listDataBase(this.queryParams).then(response => {
        this.dataBaseList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        assemblyAccession: null,
        refseqCategory: null,
        taxid: null,
        speciesTaxid: null,
        organismName: null,
        infraspecificName: null,
        isolate: null,
        assemblyLevel: null,
        genomeRep: null,
        seqRelDate: null,
        asmName: null,
        gbrsPairedAsm: null,
        pairedAsmComp: null,
        ftpPath: null,
        excludedFromRefseq: null,
        assemblyType: null,
        group: null,
        genomeSize: null,
        genomeSizeUngapped: null,
        gcPercent: null,
        repliconCount: null,
        scaffoldCount: null,
        contigCount: null,
        totalGeneCount: null,
        proteinCodingGeneCount: null,
        nonCodingGeneCount: null,
        nameCn: null,
        defined: null,
        seqSource: null,
        express: null,
        filePath: null,
        dtpnyjy: null,
        dtpnyjyExpress: null,
        nyjy: null,
        nyjyExpress: null,
        dljy: null,
        dljyExpress: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.assemblyAccession)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.assemblyAccession || this.ids
      this.$modal.confirm('是否确认删除病原体管理编号为"' + ids + '"的数据项？').then(function() {
        return delDataBase(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
  }
}
</script>
