<template>
	<!-- 公众号可设置 -->
	<div>
        <!-- <el-button type="primary" @click="innerVisible = true">选择</el-button> -->
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item label="礼品编号：">
                <el-input v-model="form.giftno" placeholder="输入礼品编号"></el-input>
            </el-form-item>
            <el-form-item label="礼品名称：">
                <el-input v-model="form.giftname" placeholder="输入礼品名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getGiftWarehouse()">查询</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%;margin-bottom:10px">
            <el-table-column prop="GiftNo" label="礼品编号"></el-table-column>
            <el-table-column prop="GiftName" label="礼品名称"></el-table-column>
            <el-table-column prop="GiftPrice" label="价值"></el-table-column>
            <el-table-column prop="GiftCount" label="剩余"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="selectPrize(scope.row)" type="text" size="small">选择</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="text-r">
            <el-pagination
            background
            layout="prev, pager, next"
            :total="total" 
			@current-change="getGiftWarehouse" 
            :small="false">
            </el-pagination>
        </div>
	</div>
</template>

<script>
import apiHelper from "@/assets/js/apiHelper.js";
export default {
		name: "GiftList",
		props: ["GiftType"],
		data() {
            return {
                innerVisible:false,
                form: {
                    giftname:"",//礼品名称
                    giftno:"",//礼品编号
                },
                tableData: [],
                gifttype:"3",//礼品类型
                total:0
            };
		},
		watch: {
            "GiftType":function(n){
                this.gifttype = n;
                this.getGiftWarehouse(1);
            }
        },
		created () {

		},
		mounted () {
            this.getGiftWarehouse(1);
		},
		methods: {
            // 获取礼品列表
            getGiftWarehouse(page=1,size=5){
                console.log("hah");
                let that = this;
                let enterpriseno = this.sup8.urlparams.eid;
                apiHelper.getGiftWarehouse(page,size,enterpriseno,this.gifttype,this.form.giftno,this.form.giftname, function(res) {
                    if (res.flag) {
                        that.tableData = res.data.Rows;
                        that.total = res.data.Total;
                    } else {
                        that.tableData = [];
                        that.total = 0;
                    }
                });
            },
            // 选择奖品
            selectPrize(row){
                this.$emit("prizeAdd",row);
            }
	    }
};

</script>
<style scoped>
.text-r{text-align: right;}
.dis-ib{display: inline-block;}
.mb-10{margin-bottom: 10px;}
.mb-20{margin-bottom: 20px;}
</style>