<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="workOrderBomNo">
            <el-input
              v-model="queryParams.workOrderBomNo"
              placeholder="请输入领料单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <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="8">
          <el-form-item label="领料状态" prop="receiveStatus">
            <el-select
              v-model="queryParams.receiveStatus"
              placeholder="请选择领料状态"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in getDictDatas(DICT_TYPE.WMS_RECEIVE_MATERIALS_STATUS)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </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="materialNo">
                      <el-input
                        v-model="model.materialNo"
                        placeholder="请输入物料编码"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <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="productCode">
                      <el-input
                        v-model="model.productCode"
                        placeholder="请输入产品编码"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="产品名称" prop="productName">
                      <el-input
                        v-model="model.productName"
                        placeholder="请输入产品名称"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </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-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="toSent" lazy>
        <ToSent
          ref="toSent"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @toIssueComplete="toIssueComplete"
          @columns="getColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="已发" name="sent" lazy>
        <!-- 已发 -->
        <Sent ref="sent" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
      <el-tab-pane label="已结束" name="completed" lazy>
        <!-- 已结束 -->
        <Completed ref="completed" :active-name="activeName" :query-paramspro="queryParams" />
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->

  </div>
</template>

<script>
import ToSent from './components/ToSent.vue'
import Sent from './components/Sent.vue'
import Completed from './components/Completed.vue'

export default {
  name: 'OutStock',
  components: {
    ToSent,
    Sent,
    Completed
  },
  provide() {
    return {
      paramsQuery: this.queryParams
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // WMS 生产发料 主列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      activeName: 'toSent',
      // 高级查询参数
      advParams: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        wmsProductionWorkOrderBomDetailId: null,
        workOrderNo: null,
        type: null,
        outStockNo: null,
        receiveStatus: null,
        createTime: [],
        materialNo: null,
        materialName: null,
        productCode: null,
        productName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wmsProductionWorkOrderBomDetailId: [{ required: true, message: 'ERP用料清单明细表ID不能为空', trigger: 'blur' }],
        outStockNo: [{ required: true, message: '发料单号不能为空', trigger: 'blur' }]
      },
      // 显隐列
      columnsList: []
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsProductionWorkOrderBomDetailId: undefined,
        outStockNo: undefined,
        type: 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
    },
    toIssueComplete() {
      const sentIssue = this.$refs.sent
      sentIssue && sentIssue.handleQuery()
    },
    // 高级查询
    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>

