<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form style="margin-top: 10px;">
        <el-form-item>
          <el-select
            v-model="listQuery.searchYsjl.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-select
            v-model="listQuery.searchYsjl.shebeileibiedaima"
            placeholder="请选择设备类别"
            style="width: 165px"
            clearable
            default-first-option
            @change="changeSbpz"
          >
            <el-option v-for="item in sblbList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <el-input v-model="listQuery.searchYsjl.shiyongdanwei" placeholder="请输入使用单位" style="width: 165px" />
          <el-select
            v-model="listQuery.searchYsjl.jianyanrenyuan"
            placeholder="请选择检验人员"
            style="width: 165px"
            filterable
            clearable
          >
            <el-option v-for="item in userList" :key="item.id" :label="item.nickname" :value="item.id" />
          </el-select>
          <el-date-picker
            v-model="listQuery.searchYsjl.jianjiankaishiriqi"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始日期"
          />
          <el-date-picker
            v-model="listQuery.searchYsjl.jianjianjieshuriqi"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束日期"
          />
          <el-select v-model="listQuery.searchYsjl.quhuadaima" placeholder="请选择" style="width: 240px;" clearable @change="handleFilter">
            <el-option v-for="item in areas" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <el-button type="primary" size="small" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
          <el-button type="info" size="small" 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%"
      size="small"
      @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="150" sortable="custom" />
      <el-table-column align="center" label="注册代码" prop="zhucedaima" width="170" sortable="custom" />
      <el-table-column align="center" label="使用单位" prop="shiyongdanwei" width="200" />
      <el-table-column align="center" label="产品名称/设备名称" prop="shebeimingcheng" width="130" />
      <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="200" />
      <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="130" />
      <el-table-column align="center" label="单位内编号" prop="danweineibubianhao" width="130" 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 fixed="right" align="center" label="操作" prop="" width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            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"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'

export default {
  name: 'GlDjStatistics',
  components: { Pagination },
  data() {
    return {
      totalCount: 0,
      list: [],
      listQuery: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: 'shenpiriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        searchYsjl: {
          createBy: this.$store.getters.departmentId === 70 ? this.$store.getters.userId : undefined
        },
        hasChild: true,
        hasFinish: true
      },
      multipleSelection: [],
      dialogQueryVisible: false,
      dialogResetFlow: false,
      resetData: {
        reason: ''
      },
      jylbList: [],
      roleName: '容器制造',
      showResetFlowApply: true,
      statusList: [
        {
          value: 1,
          label: '起草报告'
        }, {
          value: 2,
          label: '审核报告'
        }, {
          value: 3,
          label: '审批报告'
        }
      ],
      userList: [],
      exportList: [],
      dialogFormExportReportVisible: false,
      listQueryExport: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: 'shenpiriqi desc,id', // 排序字段
        sort: 'desc', // 排序方式
        searchYsjl: {
          createBy: this.$store.getters.userId
        },
        hasChild: false,
        hasFinish: true
      },
      totalCountExport: 0,
      outFile: '', // 导出文件el
      jianyanrenyuanmingcheng: '',
      departmentName: '',
      zzdwName: '',
      resetRecordList: [],
      dialogResetRecords: false,
      dialogSelectionMethod: false,
      dialogReason: false,
      areas: [],
      sblbList: [],
      sbpzList: []
    }
  },
  created() {
    this.getList()
    this.jylbList = this.$store.getters.allCategory
    this.userList = this.$store.getters.allUser.filter(user => user.departmentId === this.$store.getters.departmentId)
    this.getArea()
    this.getSbList('1000', undefined, 2)
  },
  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
    },
    clearQuery() {
      this.$set(this.listQuery, 'searchYsjl', {
        createBy: this.$store.getters.userId
      })
      this.getList()
    },
    getArea() { // 查询区划
      this.api({
        url: '/area/getShiArea',
        method: 'get',
        params: {
          shidaima: '370100'
        }
      }).then(data => {
        this.areas = data
      })
    },
    getSbList(sbzl, sblb, level) {
      this.api({
        url: '/sedirectory/getList',
        method: 'get',
        params: {
          sbzl: sbzl,
          sblb: sblb,
          level: level
        }
      }).then(data => {
        switch (level) {
          case 2:
            this.sblbList = data
            break
          case 3:
            this.sbpzList = data
            break
          default:
            break
        }
      })
    },
    changeSbpz() {
      const sblb = this.sblbList.filter(sblb => sblb.value === this.listQuery.searchYsjl.shebeileibiedaima)[0]
      this.$set(this.listQuery.searchYsjl, 'shebeipinzhongdaima', '')
      if (sblb) {
        this.sbpzList = sblb.children
      } else {
        this.sbpzList = []
      }
    }
  }
}
</script>

<style>
  .app-container {
    padding-top: 5px;
    padding-bottom: 0px;
  }
</style>
