<template>
	<div>

		<div class="tab-header webtop">
			<!-- 标题 -->
			<div>提货卡管理</div>
			<!-- start 添加修改按钮 -->
			<div>
				<el-button type="primary" size="small" @click="saveOrUpdate">发行</el-button>
				<el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
			</div>
			<!-- end 添加修改按钮 -->
			<!-- end 详情按钮 -->
		</div>

		<div class="listconadd">

			<el-card class="box-card">
				<div class="item">
					<span class="item_text">券卡数量：</span>
					<el-input v-model="formobj.num" placeholder="" class="item_input"
						oninput="value=value.replace(/^(0+)|[^\d]+/g,'')" clearable />
				</div>
				<div class="item">
					<span class="item_text">选择礼包：</span>
					<el-select v-model="formobj.bagSid" filterable class="item_input" clearable placeholder="请选择"
						style="width:100%" @change="giftPackSelect">
						<el-option v-for="item in giftPackList" :key="item.sid" :label="item.name" :value="item.sid">
						</el-option>
					</el-select>
				</div>


			</el-card>

		</div>

	</div>
</template>

<script>
	import req from '@/api/marketingCard/marketingCard.js'

	export default {
		data() {
			return {
				formobj: {
					num: '',
					 bagSid: ""
				},
				giftPackList: []
			}
		},
		created() {
			this.giftBagList()
		},
		methods: {
			giftBagList(){
				req.giftBagList()
					.then(resp => {
						console.log('>>>>>>>>>giftBagList', resp.data)
						this.giftPackList = resp.data
					})
					.catch(() => {})
			},
			giftPackSelect(val) {
				console.log('>>>>>>>>>giftPackSelect', val)
				this.formobj.bagSid = val
			},
			saveOrUpdate() {
				console.log('>>>>>>>>>saveOrUpdate', this.formobj)
				req.generateCard(this.formobj)
					.then(resp => {
						if (resp.success) {
							this.$message({
								showClose: true,
								type: 'success',
								message: resp.msg
							})
							this.handleReturn('true')
						} else {
							// 根据resp.code进行异常情况处理
						}
					})
					.catch(() => {})
			},
			handleReturn(isreload) {
				if (isreload === 'true') this.$emit('reloadlist')
				this.imgList = []
				this.formobj = {
					num: '',
					 bagSid: ""
				}
				this.$emit('doback')
			},

		}
	}
</script>
<style lang="scss">
	.box-card {
		margin-left: 60px;
		margin-right: 60px;
		min-width: 70%;
		margin-top: 20px;

		.item {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 15px;
			height: 40px;
			line-height: 40px;

			.item_text {
				flex: 0.8;
				font-size: 18px;
				text-align: right;
			}

			.item_input {
				flex: 4;
				font-size: 16px;
				margin-left: 10px;
				margin-right: 80px;
			}

			.item_left_input {
				width: 20%;
			}

			.item_left_text {
				height: 30px;
				margin-left: 20px;
				line-height: 30px;
				color: #018AD2;
				padding: 0px 15px;
				border: 1.5px solid #018AD2;
				border-radius: 5px;

			}

			.item_right {
				flex: 1;
				justify-items: center;

				.item_right_list_text {
					font-size: 16px;
				}

				.item_right_list_delect {
					color: #5E94FF;
					margin-left: 20px;
					font-size: 16px;
					text-decoration: underline;
				}
			}

		}

	}
</style>