<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="requestNo">
            <el-input
              v-model="queryParams.requestNo"
              placeholder="请输入申请单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="申请类型" prop="requestType">
            <el-select
              v-model="queryParams.requestType"
              placeholder="请选择申请类型"
              clearable
              size="small"
            >
              <el-option label="请选择字典生成" value="" />
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="业务类型" prop="businessType">
            <el-select
              v-model="queryParams.businessType"
              placeholder="请选择业务类型"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in getDictDatas('inout_business_type')"
                :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">
            <EasyAdvancedQuery
              class="mr10"
              label-width="98px"
              @advQuery="advQuery"
            >
              <template #default="{ model }">
                <el-col :span="12">
                  <el-form-item label="业务分类编码" prop="businessCategory">
                    <el-input
                      v-model="queryParams.businessCategory"
                      placeholder="请输入业务分类编码"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="业务分类名称" prop="businessDescribe">
                    <el-input
                      v-model="queryParams.businessDescribe"
                      placeholder="请输入业务分类名称"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="业务子类型" prop="businessSubType">
                    <el-select
                      v-model="queryParams.businessSubType"
                      placeholder="请选择业务子类型"
                      clearable
                      size="small"
                    >
                      <el-option label="请选择字典生成" value="" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="状态" prop="status">
                    <el-select
                      v-model="queryParams.status"
                      placeholder="请选择状态"
                      clearable
                      size="small"
                    >
                      <el-option label="请选择字典生成" value="" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="优先级" prop="priority">
                    <el-input
                      v-model="queryParams.priority"
                      placeholder="请输入优先级"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="供应商编码" prop="supplierCode">
                    <el-input
                      v-model="queryParams.supplierCode"
                      placeholder="请输入供应商编码"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="客户编码" prop="customerCode">
                    <el-input
                      v-model="queryParams.customerCode"
                      placeholder="请输入客户编码"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="源单编号" prop="sourceOrderNo">
                    <el-input
                      v-model="queryParams.sourceOrderNo"
                      placeholder="请输入源单编号"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="预计出入库时间" prop="expectedTime">
                    <el-date-picker
                      v-model="queryParams.expectedTime"
                      style="width: 240px"
                      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="24">
                  <el-form-item label="实际出入库时间" prop="actualTime">
                    <el-date-picker
                      v-model="queryParams.actualTime"
                      style="width: 240px"
                      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="totalQty">
                    <el-input
                      v-model="queryParams.totalQty"
                      placeholder="请输入总数量"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="总SKU数" prop="totalSku">
                    <el-input
                      v-model="queryParams.totalSku"
                      placeholder="请输入总SKU数"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="总行数" prop="totalLine">
                    <el-input
                      v-model="queryParams.totalLine"
                      placeholder="请输入总行数"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="备注" prop="remark">
                    <el-input
                      v-model="queryParams.remark"
                      placeholder="请输入备注"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="创建时间" prop="createTime">
                    <el-date-picker
                      v-model="queryParams.createTime"
                      style="width: 240px"
                      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="submitter">
                    <el-input
                      v-model="queryParams.submitter"
                      placeholder="请输入提交人"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="提交时间" prop="submitTime">
                    <el-date-picker
                      v-model="queryParams.submitTime"
                      style="width: 240px"
                      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="auditor">
                    <el-input
                      v-model="queryParams.auditor"
                      placeholder="请输入审核人"
                      clearable
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="审核时间" prop="auditTime">
                    <el-date-picker
                      v-model="queryParams.auditTime"
                      style="width: 240px"
                      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>
              </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
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="openForm(undefined)"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          >导出</el-button
        >
        <el-button type="primary" plain size="small" icon="el-icon-s-check"
          >审核</el-button
        >
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
    >
      <el-table-column
        label="申请单号"
        width="180px"
        align="center"
        prop="requestNo"
      />
      <!-- <el-table-column label="申请单号" align="center" prop="requestNo">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleToDemerge(scope.row)"
            >{{ scope.row.requestNo }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="申请类型" align="center" prop="requestType" /> -->
      <el-table-column label="业务类型" align="center" prop="businessType" />
      <el-table-column
        label="业务分类编码"
        align="center"
        width="150px"
        prop="businessCategory"
      />
      <el-table-column
        label="业务分类名称"
        align="center"
        width="150px"
        prop="businessDescribe"
      />
      <el-table-column
        label="业务子类型"
        align="center"
        width="150px"
        prop="businessSubType"
      />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="优先级" align="center" prop="priority" />
      <el-table-column
        label="供应商编码"
        width="150px"
        align="center"
        prop="supplierCode"
      />
      <el-table-column label="客户编码" align="center" prop="customerCode" />
      <el-table-column
        label="源单编号"
        width="150px"
        align="center"
        prop="sourceOrderNo"
      />
      <el-table-column
        label="预计出入库时间"
        align="center"
        prop="expectedTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.expectedTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="实际出入库时间"
        align="center"
        prop="actualTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.actualTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总数量" align="center" prop="totalQty" />
      <el-table-column label="总SKU数" align="center" prop="totalSku" />
      <el-table-column label="总行数" align="center" prop="totalLine" />
      <el-table-column
        label="备注"
        width="150px"
        align="center"
        prop="remark"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交人" align="center" prop="submitter" />
      <el-table-column
        label="提交时间"
        align="center"
        prop="submitTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditor" />
      <el-table-column
        label="审核时间"
        align="center"
        prop="auditTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.auditTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="150px"
        class-name="small-padding fixed-width"
      >
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="openForm(scope.row.id)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 对话框(添加 / 修改)
    <InRequestForm ref="formRef" @success="getList" /> -->
  </div>
</template>

<script>
import * as InRequestApi from "@/api/wms/output/inrequest";
import InRequestForm from "./components/InRequestForm.vue";
import QueryFormWrapper from "@/components/QueryFormWrapper";
import EasyAdvancedQuery from "@/components/EasyAdvancedQuery";
export default {
  name: "InRequest",
  components: {
    InRequestForm,
    QueryFormWrapper,
    EasyAdvancedQuery,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库申请主列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        requestNo: null,
        requestType: null,
        businessType: null,
        businessCategory: null,
        businessDescribe: null,
        businessSubType: null,
        status: null,
        priority: null,
        warehouseId: null,
        relatedWarehouseId: null,
        supplierCode: null,
        customerCode: null,
        sourceOrderNo: null,
        expectedTime: [],
        actualTime: [],
        totalQty: null,
        totalSku: null,
        totalLine: null,
        remark: null,
        extendInfo: null,
        createTime: [],
        submitter: null,
        submitTime: [],
        auditor: null,
        auditTime: [],
        erpWriteFlag: null,
        erpErrMsg: null,
        erpBackId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 高级查询处理 */
    advQuery(advQueryParams) {
      this.advParams = advQueryParams;
      this.handleQuery();
    },
    /** 查询列表 */
    async getList() {
      this.loading = true;
      const params = { ...this.queryParams, ...this.advParams };
      await InRequestApi.getInRequestPage(params)
        .then((res) => {
          this.list = res.data.list;
          this.total = res.data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // 重置表单
      this.resetForm("queryForm");
      // 重置查询参数
      Object.assign(this.queryParams, {
        pageNo: 1,
        pageSize: 10,
        requestNo: null,
        requestType: null,
        businessType: null,
        businessCategory: null,
        businessDescribe: null,
        businessSubType: null,
        status: null,
        priority: null,
        warehouseId: null,
        relatedWarehouseId: null,
        supplierCode: null,
        customerCode: null,
        sourceOrderNo: null,
        expectedTime: [],
        actualTime: [],
        totalQty: null,
        totalSku: null,
        totalLine: null,
        remark: null,
        extendInfo: null,
        createTime: [],
        submitter: null,
        submitTime: [],
        auditor: null,
        auditTime: [],
        erpWriteFlag: null,
        erpErrMsg: null,
        erpBackId: null,
      });
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      // 跳转到指定页面
      this.$router.push({
        path: "/outStorageManage/inrequest/InRequestForm",
        query: { id: id },
      });
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm(
        '是否确认删除入库申请主编号为"' + id + '"的数据项?'
      );
      try {
        await InRequestApi.deleteInRequest(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {}
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm("是否确认导出所有入库申请主数据项?");
      try {
        this.exportLoading = true;
        const data = await InRequestApi.exportInRequestExcel(this.queryParams);
        this.$download.excel(data, "入库申请主.xls");
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
    // 跳转分拆单详情
    handleToDemerge(row) {
      const { id, requestNo } = row;
      this.$router.push({
        path: "/entry-exit/inrequestdetails",
        query: { id, requestNo },
      });
    },
  },
};
</script>
