<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form>
        <el-form-item>
          <el-input v-model="listQuery.jilubianhao" placeholder="记录编号" clearable style="width: 200px" @keyup.enter.native="handleFilter" />
          <el-input v-model="listQuery.shigongdanwei" placeholder="安装单位" clearable style="width: 400px" @keyup.enter.native="handleFilter" />
          <el-button size="small" type="primary" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
          <el-button size="small" type="info" icon="el-icon-close" @click="clearQuery">
            清空条件
          </el-button>
          <br>
          <el-input v-model="listQuery.zhizaodanwei" placeholder="制造单位" clearable style="width: 400px" @keyup.enter.native="handleFilter" />
          <el-input v-model="listQuery.chanpinbianhao" placeholder="出厂编号" clearable style="width: 200px" @keyup.enter.native="handleFilter" />
          <span class="radio-group-label">编辑类型：</span>
          <el-radio-group v-model="listQuery.createBy" @change="handleFilter">
            <el-radio :label="$store.getters.userId">
              只看创建人
            </el-radio>
            <el-radio :label="undefined">
              全部
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      ref="list"
      v-adaptive="{bottomOffset: 50}"
      height="0"
      :data="list"
      :default-sort="{prop:'jilubianhao', order:'descending'}"
      element-loading-text="拼命加载中"
      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="60">
        <template slot-scope="scope">
          <span v-text="getIndex(scope.$index)" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="记录编号" prop="jilubianhao" width="180" sortable="custom" />
      <el-table-column :formatter="formatter.formatterCategory" align="center" label="检验类别" prop="neibuleibie" width="100" />
      <el-table-column align="center" label="安装单位" prop="shigongdanwei" width="240" />
      <el-table-column align="center" label="产品编号/出厂编号" prop="chanpinbianhao" width="220" />
      <el-table-column align="center" label="制造单位" prop="zhizaodanwei" width="240" />
      <el-table-column :formatter="formatter.getChineseName" align="center" label="检验人员" prop="jianyanrenyuan" width="140" />
      <el-table-column align="center" label="设备代码" prop="shebeidaima" width="140" />
      <el-table-column align="center" label="操作" prop="" width="120">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" circle icon="el-icon-view" title="预览 原始记录" @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" style="float: left;" @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data() {
    return {
      totalCount: 0,
      list: [],
      listQuery: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: undefined, // 排序字段
        sort: undefined, // 排序方式
        createBy: this.$store.getters.userId,
        hasChild: true,
        link: 2
      },
      multipleSelection: [],
      bglxOptions: [{
        value: '1',
        label: '主报告'
      }, {
        value: '2',
        label: '无损报告'
      }]
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    const that = this
    this.common.$on('ysjl-yb-list', function() {
      that.handleFilter()
    })
  },
  methods: {
    getList() {
      this.listQuery.cjState = 'bggl'
      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.getList()
    },
    onRowClick(row) {
      this.$refs.list.toggleRowSelection(row)
    },
    handleSelectionChange: function(val) {
      this.multipleSelection = val
    },
    clearQuery() {
      this.listQuery = {
        order: undefined, // 排序字段
        sort: undefined, // 排序方式
        createBy: this.$store.getters.userId,
        hasChild: true
      }
      this.getList()
    }
  }
}
</script>
