<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:stock: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" border size="mini" :height="mainTableHeight" :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="storageAreaId">
          <el-input
            v-model="queryParams.storageAreaId"
            placeholder="请输入库区编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="库位编号" prop="locationId">
          <el-input
            v-model="queryParams.locationId"
            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-item label="托盘号" prop="batchNo">
          <el-input
            v-model="queryParams.ctl"
            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="tMiStockList" @selection-change="handleSelectionChange">
          <el-table-column label="仓库编号" align="center" prop="storageId"/>
          <el-table-column label="库区编号" align="center" prop="storageAreaId"/>
          <el-table-column label="库位编号" align="center" prop="locationId"/>
          <el-table-column label="物料编号" align="center" prop="goodsId"/>
          <el-table-column label="数量" align="center" prop="shelvesNum"/>
          <el-table-column label="生产批号" align="center" prop="batchNo"/>
          <el-table-column label="生产日期" align="center" prop="productionDate" width="180">
            <template slot-scope="scope">
              <span style="color: green">{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="检查时间" align="center" prop="checkDate" width="180">
            <template slot-scope="scope">
              <span style="color :blue">{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="过期时间" align="center" prop="dueDate" width="180">
            <template slot-scope="scope">
              <span style="color:salmon">{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="入库时间" align="center" prop="wareDate"/>
          <el-table-column label="物料名称" align="center" prop="goodsName"/>
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.stock_type" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <el-table-column label="过期天数" align="center" prop="mark">
            <template slot-scope="scope">
              <span style="color: red;">{{ scope.row.mark}}天</span>
            </template>
          </el-table-column>
          <el-table-column label="保质期" align="center" prop="period">
          <template slot-scope="scope">
            <span style="color: #76a236;">{{ scope.row.period}}{{scope.row.periodUnit}}</span>
          </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="operateDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.operateDate, '{y}-{m}-{d}') }}</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 {listOverInsuredTMiStock} from "@/api/system/overInsured";

export default {
  name: "TMiStock",
  dicts: ['warehouse_type', 'inspect_status', 'stock_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存备份表格数据
      tMiStockList: [],
      // 弹出层标题
      title: "",
      mainTableHeight: "0px",
      mainTableDivHeight: "0px",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        storageId: null,
        storageAreaId: null,
        locationId: null,
        goodsId: null,
        storageMode: null,
        doctNumber: null,
        noticeId: null,
        goodsName: null,
        status: null,
        ctl: null,
        factoryId: 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;
      listOverInsuredTMiStock(this.queryParams).then(response => {
        this.tMiStockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storageId: null,
        storageAreaId: null,
        locationId: null,
        goodsId: null,
        shelvesNum: null,
        remark: null,
        version: null,
        storageMode: null,
        providerId: null,
        productionDate: null,
        wareDate: null,
        doctNumber: null,
        goodsVolume: null,
        occupyNum: null,
        noticeId: null,
        oriBill: null,
        ctl: null,
        barcode: null,
        wgh: null,
        high: null,
        goodsName: null,
        status: null,
        customerId: null,
        batchNo: null,
        dueDate: null,
        checkDate: null,
        standard: null,
        flag: null,
        mark: null,
        orderNum: null,
        problem: null,
        price: null,
        packingNum: null,
        boxType: null,
        scaleUnit: null,
        goodsSku: null,
        factoryId: null,
        salesOrderNo: null,
        salesOrderNumber: null,
        supplier: null,
        onOrder: null,
        recordPerson: null,
        lotId: null,
        decid: null,
        unit: null,
        specification: null,
        goodsAge: null,
        arraMount: null,
        recoil: null,
        operatorId: null,
        operateDate: null,
        purchaseId: null,
        applicant: null,
        respDept: null,
        planDate: null,
        planTime: null,
        needCycle: null,
        needType: null,
        goodsTypeId: null,
        brand: null,
        totalMoney: null,
        expiryDate: null,
        providerName: null,
        receiver: null,
        needDept: null,
        purchaseDept: null,
        produclotId: null,
        receiverDept: null,
        receivingArea: null,
        packageId: null,
        useType: null,
        telephone: null,
        totalVolume: null,
        totalRoughWeight: null,
        totalNetWeigh: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        defaultStorageAreaId: null,
        qualityInspecStatus: null,
        periodUnit: null,
        period: null,
        reportTime: null,
        consignment: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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/stock/export', {
        ...this.queryParams
      }, `tMiStockbak_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

