<template>
  <div >
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="商品名称" prop="goodsName">
        <el-input
          style="width:200px"
          v-model="queryParams.goodsName"
          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="商品图片" align="center" width="100">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="scope.row.imgUrl" width="80">
            <img :src="scope.row.imgUrl" style="max-width: 80px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="商品分类" align="center" prop="goodType">
        <template slot-scope="scope">
          <dict-tag :options="typeOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="goodsName" />
      <el-table-column label="库存" align="center" prop="stock" />
      <el-table-column label="所需积分" align="center" prop="integral" />
      <el-table-column label="需支付金额" align="center" prop="cash" />
      <el-table-column label="商品编号" align="center" prop="barCode" />

      <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 { listIntegralGoods } from "@/api/hisStore/integralGoods";
export default {
  name: "selectProduct",
  data() {
    return {
      loading: true,
      list:[],
      typeOptions:[],
      total: 0,
      queryParams: {
        goodsName:"",
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  created() {
     this.getList();

    this.getDicts("sys_integral_goods_type").then(response => {
      this.typeOptions = response.data;
    });

  },

  methods: {
    handleSelect(row){
      this.$emit('selectProduct',row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList(){
      this.loading = true;
      this.queryParams.status=1
      listIntegralGoods(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }
  }
};
</script>
<style scoped>

</style>
