<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="物料批次" prop="materialLots">
        <el-input
          v-model="queryParams.materialLots"
          placeholder="请输入物料批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购订单" prop="purchaseOrder">
        <el-input
          v-model="queryParams.purchaseOrder"
          placeholder="请输入采购订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来料时间" prop="IncomingTimeStart">
        <el-date-picker
          v-model="queryParams.IncomingTimeStart"
          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-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">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
      border
    >
      <el-table-column label="物料批次" align="center" prop="materialLots" />
      <el-table-column label="采购订单" align="center" prop="purchaseOrder" />
      <el-table-column
        label="来料时间"
        align="center"
        prop="incomingTime"
        width="150"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.incomingTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="来料数量" align="center" prop="incomingQty">
        <template #default="{ row }">
          <span>{{ row.incomingQty.toString() }}</span>
        </template></el-table-column
      >
      <el-table-column label="来料金额" align="center" prop="incomingAmount">
        <template #default="{ row }">
          <span>{{ row.incomingAmount.toString() }}</span>
        </template></el-table-column
      >
      <el-table-column label="入库数量" align="center" prop="storageQty">
        <template #default="{ row }">
          <span>{{ row.storageQty.toString() }}</span>
        </template></el-table-column
      >
      <el-table-column label="入库金额" align="center" prop="storageAmount">
        <template #default="{ row }">
          <span>{{ row.storageAmount.toString() }}</span>
        </template></el-table-column
      >
      <el-table-column label="退货数量" align="center" prop="returnQty">
        <template #default="{ row }">
          <span>{{ row.returnQty.toString() }}</span>
        </template></el-table-column
      >
      <el-table-column label="退货金额" align="center" prop="returnAmount">
        <template #default="{ row }">
          <span>{{ row.returnAmount.toString() }}</span>
        </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 amountAccountApi from "@/api/wms/base/amountAccount.js";
export default {
  name: "amountAccountDetail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 受托加工退货明细列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        materialCode: null,
        supplierOrCustomerName: null,
        materialLots: null,
        purchaseOrder: null,
        IncomingTimeStart: [],
      },
    };
  },
  created() {
    const { materialCode, supplierOrCustomerName } = this.$route.query;
    this.queryParams.materialCode = materialCode;
    this.queryParams.supplierOrCustomerName = supplierOrCustomerName;
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await amountAccountApi.getAmountAccountDetailPage({
          ...this.queryParams,
          IncomingTimeStart: this.queryParams.IncomingTimeStart
            ? this.queryParams.IncomingTimeStart[0]
            : null,
          IncomingTimeEnd: this.queryParams.IncomingTimeStart
            ? this.queryParams.IncomingTimeStart[1]
            : null,
        });
        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();
    },
  },
};
</script>
