<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="productCode">
            <el-input
              v-model="queryParams.productCode"
              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="SN码" prop="materialSerinalNo">
            <el-input
              v-model="queryParams.materialSerinalNo"
              placeholder="请扫入\输入成品SN码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="原箱号" prop="boxNo">
            <el-input
              v-model="queryParams.boxNo"
              placeholder="请输入原箱号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </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">
      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columnsList"
        @queryTable="handleQuery"
        @saveSetting="getColumnsList"
      />
    </el-row>

    <!-- 列表 -->
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="已拆成品列表" name="dismantledList" lazy>
        <DismantledList
          ref="dismantledList"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="重新装箱" name="reBoxList" lazy>
        <!-- 已发 -->
        <ReBoxList
          ref="reBoxList"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @complete="complete"
        />
      </el-tab-pane>
      <el-tab-pane label="成品补打" name="boxRepaired" lazy>
        <BoxRepaired ref="boxRepaired" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import DismantledList from './components/DismantledList.vue'
import ReBoxList from './components/ReBoxList.vue'
import BoxRepaired from './components/BoxRepaired.vue'

export default {
  name: 'ProductsReBox',
  components: {
    DismantledList,
    ReBoxList,
    BoxRepaired
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // MES 成品拆箱后待装箱内容列表
      list: [],
      // 弹出层标题
      title: '',
      activeName: 'dismantledList',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        mesReBoxStatus: null,
        materialSerinalNo: null,
        createTime: [],
        boxNo: null,
        workOrderNo: null,
        productCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        mesReBoxStatus: [{ required: true, message: '待重装标记 0=待装，1=已装箱不能为空', trigger: 'blur' }],
        materialSerinalNo: [{ required: true, message: '半成品、成品SN码不能为空', trigger: 'blur' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        mesReBoxStatus: undefined,
        materialSerinalNo: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    complete() {
      const dismantledLists = this.$refs.dismantledList
      dismantledLists && dismantledLists.handleQuery()
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>

