<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <QueryFormWrapper>
        <el-col :span="8">
          <el-form-item label="物料编码" prop="materialNo">
            <el-input
              v-model="queryParams.materialNo"
              placeholder="请输入物料编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="物料批次" prop="materialLots">
            <el-input v-model="queryParams.materialLots" placeholder="请输入物料批次" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="采购订单" prop="purchaseOrderNo">
            <el-input v-model="queryParams.purchaseOrderNo" placeholder="请输入采购订单" />
          </el-form-item>
        </el-col>
        <div slot="right">
          <el-form-item label-width="0" class="text-right" style="word">
            <EasyAdvancedQuery class="mr10" label-width="98px" @advQuery="advQuery">
              <template #default="{model}">
                <el-row :gutter="10" type="flex">
                  <el-col :span="12">
                    <el-form-item label="物料名称" prop="materialName">
                      <el-input
                        v-model="model.materialName"
                        placeholder="请输入物料名称"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="入库数量" prop="inQty">
                      <el-input
                        v-model="model.inQty"
                        placeholder="请输入入库数量"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
              </template>
            </EasyAdvancedQuery>
            <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-stock:create']"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['wms:incoming-stock:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col> -->
      <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="awaitWare" lazy>
        <AwaitWare
          ref="awaitWare"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="已入库" name="alreadyWare" lazy>
        <!-- 已发 -->
        <AlreadyWare
          ref="alreadyWare"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @columns="getColumns"
        />
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->

    <!-- 对话框(添加 / 修改) -->
  </div>
</template>

<script>
import AwaitWare from './components/AwaitWare.vue'
import AlreadyWare from './components/AlreadyWare.vue'

export default {
  name: 'WareHousing',
  components: {
    AwaitWare,
    AlreadyWare
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // WMS 入库业务-来料入库列表
      list: [],
      // 显示哪一个表格
      activeName: 'awaitWare',
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        wmsIncomingReceiptId: null,
        orderType: null,
        erpStockId: null,
        wmsStoreAreaId: null,
        wmsStoreId: null,
        inQty: null,
        funitId: null,
        remark: null,
        areaTest: null,
        materialLots: null,
        purchaseOrderNo: null,
        createTime: [],
        code: null,
        materialNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wmsIncomingReceiptId: [{ required: true, message: '来料登记记录ID不能为空', trigger: 'blur' }],
        orderType: [{ required: true, message: '单据类型不能为空', trigger: 'change' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsIncomingReceiptId: undefined,
        orderType: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        funitId: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.$refs[this.activeName].advParams = {}
      this.advParams = {}
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
    },
    areaTestChange(item) {
      if (item) {
        const { id } = item
        // this.queryParams.areaTest = name
        this.queryParams.id = id
      }
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams
      this.$refs[this.activeName].advParams = this.advParams
      this.handleQuery()
    },
    getColumns(data) {
      this.columnsList = data
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList()
      })
    }
  }
}
</script>

