<template>
    <div style="margin-bottom: 20px">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="配件名称" prop="title">
          <el-input
            v-model="queryParams.title"
            placeholder="请输入配件名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="配件编号" prop="planNo">
          <el-input
            v-model="queryParams.planNo"
            placeholder="请输入配件编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="storeList">
        <el-table-column label="配件名称" align="center" prop="title" />
        <el-table-column label="配件编号" align="center" prop="planNo" />
        <el-table-column label="规格参数" align="center" prop="specs" />
        <el-table-column label="库存数量" align="center" prop="total" />
        <el-table-column label="产品用量" align="center" prop="useNum" />
        <el-table-column label="供货商" align="center" prop="supplier">
          <template slot-scope="scope">
            <span v-if="scope.row.supplier">{{ scope.row.supplier }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" prop="username">
          <template slot-scope="scope">
            <span v-if="scope.row.username">{{ scope.row.username }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="联系电话" align="center" prop="tel" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.tel">{{ scope.row.tel }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip/>
        <el-table-column label="创建人" align="center" prop="createBy" show-overflow-tooltip/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleDetail(scope.row)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 详情 -->
      <DetailInfo ref="detail"/>

    </div>
</template>

<script>
  import { getStoreInfoByDeviceId } from "@/api/track/store";
  import DetailInfo from "../../store/components/DetailInfo";
  export default {
    name: "store-info",
    props:{
      deviceId:{
        type: Number
      }
    },
    components:{
      DetailInfo
    },
    data(){
        return{
          // 总条数
          total: 0,
          // 遮罩层
          loading: true,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            title: null,
            planNo: null,
          },
          storeList: []
        }
    },
    created(){
      this.queryParams.deviceId = this.deviceId;
      this.getList();
    },
    methods:{
      /** 查询配件列表 */
      getList() {
        this.loading = true;
        getStoreInfoByDeviceId(this.queryParams).then(response => {
          this.storeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      //详情
      handleDetail(row){
        this.$refs.detail.getDetailInfo(row.id);
      },
    }
  }
</script>

<style scoped>

</style>
