<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=":"
        >

          <el-form-item label="到货日期">
            <date-range-picker v-model="query.createTime" class="date-item" />
          </el-form-item>

          <el-form-item label="单据编号">
            <el-input
              v-model="query.receive_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="单据状态">
            <el-select
              v-model="query.bill_status"
              clearable
              size="mini"
              placeholder="请选择"
              class="filter-item"
              style="width: 210px;"
              @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="success"
          icon="el-icon-check"
          size="mini"
          @click="downdtl"
        >
          导出Excel
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        :max-height="590"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="index" label="序号" width="100" align="center" />
        <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 crudRawuatwcquery from '@/api/wms/statistics/rawuatwcquery'
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: 'RawUatCbQuery',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), crud()],
  cruds() {
    return CRUD({
      title: '原材料碳化钨查询',
      url: 'api/rawUatWcQuery',
      idField: 'performance_id',
      sort: 'performance_id,desc',
      crudMethod: { ...crudRawuatwcquery },
      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]() {
      var str = this.$route.path
      // var material_type_id = str.substring(str.length - 2)
      // 截取最后一个/之后的内容
      var index = str.lastIndexOf('\/')
      str = str.substring(index + 1, str.length)
      const material_type_id = str
      crudRawuatwcquery.getHeader(material_type_id).then(res => {
        this.cols = res
      })
      crudInspectionsheetmst.getStatus().then(res => {
        this.statusList = res
      })
      this.query.material_type_id = str
      return true
    },
    hand(value) {
      this.crud.toQuery()
    },
    downdtl() {
      if (this.currentRow !== null) {
        crud.downloadLoading = true
        download('/api/rawUatWcQuery/download', this.crud.query).then(result => {
          downloadFile(result, '原材料碳化钨', 'xlsx')
          crud.downloadLoading = false
        }).catch(() => {
          crud.downloadLoading = false
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
