<template>
	<view>
		<form :style="colorStyle">
			<view class="payment-top acea-row row-column row-center-wrapper">
				<span class="name">我的消费分</span>
				<view class="pic">
					<span class="pic-font">{{userinfo.integral || 0.00}}</span>
				</view>
			</view>
			<view class="payment">
				<view class="tip picList">
					<view class='to_uid acea-row row-between'>
						<view class="title">转账数量</view>
						<input class="uidbox" v-model="number"  placeholder="0.00"
							type='number' placeholder-class='placeholderUid'  name="number"></input>
					</view>
					<view class='to_uid acea-row row-between'>
						<view class="title">用户UID</view>
						<input class="uidbox" placeholder-class='placeholderUid' placeholder="请输入转入的用户uid" v-model="uid" type='number' name="uid"></input>
						<!-- #ifndef H5 -->
						<image @click="qr" class="tipimg" src="../../../static/images/qrSq.png" mode=""></image>
						<!-- #endif -->
					</view>
				</view>

				<view class="tips-title" v-if="userinfo.shop_integral_trade_commission">
					<view style="font-weight: bold; font-size: 26rpx;">提示：</view>
					<view style="margin-top: 10rpx;">当前手续费为 <text
							class='font-color'>{{userinfo.shop_integral_trade_commission*number/100}}</text></view>
				</view>
				<button class='but bg-color' @click="submitSub"> 立即转换</button>
			</view>
		</form>
		<home v-if="navigation"></home>
		<!-- <view v-show="false" v-html="formContent"></view> -->
		<!-- #ifdef MP -->
		<!-- <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize> -->
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		getUserInfo,
		integralTrade
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import home from '@/components/home';
	import colors from "@/mixins/color";
	export default {
		components: {
			home,
		},
		mixins: [colors],
		data() {
			let that = this;
			return {
				number: '',
				uid: '', //转入用户UID
				userinfo: {},
				// #ifdef H5
				isWeixin: this.$wechat.isWeixin(),
				// #endif
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getUserInfo();
					}
				},
				deep: true
			}
		},
		onLoad(options) {
			if (this.isLogin) {
				this.getUserInfo();
			} else {
				toLogin();
			}
		},
		onShow() {},
		methods: {
			onLunch() {
				this.getUserInfo();
			},
			inputNum: function(e) {
				let val = e.detail.value;
				let dot = val.indexOf('.');
				if (dot > -1) {
					this.moneyMaxLeng = dot + 3;
				} else {
					this.moneyMaxLeng = 8
				}
			},
			onLoadFun: function() {
				this.getUserInfo();
			},
			// #ifndef H5
			qr() {
				const that = this;
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.uid = res.result;
					}
				});
			},
			// #endif
			/**
			 * 获取用户信息
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					that.$set(that, 'userinfo', res.data);

				})
			},
			submitSub: function(e) {
				let that = this
				let value = that.number;
				if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
					return that.$util.Tips({
						title: '请输入数量'
					});
				}
				// 转入余额
				uni.showModal({
					title: '消费分转账',
					content: '佣金转出后无法撤回，确认是否转出消费分',
					success(res) {
						if (res.confirm) {
							integralTrade({
								to_uid: that.uid,
								num: parseFloat(value),
							}).then(res => {
								// that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
								return that.$util.Tips({
									title: '转入成功',
									icon: 'success'
								}, {
									tab: 5,
									url: '/pages/user/index'
								});
							}).catch(err => {
								return that.$util.Tips({
									title: err
								})
							});

						} else if (res.cancel) {
							return that.$util.Tips({
								title: '已取消'
							});
						}
					},
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}

	.bgcolor {
		background-color: var(--view-theme)
	}

	.payment {
		position: relative;
		width: 100%;
		background-color: #fff;
		border-radius: 10rpx;
		padding-top: 25rpx;
		border-top-right-radius: 39rpx;
		border-top-left-radius: 39rpx;
	}

	.payment .nav {
		height: 75rpx;
		line-height: 75rpx;
		padding: 0 100rpx;
	}

	.payment .nav .item {
		font-size: 30rpx;
		color: #333;
	}

	.payment .nav .item.on {
		font-weight: bold;
		border-bottom: 4rpx solid var(--view-theme);
	}

	.payment .input {
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom: 1px dashed #dddddd;
		margin: 60rpx auto 0 auto;
		padding-bottom: 20rpx;
		font-size: 56rpx;
		color: #333333;
		flex-wrap: nowrap;

	}

	.payment .input text {
		padding-left: 106rpx;
	}

	.payment .input input {
		padding-right: 106rpx;
		width: 300rpx;
		height: 94rpx;
		text-align: center;
		font-size: 70rpx;
	}

	.payment .placeholder {
		color: #d0d0d0;
		height: 100%;
		line-height: 94rpx;
	}

	.payment .tip {
		font-size: 26rpx;
		color: #888888;
		padding: 0 30rpx;
		margin-top: 25rpx;
	}

	.payment .but {
		color: #fff;
		font-size: 30rpx;
		height: 100rpx;
		border-radius: 10rpx;
		margin: 46rpx 50rpx 0 50rpx;
		line-height: 100rpx;
		background-image: linear-gradient(45deg, #ffcdd3, #ffb0b3);
	}

	.payment-top {
		width: 100%;
		height: 350rpx;
		// background-color: var(--view-theme);
		background-image: linear-gradient(45deg, rgb(255, 242, 232) 10%, #fff0f2 35%, rgb(255, 234, 247) 45%, #ffcdd3 75%, #ffb0b3);

		.name {
			font-size: 26rpx;
			color: rgba(255, 255, 255, 0.8);
			margin-top: -38rpx;
			margin-bottom: 30rpx;
		}

		.pic {
			font-size: 32rpx;
			color: #fff;
		}

		.pic-font {
			font-size: 78rpx;
			color: #fff;
		}
	}

	.picList {
		margin: 30rpx 0;
	}

	.tips-box {
		.tips {
			font-size: 28rpx;
			color: #333333;
			font-weight: 800;
			margin-bottom: 14rpx;
			margin-top: 20rpx;
		}

		.tips-samll {
			font-size: 24rpx;
			color: #333333;
			margin-bottom: 14rpx;
		}

		.tip-box {
			margin-top: 30rpx;
		}
	}

	.tips-title {
		padding-left: 30rpx;
		margin-top: 20rpx;
		font-size: 24rpx;
		color: #333;
	}

	.to_uid {
		padding: 20rpx;
		width: 100%;
		line-height: 1;
		font-size: 28rpx;
		align-items: center;

		border-bottom: 1px solid #dddddd;

		.title {
			font-weight: bold;
		}

		.uidbox {
			flex-grow: 1;
			text-align: right;
		}

		.placeholderUid {
			text-align: right;
		}
	}

	.tipimg {
		width: 50rpx;
		height: 50rpx;
		margin-left: 10rpx;
	}
</style>