<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: 400px"
              placeholder="入库单号,入库订单名称,入库商品ID,入库商品名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="入库时间" prop="storeTime">
            <el-date-picker
              v-model="queryParams.storeTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="rksjchange"
            >
            </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="scsjchange"
            >
            </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="storeOdd" width="200" />
        <el-table-column label="入库订单名称" align="center" prop="storeOddName" />
        <el-table-column label="入库时间" align="center" prop="storeDate" width="200" />
        <el-table-column label="入库商品信息" align="storeGoods" width="200">
          <template slot-scope="scope">
            <div
              v-for="(item, index) in scope.row.storeGoods
                ? scope.row.storeGoods.split(',')
                : []"
              :key="index"
            >
              {{ item }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="入库单位" align="center" prop="storeUnit" />
        <el-table-column label="入库数量" align="center" prop="storeNum" />
        <el-table-column label="合计金额(￥)" align="center" prop="totalPrice" />
        <el-table-column label="已出库数量(斤)" align="center" prop="outBoundNum" />
        <el-table-column label="生产日期" align="center" prop="produceDate" />
        <el-table-column label="保质期" align="center" prop="shelfLife">
          <template slot-scope="scope">
            {{ scope.row.shelfLife }}
            {{
              scope.row.shelfLifeUnit == 0
                ? "天"
                : scope.row.shelfLifeUnit == 1
                ? "月"
                : scope.row.shelfLifeUnit == 2
                ? "年"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="供应商名称"
          align="center"
          prop="supplierName"
          width="150"
        />
        <el-table-column
          label="供应商电话"
          align="center"
          prop="supplierPhone"
          width="150"
        />
        <el-table-column label="操作时间" align="center" prop="createTime" width="200" />
        <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
            >
            <!-- <el-button
              size="mini"
              type="text"
              style="color: red"
              @click="handleRemove(scope.row)"
              v-hasPermi="['storage:remove']"
              >删除</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 { queryPage, storeManageRemove, storeManageExport } 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: {
    handleExport() {
      this.queryParams.ids = this.ids.toString();
      this.download(
        "system/storeManage/export",
        {
          ...this.queryParams,
        },
        `入库信息表_${new Date().getTime()}.xlsx`
      );
    },

    rksjchange(val) {
      this.queryParams.storeStartTime = val[0];
      this.queryParams.storeEndTime = val[1];
    },
    scsjchange(val) {
      this.queryParams.createStartTime = val[0];
      this.queryParams.createEndTime = val[1];
    },
    resetQuery() {
      this.queryParams.storeStartTime = "";
      this.queryParams.storeEndTime = "";
      this.queryParams.createStartTime = "";
      this.queryParams.createEndTime = "";
      this.resetForm("queryForm");
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },

    getList() {
      this.loading = true;
      queryPage(this.queryParams).then((res) => {
        this.dialogVisible = true;
        this.dataList = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    handleRemove(record) {
      this.$confirm("是否确认删除该记录,删除后无法恢复？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          storeManageRemove(record.id).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功！");
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    handleDetail(record) {
      this.$router.push({ path: "/storage/storage/look", query: record });
    },
    handleEdit(record) {
      this.$router.push({ path: "/storage/storage/edit", query: record });
    },
    addStorage() {
      this.$router.push({ path: "/storage/storage/add" });
    },
  },
};
</script>

<style></style>
