<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="100px"
    >
      <QueryFormWrapper>
        <el-col :span="8">
          <el-form-item label="入库单号" prop="inOrderNo">
            <el-input
              v-model="queryParams.inOrderNo"
              placeholder="请输入入库单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="申请人员" prop="applyer">
            <el-input
              v-model="queryParams.applyer"
              placeholder="请输入申请人员"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="申请入库时间" prop="applyTime">
            <el-date-picker
              v-model="queryParams.applyTime"
              style="width: 100%"
              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">
            <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="inStorager">
                      <el-input
                        v-model="model.inStorager"
                        placeholder="请输入入库人员"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="实际入库时间" prop="realTime">
                      <el-date-picker
                        v-model="model.realTime"
                        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-col :span="12">
                    <el-form-item label="生产订单编号" prop="erpWorkOrderNo">
                      <el-input
                        v-model="model.erpWorkOrderNo"
                        placeholder="请输入生产订单编号"
                        clearable
                        @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="关联订单数" prop="countOrderNo">
                      <el-input
                        v-model="model.countOrderNo"
                        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-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
        :columns="columnsList"
        :show-search.sync="showSearch"
        @saveSetting="getColumnsList"
      />
    </el-row>

    <!-- 列表 -->
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="待入库" name="awaitProductWare" lazy>
        <AwaitProductWare
          ref="awaitProductWare"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @productComplete="productComplete"
          @columns="getAwaitColumns"
        />
      </el-tab-pane>
      <el-tab-pane label="已入库" name="alreadyProductWare" lazy>
        <!-- 已发 -->
        <AlreadyProductWare
          ref="alreadyProductWare"
          :active-name="activeName"
          :query-paramspro="queryParams"
          @cloumns="getAwaitColumns"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog
      v-dialogDrag
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入库单号" prop="warehousingOrderNo">
          <el-input
            v-model="form.warehousingOrderNo"
            placeholder="请输入入库单号"
          />
        </el-form-item>
      </el-form>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import AwaitProductWare from "./components/AwaitProductWare.vue";
import AlreadyProductWare from "./components/AlreadyProductWare.vue";

export default {
  name: "IncomingProduce",
  components: {
    AwaitProductWare,
    AlreadyProductWare,
  },
  provide() {
    return {
      paramsQuery: this.queryParams,
    };
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库业务 生产入库列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 显示哪一个表格
      activeName: "awaitProductWare",
      // 高级查询参数
      advParams: {
        applyTime: [],
        inStorager: null,
        realTime: null,
        sumDetailQty: null,
        countOrderNo: null,
        productCode: null,
        productName: null,
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        inOrderNo: null,
        inQty: null,
        applyer: null,
        applyTime: [],
        inStorager: null,
        realTime: [],
        sumDetailQty: null,
        countOrderNo: null,
        productCode: null,
        productName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        warehousingOrderNo: [
          { required: true, message: "入库单号不能为空", trigger: "blur" },
        ],
      },
      // // 显示隐藏列默认参数
      // columns: [
      //   { key: 0, label: '生产入库单号', visible: true },
      //   { key: 1, label: '申请入库时间', visible: true },
      //   { key: 2, label: '申请人', visible: true },
      //   { key: 3, label: '入库箱数', visible: true },
      //   { key: 4, label: '检验结果', visible: true },
      //   { key: 5, label: '检验单号', visible: true },
      //   { key: 6, label: '入库单号', visible: true },
      //   { key: 7, label: '物料编码', visible: true },
      //   { key: 8, label: '物料名称', visible: true },
      //   { key: 9, label: '计划数量', visible: true },
      //   { key: 10, label: 'BOM版本', visible: true },
      //   { key: 11, label: '生产订单', visible: true },
      //   { key: 12, label: '箱号', visible: true },
      //   { key: 13, label: '拆箱状态', visible: true },
      //   { key: 14, label: '装箱数量', visible: true },
      //   { key: 15, label: '仓库', visible: true },
      //   { key: 16, label: '区域', visible: true },
      //   { key: 17, label: '货位', visible: true },
      //   { key: 18, label: '操作人', visible: true },
      //   { key: 19, label: '入库时间', visible: true }
      // ],
      // // 显示隐藏持久化参数
      columnsList: [],
    };
  },
  // 获取当前登录用户id
  // computed: {
  //   ...mapGetters([
  //     'userId'
  //   ])
  // },
  created() {
    // this.getColumnsList()
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        warehousingOrderNo: 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;
    },
    productComplete() {
      const alreadyProductWare = this.$refs.alreadyProductWare;
      alreadyProductWare && alreadyProductWare.handleQuery();
    },
    // 高级查询
    advQuery(advQueryParams) {
      this.advParams = advQueryParams;
      this.$refs[this.activeName].advParams = this.advParams;
      this.handleQuery();
    },
    // 获取显示隐藏列
    getColumnsList() {
      this.$nextTick(() => {
        this.$refs[this.activeName].getColumnsList();
      });
    },
    // 获取待入库的显隐列
    getAwaitColumns(data) {
      this.columnsList = data;
    },
  },
};
</script>
