<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="100px"
        >
          <el-form-item prop="key">
            <el-input
              v-model="queryParams.key"
              style="width: 300px"
              placeholder="出库单号,关联入库订单编号,关联入库订单商品名称"
            ></el-input>
          </el-form-item>
          <el-form-item prop="outboundType" label="出库类型">
            <el-select v-model="queryParams.outboundType" placeholder="请选择">
              <el-option label="全部" value="" />
              <el-option label="销售出库" value="1" />
              <el-option label="平台出库" value="2" />
              <el-option label="下捡出库" value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="出库时间" prop="outboundTime">
            <el-date-picker
              v-model="queryParams.outboundTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="cksjchange"
              style="width: 200px"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="操作时间" prop="createTime">
            <el-date-picker
              v-model="queryParams.createTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="czsjchange"
              style="width: 200px"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="getList"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-button icon="el-icon-refresh" size="mini" @click="handleExport"
            >批量导出</el-button
          >
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addStorage"
            >新增</el-button
          >
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>
      </el-col>
      <el-table
        v-loading="loading"
        :data="dataList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="出库单号" align="center" prop="outboundOdd" />
        <el-table-column label="出库时间" align="center" prop="outboundDate" />
        <el-table-column label="出库类型" align="center" prop="outboundType">
          <template slot-scope="scope">
            {{
              scope.row.outboundType == 0
                ? "下捡出库"
                : scope.row.outboundType == 1
                ? "销售出库"
                : scope.row.outboundType == 2
                ? "平台出库"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="关联入库订单编号"
          align="center"
          prop="associationStoreNum"
        >
          <template slot-scope="scope">
            <div
              v-for="(item, index) in scope.row.associationStoreNum
                ? scope.row.associationStoreNum.split(',')
                : []"
              :key="index"
            >
              {{ item }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="关联入库订单名称"
          align="center"
          prop="associationStoreName"
        >
          <template slot-scope="scope">
            <div
              v-for="(item, index) in scope.row.associationStoreName
                ? scope.row.associationStoreName.split(',')
                : []"
              :key="index"
            >
              {{ item }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="出库商品ID" align="center" prop="outboundGoodsId" />
        <el-table-column label="出库商品名称" align="center" prop="outboundGoodsName" />
        <el-table-column
          label="出库总数量"
          align="center"
          prop="outboundTotalNums"
          width="200"
        />
        <el-table-column
          label="合计金额（￥）"
          align="center"
          prop="outboundTotalPrice"
        />
        <el-table-column label="出库员" align="center" prop="outboundUser" />
        <el-table-column label="操作时间" align="center" prop="createTime" />
        <el-table-column
          label="操作"
          align="center"
          width="160"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleDetail(scope.row)"
              v-hasPermi="['storage:detail']"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleEdit(scope.row)"
              v-hasPermi="['storage:edit']"
              >编辑</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"
      />
    </el-row>
  </div>
</template>

<script>
import { outboundManageQueryPage, storeManageRemove } from "@/api/manage/storage.js";
export default {
  data() {
    return {
      showSearch: true,
      queryParams: {
        key: "",
        pageNo: 1,
        pageSize: 10,
        storeTime: "",
        createTime: "",
      },
      dataList: [],
      loading: false,
      total: 0,
      ids: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    czsjchange(val) {
      this.queryParams.createStartTime = val[0];
      this.queryParams.createEndTime = val[1];
    },
    cksjchange(val) {
      this.queryParams.outboundStartTime = val[0];
      this.queryParams.outboundEndTime = val[1];
    },
    resetQuery() {
      this.queryParams.createStartTime = "";
      this.queryParams.createEndTime = "";
      this.queryParams.outboundStartTime = "";
      this.queryParams.outboundEndTime = "";
      this.resetForm("queryForm");
      this.getList();
    },
    getList() {
      this.loading = true;
      outboundManageQueryPage(this.queryParams).then((res) => {
        this.dialogVisible = true;
        this.dataList = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },
    handleExport() {
      this.queryParams.ids = this.ids.toString();
      this.download(
        "system/outboundManage/export",
        {
          ...this.queryParams,
        },
        `出库信息表_${new Date().getTime()}.xlsx`
      );
    },
    handleDetail(record) {
      this.$router.push({ path: "/storage/outbound/look", query: record });
    },
    handleEdit(record) {
      this.$router.push({ path: "/storage/outbound/edit", query: record });
    },
    addStorage() {
      this.$router.push({ path: "/storage/outbound/add" });
    },
  },
};
</script>

<style></style>
