<template>
	<view>
		<view class="width90 mart20 fotct" v-if="user.hltCardNo.cardNo">
			<image :src="imagewxUrl+imgadres" mode="widthFix" class="cardImg"></image>
			<view class="cardlabel font18 fcorfff fontwig6" style="top: 50px;">卡号 : {{user.hltCardNo.cardNo}}</view>
			<view class="cardlabel font18 fcorfff fontwig6" style="top: 80px;">余额 : {{tongCardPrice}}￥</view>
		</view>
		<view class="btnw50 font20 fontlet" @click="selectCards()">查询明细</view>
		<view class="btnw50 font20 fontlet" @click="unionCardPay()">充值余额</view>
		<view class="btnw50 font20 fontlet" @click="delUserCard()" v-if="user.hltCardNo">解绑</view>
	</view>
</template>

<script>
	import {
		delUserCard,
		getHuiLianTongCardBalance
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				user: '',
				tongCardPrice: 0,
				imagewxUrl: app.globalData.imageWxImg,
				imgadres: 'cards.jpg',
			}
		},
		onShow() {
			this.user = app.globalData.userInfo;
			if (!this.user.isSetHltCard) {
				uni.showToast({
					icon: 'none',
					title: '当前账号还未绑定,前往绑定',
					duration: 2000,
					success() {
						setTimeout(() => {
							uni.navigateTo({
								url: '../bindingCard/bindingCard'
							})
						}, 1000)
					}
				});
				return;
			}
			this.getHuiLianTongCardBalance();
		},
		methods: {
			//跳转明细
			selectCards() {
				uni.navigateTo({
					url: '../unionCard/unionCard'
				})
			},
			//解除绑定我的卡号列表
			delUserCard() {
				let that = this;
				uni.showModal({
					content: '是否确定解除当前绑定卡号?',
					success: (res) => {
						if (res.confirm) {
							let params = {
								cardNo: that.user.hltCardNo.cardNo
							}
							delUserCard(params).then(res => {
								if (res.return_code == '000000') {
									uni.showToast({
										title: '解除成功',
										duration: 2000,
										icon: 'success',
										success() {
											setTimeout(() => {
												uni.navigateBack({})
											}, 1000)
										}
									})
								} else {
									uni.showToast({
										title: res.return_msg,
										duration: 2000,
										icon: 'none'
									})
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//查询详情
			getHuiLianTongCardBalance() {
				let params = {
					cardNo: this.user.hltCardNo.cardNo
				}
				getHuiLianTongCardBalance(params).then(res => {
					if (res.return_code == '000000') {
						this.tongCardPrice = res.return_data.balance;
					}

				});
			},
			//跳转充值
			unionCardPay() {
				uni.navigateTo({
					url: '../../../subPages/trade-union-recharge/trade-union-recharge?cardId=' + this.user
						.hltCardNo.cardNo
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.cardImg {
		position: relative;
		margin-top: 5px;
		margin-bottom: 5px;
	}

	.cardlabel {
		position: absolute;
		left: 13%;
	}
</style>
