<template>
  <el-dialog title="查看流水" :visible.sync="visible" @close="close">
    <div>
      <el-form :model="search" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" :size="ELsize">
        <el-form-item label="库存流水">
          <el-select v-model="search.stockFlowWaterType" placeholder="请选择库存流水" clearable size="small"
            style="width: 240px">
            <el-option v-for="item in stockFlowWaterTypeList" :label="item.label" :value="item.value"
              :key="item.value" />
          </el-select>
        </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-table :data="dataList" v-loading="loading">
        <el-table-column type="index" width="55" label="序号" align="center" :border="TableBorder" :size="ELTableSize">
          <template slot-scope="{$index}">
            {{ $getTableIndex(queryParams, $index + 1) }}
          </template>
        </el-table-column>
        <el-table-column property="skuSetName" label="规格名称" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column property="originalStock" label="原库存" align="center"></el-table-column>
        <el-table-column property="resultStock" label="结果库存" align="center"></el-table-column>
        <el-table-column property="stockFlowWaterType" label="库存流水" align="center">
          <template slot-scope="{ row }">
            <span>{{ stockFlowWaterTypeChange(row.stockFlowWaterType) }}</span>
          </template>
        </el-table-column>
        <el-table-column property="createTime" label="创建时间" align="center"></el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </el-dialog>
</template>
<script>
import getListApi from "@/mixins/getListApi";
import { productStockFlowWaterPage } from "@/api/productInventory";
export default {
  mixins: [getListApi],
  data() {
    return {
      visible: false,
      listURL: productStockFlowWaterPage,
      exportObj: {
        url: "/shop/productSkuSetStock/export", // 导出接口地址
        name: "商品库存", // 导出文件名前缀
      },
      stockFlowWaterTypeList: [
        { label: "初始化", value: 0 },
        { label: "编辑商品规库存更新", value: 1 },
        { label: "下单扣库存", value: 2 },
        { label: "订单取消退库存", value: 3 },
        { label: "订单退款回退库存", value: 4 },
        { label: "订单退货退款回退库存", value: 5 },
      ],
    };
  },
  methods: {
    open(id) {
      this.queryParams.skuSetStockId = id;
      this.resetQuery();
      this.visible = true;
    },
    close() {
      this.dataList = [];
      this.visible = false;
    },
    stockFlowWaterTypeChange(e) {
      if (e != null) {
        const obj =
          this.stockFlowWaterTypeList.find((item) => item.value == e) || {};
        return obj.label;
      } else {
        return "--";
      }
    },
  },
};
</script>
<style scoped lang="scss"></style>
