<template>
    <view class="page">
        <view class="topbg">
            <view class="topinfo">
				
                <navigator v-if="commission_withdraw_mode==0" :url="'../cash/balance?user_total_weath=' + (CashData.user_total_weath) + '&user_money=' + (CashData.user_money) + '&commission_amount=' + (CashData.commission_amount) + '&user_commission_now=' + (CashData.user_commission_now) + '&user_commission_buy=' + (CashData.user_commission_buy)">
                    <label>{{('￥')}}</label><label style="font-size:56px">{{CashData.user_total_weath}}</label>
                </navigator>
                <navigator v-else url="/member/cash/commissionwithdraw">
                    <label>{{('￥')}}</label><label style="font-size:56px">{{CashData.user_total_weath}}</label>
                </navigator>
				<block v-if="(isMemDist)">
                <view class="portionMoney" v-if="isShowMoney"><label>{{__('余额')}} {{__('￥')}}{{CashData.user_money}}</label><label>{{__('佣金')}} {{__('￥')}}{{CashData.user_commission_now}}</label></view>
                <!-- <navigator url="/member/cash/predepositapply?price=(CashData.user_commission_buy)" class="m-t-text">申请提现</navigator> -->
				</block>
            </view>
            <view class="menu_list"  v-if="(Config.PLANTFORM_FX_ENABLE)">
                <navigator url="/member/fans/profitlist?tp=1" class="menu_item">
                    <view>{{CashData.month_commission_buy}}</view>
                    <text>{{__('本月预估收益(￥)')}}</text>
                </navigator>
                <navigator url="/member/fans/list" class="menu_item">
                    <view>{{CashData.month_fans_num}}</view>
                    <text>{{__('本月新增粉丝(个)')}}</text>
                </navigator>
            </view>
        </view>
        <view class="m-cells">
            <navigator url="/member/fans/list" class="m-cell m-cell-access" v-if="(isMemDist)">
                <view class="m-cell-bd">
                    <label>{{__('我的粉丝')}}</label>
                </view>
                <view class="m-cell-ft">{{CashData.total_fans_num}}</view>
            </navigator>
            <navigator url="/member/fans/profitlist" class="m-cell m-cell-access" v-if="(isMemDist)">
                <view class="m-cell-bd">
                    <label>{{__('分销总收益')}}</label>
                </view>
                <view class="m-cell-ft">{{CashData.commission_amount}}</view>
            </navigator>
            <navigator url="/member/cash/predepositlist" class="m-cell m-cell-access" v-if="(isMemDist||isECashCard)">
                <view class="m-cell-bd">
                    <label>{{__('资金明细')}}</label>
                </view>
                <view class="m-cell-ft"></view>
            </navigator>
            <navigator url="/member/cash/predepositapplylist" class="m-cell m-cell-access" v-if="(isMemDist||isECashCard)">
                <view class="m-cell-bd">
                    <label>{{__('提现记录')}}</label>
                </view>
                <view class="m-cell-ft"></view>
            </navigator>
            <navigator url="/member/cash/rechargelist" class="m-cell m-cell-access" v-if="false">
                <view class="m-cell-bd">
                    <label>{{__('充值记录')}}</label>
                </view>
                <view class="m-cell-ft"></view>
            </navigator>

			<navigator url="/integral/integral/record" class="m-cell m-cell-access">
			    <view class="m-cell-bd">
			        <label>{{__('积分')}}</label>
			    </view>
			    <view class="m-cell-ft">{{userInfo.user_points}}</view>
			</navigator>

			<navigator url="/integral/sp/list" class="m-cell m-cell-access" v-if="(Config.SP_ENABLE)">
			    <view class="m-cell-bd">
			        <label>{{__('众宝')}}</label>
			    </view>
			    <view class="m-cell-ft">{{userInfo.user_sp_total}}</view>
			</navigator>
			<navigator url="/member/member/coupon" class="m-cell m-cell-access">
			    <view class="m-cell-bd">
			        <label>{{__('优惠券')}}</label>
			    </view>
			    <view class="m-cell-ft">{{userInfo.voucher}}</view>
			</navigator>
        </view>
        <view class="m-text-box" v-if="(isMemDist)">
            <view @click="showTip">
                <label class="iconfont icon-14052218"></label>{{__('分销规则')}}
            </view>
        </view>
        <!-- <view class="m-btn-box m-btn-box-two" v-if="(CashData.isShowDistributionButton)">
          <navigator url="/member/fans/endorsement" class="u-btn u-btn-default">{{__('我要代言')}}</navigator>
          <navigator url="/member/cash/recharge" class="u-btn u-btn-default">{{__('我要充值')}}</navigator>
        </view>
        <view class="m-btn-box" v-if="(CashData.isShowDistributionButton==false)">
          <navigator url="/member/cash/recharge" class="u-btn u-btn-default">{{__('我要充值')}}</navigator>
        </view> -->
        <!-- <view class="m-btn-box" v-if="(CashData.isShowDistributionButton)">
          <navigator url="/member/fans/endorsement" class="u-btn u-btn-default">{{__('我要代言')}}</navigator>
        </view> -->
        <view class="m-btn-box" v-if="false">
            <view class="u-btn u-btn-default" @click="goto" v-if="(isECashCard)">{{__('我要充值')}}</view>
        </view>
        <view class="m-btn-box" v-if="(CashData.isShowDistributionButton&&isMemDist)">
            <navigator url="/member/fans/endorsement" class="u-btn btn-line-primary">{{__('我要分销')}}</navigator>
        </view>
    </view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'


	export default {
		name: "predeposit",
		data: function() {
			return {
                CashData: {},
                isECashCard: true,
				isMemDist: false,
				isShowMoney:true,
				commission_withdraw_mode:0
			}
		},
		computed: mapState(['Config', 'StateCode', 'notice', 'plantformInfo', 'shopInfo', 'userInfo', 'hasLogin']),
		onLoad: function(options) {
            uni.setNavigationBarTitle({
                title:this.__('账户余额')
            });


            var that = this;
            var params = {user_id: this.userInfo.user_id};

			/*
            this.forceUserInfo(function (resource) {
				that.reloadUserResource(function (user_info) {

					that.$.request({
					    url: that.Config.URL.fx.index,
					    data: params,
					    success: function (data, status, msg, code) {
					        if (200 == status) {
					            var new_data = {
					                user_money: that.$.sprintf('%.2f', resource.user_money),
					                user_commission_buy: that.$.sprintf('%.2f', data.user_commission_buy),
					                user_commission_now: that.$.sprintf('%.2f', data.user_commission_now),
					                commission_amount: that.$.sprintf('%.2f', data.commission_amount),

					                month_commission_buy: that.$.sprintf('%.2f', data.month_commission_buy),
					                month_fans_num: data.month_num,
					                isShowDistributionButton: true,
					                commission_buy_amount: that.$.sprintf('%.2f', data.commission_buy_amount),
					                total_fans_num: data.all_num,
					                user_total_weath: that.$.sprintf('%.2f', resource.user_money+data.user_commission_now),
					            };

					            that.setData({CashData: new_data})
					        }
					    }
					});
				});

            });
			*/
            this.getPlantformInfo(function(plantformInfo) {
				
				that.commission_withdraw_mode = plantformInfo.plantform_commission_withdraw_mode
				
				//如果启用了支付方式
				if (that.$.inArray(plantformInfo.payment_channel_code_row, 'money'))
				{
					that.isShowMoney = true;
				}
				else
				{
					that.isShowMoney = false;
				}
            });

            // var r = this.shopInfo.VendorFeatureSet;
            // r.indexOf("ECashCard") > -1 ? this.setData({isECashCard: true}) : this.setData({isECashCard: false}),
            // r.indexOf("MemDist") > -1 ? this.setData({isMemDist: true}) : this.setData({isMemDist: false})
            // 系統配置是否启用分销、提现等系统
		},

		onShow: function() {
			let that = this;

            var params = {user_id: this.userInfo.user_id};

            this.forceUserInfo(function (resource) {
				that.reloadUserResource(function (user_info) {

					that.$.request({
					    url: that.Config.URL.fx.index,
					    data: params,
					    success: function (data, status, msg, code) {
					        if (200 == status) {
					            var new_data = {
					                user_money: that.$.sprintf('%.2f', resource.user_money),
					                user_commission_buy: that.$.sprintf('%.2f', data.user_commission_buy),
					                user_commission_now: that.$.sprintf('%.2f', data.user_commission_now),
					                commission_amount: that.$.sprintf('%.2f', data.commission_amount),

					                month_commission_buy: that.$.sprintf('%.2f', data.month_commission_buy),
					                month_fans_num: data.month_num,
					                isShowDistributionButton: true,
					                commission_buy_amount: that.$.sprintf('%.2f', data.commission_buy_amount),
					                total_fans_num: data.all_num,
					                user_total_weath: that.$.sprintf('%.2f', resource.user_money+data.user_commission_now),
					            };

					            that.setData({CashData: new_data})
					        }
					    }
					});
				});
            });


			setTimeout(()=>{
				this.setData({isMemDist: this.Config.PLANTFORM_FX_ENABLE})
			}, 100)
		},

		methods: {
			...mapMutations(['login', 'logout', 'getPlantformInfo', 'forceUserInfo', 'getUserInfo', 'reloadUserResource']),
            showTip: function () {
                let that = this;
                that.$.confirm(that.__("分享商品或者出示分销二维码给您的好友，好友通过您的分享注册后即成为您的一级下级，一级下级分享绑定的会员是您的二级下级，您的一二级下级购买商品您都可以获得分销佣金；简言之：A推B，B推C，C购买AB有佣金。"))
            },
            "goto": function () {
                let that = this;
                that.$.redirectTo("/member/cash/recharge")
            }
		}
	}
</script>

<style lang="scss">
    @import "../../styles/_variables";

    .topbg {background-color: $default-skin-bg;padding-bottom: 20rpx;}
    .topinfo {display: flex;width: 100%;flex-flow: column;padding-top:40rpx;justify-content: center;align-items: center;color: white;font-size: 14px;position: relative;}
    /* .topinfo label {font-size: 56px;} */
    .m-t-text{float: right;position: relative;margin-right: 40rpx;}
    .m-t-text::after {content:" ";display:inline-block;height:12rpx;width:12rpx;border-width:4rpx 4rpx 0 0;border-color:#fff;border-style:solid;-webkit-transform:matrix(0.71, 0.71, -0.71, 0.71, 0, 0);transform:matrix(0.71, 0.71, -0.71, 0.71, 0, 0);position:relative;position:absolute;top: 50%;margin-top: -6rpx;}

    .menu_list{display: -webkit-box;margin-top: 40rpx;}
    .menu_item{color: white;float: left;-webkit-box-flex: 1;box-sizing: border-box;text-align: center;
        position: relative;}
    .menu_item text{font-size: 14px;}
    .menu_item:nth-child(1):before {content: "";border-right: 1rpx solid white;height: 50rpx;position: absolute;right: 0;bottom: 0;}
    .m-cells{font-size: 28rpx;background-color: #fff;}
    .m-cell-bd{color: #333;}
    .m-text-box{font-size: 24rpx;box-sizing: border-box;padding: 20rpx;color: #888;line-height: 40rpx;}
    .m-text-box label{padding-right: 10rpx;}
    .m-cell-bd{line-height: 50rpx;}
    /* .m-btn-box{padding-bottom: 10rpx;} */
    .m-btn-box-two{
        display: flex;
        justify-content: space-around;
    }
    .portionMoney{
        width: 60%;
        display: flex;
        font-size: 28rpx;
        justify-content: space-around
    }
</style>
