<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <el-col :span="6">
          <el-form-item label="报废单号" prop="scrapNo">
            <el-input
              v-model="queryParams.scrapNo"
              placeholder="请输入报废单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="产品条码" prop="productBarcode">
            <el-input
              v-model="queryParams.productBarcode"
              placeholder="请输入产品条码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="生产订单" prop="workOrderNo">
            <el-input
              v-model="queryParams.workOrderNo"
              placeholder="请输入生产订单"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="创建时间" prop="createTime">
            <el-date-picker
              v-model="queryParams.createTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </div>
      </QueryFormWrapper>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['wms:incoming-scrap:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :columns="columnsList"
        :show-search.sync="showSearch"
        @queryTable="handleQuery"
        @saveSetting="getColumnsList"
      />
    </el-row>

    <!-- 列表 -->
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="待入库" name="awaitScrapStock" lazy>
        <AwaitScrapStock
          ref="awaitScrapStock"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @alreadyScrapComplete="alreadyScrapComplete"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="已入库" name="alreadyScrapStock" lazy>
        <AlreadyScrapStock
          ref="alreadyScrapStock"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @columns="getColumns"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import AwaitScrapStock from './components/AwaitScrapStock.vue'
import AlreadyScrapStock from './components/AlreadyScrapStock.vue'

export default {
  name: 'IncomingScrap',
  components: {
    AwaitScrapStock,
    AlreadyScrapStock
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库业务 报废入库列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      activeName: 'awaitScrapStock',
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        scrapNo: null,
        productBarcode: null,
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        createTime: [],
        workOrderNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rejectNo: [{ required: true, message: '报废单号不能为空', trigger: 'blur' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {

    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        rejectNo: undefined,
        productBarcode: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNo = 1
      // this.getList()
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      // this.handleQuery()
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    alreadyScrapComplete() {
      const alreadyScrapStock = this.$refs.alreadyScrapStock
      alreadyScrapStock && alreadyScrapStock.handleQuery()
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>

