<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-width="80px"
          label-suffix=":"
          size="mini"
        >

          <el-form-item label="日期">
            <label slot="label">日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期:</label>
            <date-range-picker v-model="query.createTime" class="date-item" />
          </el-form-item>

          <el-form-item label="单据编号">
            <el-input
              v-model="query.inspection_code"
              clearable
              size="mini"
              placeholder="请输入单据编号"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="物料编码">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="请输入物料编码、名称"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="批次">
            <label slot="label">批&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;次:</label>
            <el-input
              v-model="query.pcsn"
              clearable
              size="mini"
              placeholder="请输入批次"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="型号">
            <label slot="label">型&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</label>
            <el-input
              v-model="query.material_model"
              clearable
              size="mini"
              placeholder="请输入型号"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="炉号">
            <label slot="label">炉&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</label>
            <el-input
              v-model="query.other_device_no"
              clearable
              size="mini"
              placeholder="请输入炉号"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="单据状态">
            <el-select
              v-model="query.bill_status"
              clearable
              size="mini"
              placeholder="请选择"
              class="filter-item"
              style="width: 230px;"
              @change="hand"
            >
              <el-option
                v-for="item in statusList"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          class="filter-item"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="Export"
        >
          导出
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        :max-height="590"
        size="mini"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="index" label="序号" width="100" align="center" fixed />
        <el-table-column prop="0" label="质检单号" min-width="100" show-overflow-tooltip fixed />
        <el-table-column prop="1" label="物料编码" min-width="100" show-overflow-tooltip fixed />
        <el-table-column prop="20" label="物料名称" min-width="100" show-overflow-tooltip fixed />
        <el-table-column prop="2" label="批号" min-width="100" show-overflow-tooltip fixed />
        <template v-for="(col,index) in cols">
          <el-table-column v-if="col" :prop="col.prop" :label="col.label" width="120px" show-overflow-tooltip />
        </template>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudPhySicalQuery from '@/api/wms/statistics/physicalquery'
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
import crudInspectionsheetmst from '@/api/wms/ql/inspectionsheetmst'
import { download } from '@/api/data'
import { downloadFile } from '@/utils'

export default {
  name: 'PhySicalQuery',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), crud()],
  cruds() {
    return CRUD({
      title: '理化报告查询',
      url: 'api/physicalQuery',
      idField: 'performance_id',
      sort: 'performance_id,desc',
      crudMethod: { ...crudPhySicalQuery },
      props: {
        // 每页数据条数
        size: 20
      },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      cols: [],
      statusList: [],
      permission: {
      },
      rules: {
      }}
  },
  beforeCreate() {
  },
  created() {
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      crudPhySicalQuery.getHeader().then(res => {
        this.cols = res
      })
      crudInspectionsheetmst.getStatus().then(res => {
        this.statusList = res
      })
    },
    hand(value) {
      this.crud.toQuery()
    },
    Export() {
      download('/api/physicalQuery/download', this.query).then(result => {
        downloadFile(result, '理化报告查询', 'xlsx')
        crud.downloadLoading = false
      }).catch(() => {
        crud.downloadLoading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
