<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="申请单号" prop="requestNo">
        <el-input
          v-model="queryParams.requestNo"
          placeholder="请输入申请单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <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>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['rtkwms:in-request:create']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="openForm(undefined)"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['rtkwms:in-request:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          >导出</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="申请单ID" align="center" prop="id" /> -->
      <el-table-column
        label="申请单号"
        align="center"
        width="180px"
        prop="requestNo"
      />
      <!-- <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="业务子类型"
        width="150px"
        align="center"
        prop="businessSubType"
      />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="优先级" align="center" prop="priority" />
      <!-- <el-table-column label="仓库ID" align="center" prop="warehouseId" />
      <el-table-column
        label="关联仓库ID"
        align="center"
        prop="relatedWarehouseId"
      /> -->
      <el-table-column
        label="供应商编码"
        align="center"
        width="150px"
        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
            v-hasPermi="['rtkwms:in-request:update']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="openForm(scope.row.id)"
            >修改</el-button
          >
          <el-button
            v-hasPermi="['rtkwms:in-request:delete']"
            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"
    />
  </div>
</template>

<script>
import * as InRequestApi from "@/api/rtkwms/inrequestpda";
export default {
  name: "InRequest",
  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: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await InRequestApi.getInRequestPage(this.queryParams);
        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");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      // 跳转到指定页面，带ID参数用于修改，不带ID用于新增
      this.$router.push({
        path: "/inStorageManage/in-request/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;
      }
    },
  },
};
</script>
