<!-- 综合单据查询 -->
<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="materialLots">
            <el-input
              v-model="queryParams.materialLots"
              placeholder="请输入物料批次"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="采购订单" prop="purchaseOrderNo">
            <el-input
              v-model="queryParams.purchaseOrderNo"
              placeholder="请输入采购订单"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <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>
        <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="receiptType">
                      <DictSelect v-model="model.receiptType" placeholder="请选择收料类别" dict-type="WMS_MATERIAL_RECEIVING_CATEGORY" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="领料单号" prop="workOrderBomNo">
                      <el-input
                        v-model="model.workOrderBomNo"
                        placeholder="请输入领料单号"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="生产订单" prop="workOrderNo">
                      <el-input
                        v-model="model.workOrderNo"
                        placeholder="请输入生产订单号"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="物料条码" prop="qrCode">
                      <el-input
                        v-model="model.qrCode"
                        placeholder="请输入物料条码"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="仓库" prop="wmsStockId">
                      <StockSelect
                        :ref="`stock1`"
                        v-model="model.wmsStockId"
                        filterable
                        @change="($event) => { stockChange($event) }"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="区域" prop="wmsStoreAreaId">
                      <AreaSelect
                        :ref="`area1`"
                        v-model="model.wmsStoreAreaId"
                        filterable
                        @change="($event) => { areaChange($event) }"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="货位" prop="wmsStockLocationId">
                      <LocationSelect :ref="`location1`" v-model="model.wmsStockLocationId" filterable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="创建时间" prop="createTime">
                      <el-date-picker
                        v-model="model.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>
                </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-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="来料登记" name="incomingRegister" lazy>
        <IncomingRegister ref="incomingRegister" active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="采购入库" name="purchaseReceipt" lazy>
        <AlreadyWare ref="purchaseReceipt" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="生产领料" name="productionRecieve" lazy>
        <ProductionRecieve ref="productionRecieve" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="生产退料" name="productionReturn" lazy>
        <ProductionReturn ref="productionReturn" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="生产补料" name="productionReplenishment" lazy>
        <ProductionReplenishment ref="productionReplenishment" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="其他出库" name="otherIssue" lazy>
        <OtherIssueDocument ref="otherIssue" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="生产入库" name="productionWarehousing" lazy>
        <ProductionReceipt ref="productionWarehousing" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="销售出库" name="salesIssue" lazy>
        <SalesIssueDocument ref="salesIssue" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import IncomingRegister from './components/IncomingRegister.vue'
import AlreadyWare from '../../incoming/wareHousing/components/AlreadyWare.vue'
import ProductionRecieve from './components/ProductionRecieve.vue'
import ProductionReplenishment from './components/ProductionReplenishment.vue'
import OtherIssueDocument from './components/OtherIssueDocument.vue'
import ProductionReturn from './components/ProductionReturn.vue'
import ProductionReceipt from './components/ProductionReceipt.vue'
import SalesIssueDocument from './components/SalesIssueDocument.vue'

import StockSelect from '../../incoming/wareHousing/components/StockSelect.vue'
import AreaSelect from '../../incoming/wareHousing/components/AreaSelect.vue'
import LocationSelect from '../../incoming/wareHousing/components/LocationSelect.vue'

export default {
  name: 'ComplexDocuments',
  components: {
    IncomingRegister,
    AlreadyWare,
    ProductionRecieve,
    ProductionReplenishment,
    OtherIssueDocument,
    ProductionReturn,
    ProductionReceipt,
    SalesIssueDocument,
    StockSelect,
    AreaSelect,
    LocationSelect
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 显示哪一个表格
      activeName: 'incomingRegister',
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        materialNo: null,
        materialName: null,
        materialLots: null,
        purchaseOrderNo: null,
        workOrderBomNo: null,
        workOrderNo: null,
        createTime: []
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.$nextTick(() => {
      this.$refs[this.activeName].registerOperateShow = false
    })
  },
  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,
        createTime: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs[this.activeName].getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.advParams = {}
      this.$refs[this.activeName].advParams = {}
      this.$refs[this.activeName].handleQuery()
    },
    handleClick(tab, event) {
      this.activeName = tab.name
      if (this.activeName === 'purchaseReceipt') {
        this.$nextTick(() => {
          this.$refs[this.activeName].operateShow = false
        })
      } else if (this.activeName === 'otherIssue') {
        this.$nextTick(() => {
          this.$refs[this.activeName].otherIssueOperate = false
        })
      } else if (this.activeName === 'incomingRegister') {
        this.$nextTick(() => {
          this.$refs[this.activeName].registerOperateShow = false
        })
      }
    },
    // 仓库
    stockChange(item) {
      if (item) {
        const { id } = item
        this.$refs[`area1`].options = []
        this.$refs[`area1`].fetchAreaList(id)
      }
    },
    // 区域
    areaChange(item) {
      if (item) {
        const { id } = item
        this.$refs[`location1`].options = []
        this.$refs[`location1`].fetchLocationList(id)
      }
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams
      this.$refs[this.activeName].advParams = this.advParams
      this.handleQuery()
    }
  }
}
</script>

