<template>
  <div class="app-container" ref="appPanel">
    <div ref="toolPanel">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:safetyStock:export']"
          >导出
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="resetQuery"
          >重置
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </div>
    <div class="search-container" ref="searchPanel">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="仓库编号" prop="storageId">
          <el-input
            v-model="queryParams.storageId"
            placeholder="请输入仓库编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="仓库名称" prop="storageName">
          <el-input
            v-model="queryParams.storageName"
            placeholder="请输入仓库名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料编号" prop="goodsId">
          <el-input
            v-model="queryParams.goodsId"
            placeholder="请输入物料编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="物料名称" prop="goodsName">
          <el-input
            v-model="queryParams.goodsName"
            placeholder="请输入物料名称
"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-form>
    </div>
    <div class="table-container">
      <div ref="mainTablePanel" :style="{height: mainTableDivHeight}">
        <el-table v-loading="loading" :data="safetyStockList" @selection-change="handleSelectionChange"
                  :row-class-name="rowClass"  ref="table" :stripe="false">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="仓库编号" align="center" prop="storageId"/>
          <el-table-column label="仓库名称" align="center" prop="storageName"/>
          <el-table-column label="物料编号" align="center" prop="goodsId"/>
          <el-table-column label="物料名称" align="center" prop="goodsName">
            <template slot-scope="scope">
              <span style="color: #1f77b4">{{ scope.row.goodsName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center" prop="shelvesNum">
            <template slot-scope="scope">
              <span style="color: #ff7f0e">{{ scope.row.shelvesNum }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库存上限" align="center" prop="warnUp">
            <template slot-scope="scope">
              <span style="color: #2ca02c">{{ scope.row.warnUp }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库存下限" align="center" prop="warnDown">
            <template slot-scope="scope">
              <span style="color: #d62728">{{ scope.row.warnDown }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
  import {safetyStockList} from "@/api/system/safetyStock";

  export default {
    name: "TSafetyStock",
    dicts: ['warehouse_type', 'inspect_status', 'stock_type'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 库存备份表格数据
        safetyStockList: [],
        // 弹出层标题
        title: "",
        mainTableHeight: "0px",
        mainTableDivHeight: "0px",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 100,
          storageId: null,
          storageName: null,
          goodsId: null,
          goodsName: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    mounted() {
      this.computedTableHeight();
    },
    watch: {
      'showSearch': function () {
        this.computedTableHeight();
      }
    },
    methods: {
      computedTableHeight() {
        this.$nextTick(() => {
          var totalHeight = this.$refs.appPanel.clientHeight;
          var toolHeight = this.$refs.toolPanel.clientHeight;
          var searchHeight = this.$refs.searchPanel.clientHeight;

          var tablePanelHeight = totalHeight - toolHeight - searchHeight - 14 - 5;

          var mainHeight = tablePanelHeight / 2;
          this.mainTableDivHeight = mainHeight + "px";
          this.mainTableHeight = (mainHeight - 25) + "px";
        })
      },
      /** 查询库存备份列表 */
      getList() {
        this.loading = true;
        safetyStockList(this.queryParams).then(response => {

          if (response.rows == null){

          }
          this.safetyStockList = response.rows;

          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/safetyStock/export', {
          ...this.queryParams
        }, `tSafetyStock_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style scoped>
  .app-container {
    height: calc(100vh - 84px);
  }
  ::v-deep .el-table .el-table__body tr.el-table__row:hover {
    background: white !important;
    color:black !important;
  }
</style>

<style >
  .highlight-row-red{
    background: red !important;
    color:white;
    /*color:red;*/
    /*font-weight: bold;*/
  }
  .highlight-row-yellow{
    background: yellow !important;
    color:black;
    /*font-weight: bold;*/
  }
  .highlight-row-normal{
    background: white !important;
    color:black;
  }
</style>
