sendGift.vue 4.8 KB
<template>
	<view class="sendGiftAlert" v-if="showSendGift">
		<view class="sendGift">
			<view class="giftPad">
				<view class="giftList">
					<view class="giftItem" v-for="(item,index) in giftList" :key="index" @click="chooseGift(index)">
						<view class="giftImg">
							<view class="giftImgActive" :class="{active:giftIndex == index}">
								<image :src="item.image" mode=""></image>
							</view>
						</view>	
						<view class="giftName">{{item.price}}币</view>
					</view>
				</view>
				<view class="giftForm">
					<view class="inpItem">
						<view class="inpKey">余额</view>
						<view class="inpVal">{{wallet.landlord_money}}问野币</view>
					</view>
					<view class="inpItem">
						<view class="inpKey">数量</view>
						<view class="inpVal">
							<input type="number" v-model="inpNum" @keyup="inpNum = inpNum.length === 1 ? inpNum.replace(/[^1-9]/g, '') : inpNum.replace(/\D/g, '')" placeholder="请输入数量" placeholder-class="inpValPh"/>
						</view>
					</view>
					<view class="inpItem">
						<view class="inpKey">总计</view>
						<view class="inpVal">{{jbNum}}问野币</view>
					</view>
				</view>
				<view class="bottomBtn" @click="sendGift">
					送出礼物
				</view>
			</view>
			<view class="closeBtn" @click="closeSendGift">
				<image src="../static/image/cross@2x.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	// var apiUrl = 'http://landlord.t.brotop.cn/api'
	var apiUrl = 'http://app.zhaodizhu.cn/api'
	export default{
		data(){
			return{
				showSendGift:false,
				wallet:{},//我的钱包
				inpNum:'',//输入礼物数量
				giftList:[],
				giftIndex:-1
			}
		},
		props:{
			toUserId:{
				type:Number
			}
		},
		computed:{
			jbNum(){
				if(this.giftIndex != -1){
					return this.inpNum * this.giftList[this.giftIndex].price
				}
			}
		},
		mounted() {
			uni.request({
				url:this.apiUrl + '/gift/lis',
				method:'POST',
				success: (res) => {
					this.giftList = res.data.data
					this.showSendGift = true
				}
			})
			uni.request({
				url:apiUrl+'/wallet/index',
				method:'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded', 
					'token': uni.getStorageSync('token')
				},
				success: (res) => {
					this.wallet = res.data.data
				}
			})
		},
		methods:{
			//送出礼物
			sendGift(){
				if(this.giftIndex == -1){
					uni.showToast({
						title:'请选择礼物',
						icon:'none'
					})
					return
				}
				if(this.inpNum == '' || this.inpNum <= 0){
					uni.showToast({
						title:'请输入正确数量',
						icon:'none'
					})
					return
				}
				this.$request('/gift/give',{
					gift_id:this.giftList[this.giftIndex].id,
					user_id:this.toUserId,
					number:this.inpNum
				}).then((res)=>{
					if(res.code == 1){
						this.$emit('closeSendGift',this.inpNum+this.giftList[this.giftIndex].name)
						uni.showToast({
							title:'送出礼物成功'
						})
					}else{
						this.$emit('closeSendGift')
						uni.showModal({
							title:'提示',
							content:'问野币不足,是否充值',
							confirmText:'去充值',
							success: (res) => {
								if(res.confirm){
									this.$href('/pages/my/recharge')
								}
							}
						})
					}
				})
			},
			//选择礼物
			chooseGift(index){
				this.giftIndex = index
			},
			closeSendGift(){
				this.$emit('closeSendGift')
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 送礼物弹框 */
	.sendGiftAlert{
		position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,0.5);z-index: 21;
		.sendGift{
			width: 100%;
			position: absolute;
			height: 630rpx;
			bottom: 0;
			background: #fff;
			border-radius: 50rpx 50rpx 0 0;
			.giftPad{
				padding: 40rpx 32rpx 0 32rpx;
				.giftList{
					display: flex;
					justify-content: center;
					.giftItem{
						.giftImg{
							display: flex;
							justify-content: center;
							image{width: 120rpx;height: 120rpx;}
							.giftImgActive{
								width: 140rpx;
								display: flex;
								justify-content: center;
								border-radius: 10rpx;
							}
							.giftImgActive.active{
								background: #e0e3ef;
							}
						}
						.giftName{
							text-align: center;
							color: #e8c760;
							font-size: 28rpx;
						}
					}
				}
				.giftForm{
					padding: 32rpx;
					.inpItem{
						height: 88rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						.inpVal{
							input{text-align: end;}
							.inpValPh{
								text-align: end;
							}
						}
					}
				}
				.bottomBtn{
					height:88rpx;
					background: #35655f;
					text-align: center;
					line-height: 88rpx;
					font-size: 32rpx;
					color: #fff;
					border-radius: 50rpx;
				}
			}
			.closeBtn{
				position: absolute;
				width: 44rpx;
				height: 44rpx;
				right: 32rpx;
				top: 32rpx;
				image{width: 44rpx;height: 44rpx;}
			}
		}
	}
</style>