<template>
	<page-meta :page-style="themeColor"></page-meta>
	<view class="balance">
		<!-- #ifdef MP -->
		<view class="custom-navbar" :style="{
				'padding-top': menuButtonBounding.top + 'px',
				'height': menuButtonBounding.height + 'px'
			}"
		>
			<view class="navbar-wrap">
				<text class="iconfont icon-back_light back" @click="$util.redirectTo('/pages/member/index')"></text>
				<view class="navbar-title">
					我的消费券
				</view>
			</view>
		</view>
		<!-- #endif -->
		
		<view class="head-wrap" :style="{ background: 'url(' + $util.img('public/uniapp/balance/balance_bg.png') + ') no-repeat right bottom/ auto 340rpx, linear-gradient(314deg, #FE7849 0%, #FF1959 100%)' }">
			<view class="balance price-font">{{ fenxiaoInfo && fenxiaoInfo.house_purchase != undefined ? fenxiaoInfo.house_purchase : '--' }}</view>
			<view class="title">账户购房券</view>
<!--			<view class="flex-box">-->
<!--				<view class="flex-item">-->
<!--					<view class="num price-font">{{  balanceInfo.balance_money|moneyFormat }}</view>-->
<!--					<view class="font-size-tag">现金消费券（元）</view>-->
<!--				</view>-->
<!--				<view class="flex-item">-->
<!--					<view class="num price-font">{{ balanceInfo.balance|moneyFormat }}</view>-->
<!--					<view class="font-size-tag">储值消费券（元）</view>-->
<!--				</view>-->
<!--			</view>-->
		</view>

		<view class="menu-wrap">
			<view class="menu-item" @click="toBalanceDetail">
				<view class="icon">
					<text class="iconfont icon-yuemingxi"></text>
				</view>
				<text class="title">购房券明细</text>
				<text class="iconfont icon-right"></text>
			</view>
<!--			<view class="menu-item" @click="toOrderList" v-if="addonIsExist.memberrecharge && memberrechargeConfig && memberrechargeConfig.is_use">-->
<!--				<view class="icon">-->
<!--					<text class="iconfont icon-chongzhijilu"></text>-->
<!--				</view>-->
<!--				<text class="title">充值记录</text>-->
<!--				<text class="iconfont icon-right"></text>-->
<!--			</view>-->
		</view>
		
		<view class="action">
<!--			<view @click="toList" class="recharge-withdraw " v-if="addonIsExist.memberrecharge && memberrechargeConfig && memberrechargeConfig.is_use">-->
<!--				{{ $lang('recharge') }}-->
<!--			</view>-->
			<view class="withdraw  " v-if="addonIsExist.memberwithdraw && withdrawConfig && withdrawConfig.is_use" @click="toWithdrawal">
				转赠
			</view>
		</view>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
export default {
	data() {
		return {
			balanceInfo: {
				balance: 0,
				balance_money: 0
			},
			withdrawConfig: null,
			memberrechargeConfig: null,
			menuButtonBounding: {}, // 小程序胶囊属性
      fenxiaoInfo: null
		};
	},
	async onShow() {
		this.getWithdrawConfig();
		this.getMemberrechargeConfig();
		if (!uni.getStorageSync('token')) {
			setTimeout(() => {
				this.$refs.login.open('/pages_tool/member/balance');
			});
		} else {
			this.getUserInfo();
      this.getFenxiaoInfo();
		}
	},
	onLoad() {
		// #ifdef MP
		this.menuButtonBounding = uni.getMenuButtonBoundingClientRect();
		// #endif
	},
	methods: {
		toWithdrawal() {
			this.$util.redirectTo('/pages_tool/member/integral/transfer');
		},
		toOrderList() {
			this.$util.redirectTo('/pages_tool/recharge/order_list');
		},
		toBalanceDetail() {
			this.$util.redirectTo('/pages_promotion/fenxiao/bill',{type: 'house_purchase'});
		},
		toList() {
			this.$util.redirectTo('/pages_tool/recharge/list');
		},
    getFenxiaoInfo(){
      this.$api.sendRequest({
        url: '/fenxiao/api/fenxiao/detail',
        success: res => {
          if (res.code >= 0) {
            this.fenxiaoInfo=res.data;
          }
        }
      });

    },
		//获取消费券信息
		getUserInfo() {
			this.$api.sendRequest({
				url: '/api/memberaccount/info',
				data: {
					account_type: 'balance,balance_money'
				},
				success: res => {
					if (res.data) {
						this.balanceInfo = res.data;
					} else {
						this.$util.showToast({
							title: res.message
						});
					}
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		/**
		 * 获取消费券提现配置
		 */
		getWithdrawConfig() {
			this.$api.sendRequest({
				url: '/api/memberwithdraw/config',
				success: res => {
					if (res.code >= 0 && res.data) {
						this.withdrawConfig = res.data;
					}
				}
			});
		},
		/**
		 * 获取充值提现配置
		 */
		getMemberrechargeConfig() {
			this.$api.sendRequest({
				url: '/memberrecharge/api/memberrecharge/config',
				success: res => {
					if (res.code >= 0 && res.data) {
						this.memberrechargeConfig = res.data;
					}
				}
			});
		}
	},
	onBackPress(options) {
		if (options.from === 'navigateBack') {
			return false;
		}
		this.$util.redirectTo('/pages/member/index', {}, 'reLaunch');
		return true;
	},
	watch: {
		storeToken: function(nVal, oVal) {
			if (nVal) {
				this.getUserInfo();
			}
		}
	},
	computed: {
		storeToken() {
			return this.$store.state.token;
		}
	}
};
</script>

<style lang="scss">
@import './public/css/balance.scss';
</style>
