<template>
	<van-popup
	v-model:show="showBottom"
	round
	position="bottom"
	@close="close"
	:style="{ height: '75%' }"
	>
		
		<view class="box">
			
			<view class="title">
				{{ title || '选择优惠劵' }}
			</view>
			
			<view class="technician-list">
				<van-list
				  v-model:loading="loading"
				  :finished="finished"
				  @load="onLoad"
				>
					<couponList :list="list" @select="select"/>
				</van-list>
			</view>
			
		</view>
	
	</van-popup>
</template>

<script>
	import couponList from "../couponList.vue"
	export default {
		components: {
			couponList
		},
		name:"selectCouponPopup",
		props : ['show', 'title'],
		data() {
			return {
				showBottom : false,
				i : 0,
				queryParams : {
					pageNo : 1,
					pageSize : 10,
					title : ''
				},
				list : [],
				loading : false,
				finished : false,
			}
		},
		created(){
			this.getCouponList();
		},
		methods : {
			onLoad(){
				this.queryParams.pageSize += 10
				this.getCouponList()
			},
			getCouponList(){
				this.$api('getCouponList' , {
					...this.queryParams,
					state : 0
				} , res => {
					if(res.code == 200){
						this.list = res.result.records;
						this.$emit('countCouponNum',this.list.length)
						if(this.queryParams.pageSize > res.result.total){
							this.finished = true
						}
					}
					this.loading = false
				})
			},
			select(e){
				this.$emit('selectCoupon', e)
			},
			close(){
				this.$emit('close')
			},
		},
		watch: {
			show: {
			   handler (newValue, oldValue) {
				   this.showBottom = newValue
				   this.getCouponList()
			   },
			   immediate: true
			}
		}
	}
</script>

<style lang="scss" scoped>
.box{
	width: 100%;
	height: 100%;
	background: linear-gradient(#57CAA0, #55B16E);
	box-sizing: border-box;
	padding: 40rpx;
	.title{
		font-size: 32rpx;
		text-align: center;
		color: #fff;
		margin-bottom: 40rpx;
	}
	.technician-list{
		overflow: auto;
		width: 100%;
		height: calc(100% - 45rpx);
	}
}
</style>