<template>
  <div class="product-select" >
    <el-form   :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="商品名称" prop="productName">
        <el-input
          style="width:200px"
          v-model="queryParams.productName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table border v-loading="loading" :data="list">
      <el-table-column label="商品ID" align="center" prop="productId" />
      <el-table-column label="商品图片" align="center" width="100">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="scope.row.image" width="80">
            <img :src="scope.row.image" style="max-width: 80px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="productName" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="操作" align="center" width="100px" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleSelect(scope.row)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      style="padding-bottom:10px;"
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listStoreProduct } from "@/api/hisStore/storeProduct";
export default {
  name: "selectProduct",
  data() {
    return {
      loading: true,
      list:[],
      total: 0,
      queryParams: {
        productName:"",
        pageNum: 1,
        pageSize: 10,
        isPackage:0,
      }
    };
  },
  created() {
     this.getList();
  },
  methods: {
    getData(){
      this.getList();
    },
    handleSelect(row){
      this.$emit('selectProduct',row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList(){
      this.loading = true;
      listStoreProduct(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }
  }
};
</script>
<style scoped>
.product-select{
  padding-bottom: 15px;
}
</style>
