<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 prop="statusCode" label="状态">
            <el-select v-model="queryParams.statusCode" placeholder="请选择">
              <el-option label="正常" :value="0" />
              <el-option label="即将到期" :value="1" />
              <el-option label="已到期" :value="2" />
            </el-select>
          </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="商品ID" align="center" prop="dxSpuId" width="200" />
        <el-table-column label="商品名称" prop="spuName" width="200"> </el-table-column>
        <el-table-column label="生产日期" align="center" prop="produceDate" />
        <el-table-column label="状态" align="center" prop="statusCode">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.statusCode == 0">正常</el-tag>
            <el-tag type="warning" v-else-if="scope.row.statusCode == 1">即将到期</el-tag>
            <el-tag type="danger" v-else-if="scope.row.statusCode == 2">已到期</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="保质期" align="center">
          <template slot-scope="scope">
            {{ scope.row.shelfLife }}
            {{
              scope.row.shelfLifeUnit == 0
                ? "天"
                : scope.row.shelfLifeUnit == 1
                ? "月"
                : "年"
            }}
          </template>
        </el-table-column>
        <el-table-column label="剩余天数（天）" align="center" prop="remainingDays" />
        <el-table-column
          label="预警天数(天)"
          align="center"
          prop="warningDay"
          width="200"
        />
      </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 { queryShelfLife, storeManageRemove } from "@/api/manage/storage.js";
export default {
  data() {
    return {
      showSearch: true,
      queryParams: {
        key: "",
        pageNo: 1,
        pageSize: 10,
        storeTime: "",
        createTime: "",
        statusCode:""
      },
      dataList: [],
      loading: false,
      total: 0,
      ids: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    rksjchange(val) {
      this.queryParams.storeStartTime = val[0];
      this.queryParams.storeEndTime = val[1];
    },
    scsjchange(val) {
      this.queryParams.createStartTime = val[0];
      this.queryParams.createEndTime = val[1];
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.getList();
    },
    getList() {
      this.loading = true;
      queryShelfLife(this.queryParams).then((res) => {
        this.dialogVisible = true;
        this.dataList = res.data.records;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.queryParams.ids = this.ids.toString();
      this.download(
        "system/storeManage/exportShelfLife",
        {
          ...this.queryParams,
        },
        `保质期管理表_${new Date().getTime()}.xlsx`
      );
    },
    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>
