<template>
  <div class="app-container">
    <el-card>
      <div>
      <el-input
              v-model="listQuery.search"
              placeholder="仓库名称/仓库编号"
              style="width: 300px"
              class="filter-item"
              @keyup.enter.native="handleFilter"
            />
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="handleFilter"
              >搜索</el-button
            >
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-refresh-left"
              @click="resetFilter"
              >重置</el-button
            >
    </div>
    </el-card>
    <el-card style="margin-top: 10px">
      <el-table
        v-loading="listLoading"
        :data="warehouseList.results"
        border
        fit
        stripe
        highlight-current-row
        max-height="600"
      >
        <el-table-column type="index" width="50" />
        <el-table-column label="物料名称">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
       
        <el-table-column label="物料批次">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>
         <el-table-column label="入库数量">
          <template slot-scope="scope">{{ scope.row.place }}</template>
        </el-table-column>
         <el-table-column label="物料有效期">
          <template slot-scope="scope">{{ scope.row.place }}</template>
        </el-table-column>
  <el-table-column label="入库时间">
          <template slot-scope="scope">{{ scope.row.create_time }}</template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="220px"
        >
          <template slot-scope="scope">
           
           
            <el-link
              v-if="checkPermission(['warehouse_delete'])"
              type="danger"
              @click="handleDelete(scope)"
              >删除</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="warehouseList.count > 0"
        :total="warehouseList.count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
    </el-card>
   
  </div>
</template>
<script>
import { getWarehouseList, deleteWarehouse } from "@/api/inm";
import checkPermission from "@/utils/permission";


import { genTree } from "@/utils";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
const defaultewarehouse = {
};
export default {
  components: { Pagination },
  data() {
    return {
      warehouse: defaultewarehouse,
     warehouseList: {
        count: 0,
      },
      options: [{
          value: 0,
          label: '运转正常'
        }, {
          value: 1,
          label: '停用'
        }, {
          value: 2,
          label: '报废'
        }],
      listQuery: {
        page: 1,
        page_size: 20,
      },
      keeperOptions:[],
      depOptions:[],
      listLoading: true,
      dialogVisible: false,
      dialogType: "new",
      rule1: {
        name: [{ required: true, message: "请输入", trigger: "blur" }],
          number: [{ required: true, message: "请输入", trigger: "blur" }],
            place: [{ required: true, message: "请输入", trigger: "blur" }],
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    checkPermission,
    //设备列表
    getList() {
      this.listLoading = true;
      getWarehouseList(this.listQuery).then((response) => {
        if (response.data) {
          this.warehouseList = response.data;
        }
        this.listLoading = false;
      });
    },
   
    handleMaterial(scope){
      alert(1)
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    resetFilter() {
      this.listQuery = {
        page: 1,
        page_size: 20,
      }
      this.getList();
    },
    
    handleDelete(scope) {
      this.$confirm("确认删除?", "警告", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(async () => {
          await deleteWarehouse(scope.row.id);
          this.getList();
          this.$message.success("成功");
        })
        .catch((err) => {
          console.error(err);
        });
    },
   
   
  },
};
</script>
