<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form style="margin-top: 10px;">
        <el-form-item>
          <el-input
            v-model="listQuery.baogaobianhao"
            placeholder="报告编号"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleFilter"
          />
          <el-input
            v-model="listQuery.zhucedaima"
            placeholder="注册代码"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleFilter"
          />
          <el-input
            v-model="listQuery.shiyongdanwei"
            placeholder="使用单位"
            clearable
            style="width: 350px"
            @keyup.enter.native="handleFilter"
          />
          <el-button type="primary" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
          <el-button type="primary" icon="el-icon-search" @click="highQuery">
            高级查询
          </el-button>
          <el-button type="info" icon="el-icon-close" @click="clearQuery">
            清空条件
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      ref="list"
      v-adaptive="{bottomOffset: 50}"
      height="0"
      :data="list"
      border
      fit
      highlight-current-row
      stripe
      width="100%"
      @row-click="onRowClick"
      @selection-change="handleSelectionChange"
      @sort-change="sortChange"
    >
      <el-table-column type="selection" width="40" />
      <el-table-column fixed="left" align="center" label="序号" width="50">
        <template slot-scope="scope">
          <span v-text="getIndex(scope.$index)" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="报告编号" prop="baogaobianhao" width="180" sortable="custom" />
      <el-table-column :formatter="formatter.formatterCategory" align="center" label="检验类别" prop="neibuleibie" width="100" />
      <el-table-column align="center" label="使用登记证号" prop="shiyongdengjibianhao" width="180" sortable="custom" />
      <el-table-column align="center" label="注册代码" prop="zhucedaima" width="180" sortable="custom" />
      <el-table-column align="center" label="使用单位" prop="shiyongdanwei" width="240" />
      <el-table-column align="center" label="产品名称/设备名称" prop="shebeimingcheng" width="220" />
      <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="240" />
      <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="220" />
      <el-table-column align="center" label="单位内编号" prop="danweineibubianhao" width="150" sortable="custom" />
      <el-table-column :formatter="formatter.getChineseName" align="center" label="检验人员" prop="jianyanrenyuan" width="140" />
      <el-table-column align="center" label="检验日期" prop="jianyanjieshuriqi" width="110" sortable="custom" />
      <el-table-column align="center" label="下次检验日期" prop="xiacijianyanriqi" width="130" sortable="custom" />
      <el-table-column align="center" label="检验结论" prop="jianyanjielun" width="120" />
      <el-table-column :formatter="formatterHuanjie" fixed="right" align="center" label="当前环节" prop="flowstatus" width="80" />
      <el-table-column fixed="right" align="center" label="报告类型" prop="inspectionItems" width="95">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.bglx===1">
            主报告
          </el-tag>
          <el-tag v-if="scope.row.bglx===2" type="success">
            {{ scope.row.inspectionItems }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" label="操作" prop="" width="100">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-view"
            title="预览"
            circle
            @click="common.viewYsjl(scope.row.id, 'JYBG')"
          />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalCount>0"
      :total="totalCount"
      :page-num.sync="listQuery.pageNum"
      :page-row.sync="listQuery.pageRow"
      @pagination="getList"
    />
    <!-- 高级查询窗口 -->
    <el-dialog :visible.sync="dialogQueryVisible" title="高级查询" width="60%">
      <el-container>
        <el-form :inline="true">
          <el-form-item label="检验类别:" style="width: 240px;">
            <el-select
              v-model="listQuery.neibuleibie"
              placeholder="请选择检验类别"
              style="width: 165px"
              clearable
              default-first-option
            >
              <el-option v-for="item in jylbList" v-show="item.parentId" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备/产品名称:" style="width: 290px;">
            <el-input
              v-model="listQuery.shebeimingcheng"
              placeholder="请输入设备/产品名称"
              clearable
              style="width: 185px"
            />
          </el-form-item>
          <el-form-item label="制造单位:" style="width: 450px;">
            <el-input v-model="listQuery.zhizaodanwei" placeholder="请输入制造单位" style="width: 370px" />
          </el-form-item>
          <el-form-item label="使用登记证编号:" style="width: 350px;">
            <el-input
              v-model="listQuery.shiyongdengjibianhao"
              placeholder="请输入使用登记证编号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="产品/出厂编号:" style="width: 290px;">
            <el-input v-model="listQuery.chanpinbianhao" placeholder="请输入产品编号" style="width: 185px" />
          </el-form-item>
        </el-form>
      </el-container>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogQueryVisible = false">
          取 消
        </el-button>
        <el-button type="success" @click="handleFilter">
          查 询
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
export default {
  name: 'SignList',
  components: { Pagination },
  data() {
    return {
      totalCount: 0,
      list: [],
      listQuery: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: 'jianyanjieshuriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        bglx: 2, // 无损报告
        jianyanrenyuan: this.$store.getters.userId,
        hasFinish: null,
        hasLook: 1, // 科室数据
        ownRoles: 1 // 检验员包括自己的
      },
      multipleSelection: [],
      dialogQueryVisible: false,
      jylbList: []
    }
  },
  created() {
    this.getList()
    this.jylbList = this.$store.getters.allCategory
  },
  methods: {
    getList() {
      this.api({
        url: '/ysjl/getList',
        method: 'get',
        params: this.listQuery
      }).then(data => {
        this.list = data.list
        this.totalCount = data.totalCount
        this.common.switchInspection(this.list)
      })
    },
    sortChange(column) {
      this.listQuery.order = column.prop
      this.listQuery.sort = column.order.replace('ending', '')
      this.getList()
    },
    getIndex($index) {
      // 表格序号
      return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
    },
    handleFilter() {
      // 查询事件
      this.listQuery.pageNum = 1
      this.dialogQueryVisible = false
      this.getList()
    },
    onRowClick(row) {
      this.$refs.list.toggleRowSelection(row)
    },
    handleSelectionChange: function(val) {
      this.multipleSelection = val
    },
    highQuery() {
      this.dialogQueryVisible = true
    },
    clearQuery() {
      this.listQuery = {
        order: 'jianyanjieshuriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        bglx: 2, // 无损报告
        jianyanrenyuan: this.$store.getters.userId,
        hasFinish: null,
        hasLook: 1, // 科室数据
        ownRoles: 1 // 检验员包括自己的
      }
      this.getList()
    },
    formatterHuanjie(row) {
      switch (row.flowstatus) {
        case 1:
          return '起草报告'
        case 2:
          return '审核报告'
        case 3:
          return '审批报告'
        case 4:
          return '办结报告'
        default:
          return '未知'
      }
    }
  }
}
</script>

<style scoped>

</style>
