<template>
	<ciy-header title="我的" mode="scroll"></ciy-header>
	<view class="topbg"></view>
	<view :style="{height:header_statusbar_height+'px'}"></view>
	<view style="padding-top:1rem;">
		<view class="avartop">
			<image :src="file_stor(me.icon?me.icon:'/img/face.png')" mode="scaleToFill" />
		</view>
	</view>
	<view class="maincard" style="margin-top: -2.5rem;">
		<view class="flex flex-center">
			<view class="nick" @tap="gourl" data-url="$/pages/me/user_info">{{me.id>0?(me.name?me.name:'游客'):'登录/注册'}}</view>
			<view class="icon zy" style="margin-left:1rem;" v-if="showbalance" @tap="getbalance(2)"></view>
			<view class="icon by" style="margin-left:1rem;" v-else @tap="getbalance(1)"></view>
		</view>
		<view class="abs r0 t0" style="opacity: 0;" @tap="gourl" data-url="/pages/demo/index">Demo</view>
		<view class="abs r1 b1 txt-smmm" @tap="copyboard('E' + me.eid)" v-if="me.id>0">E{{me.eid}}</view>
		<view class="usrnum">
			<view>
				<view class="num" v-if="showbalance">
					<ciy-shownum speed="80" :value="me.mymoney" unit=",100,2|万,1000000,2|亿,10000000000,2"></ciy-shownum>
				</view>
				<view class="num" v-else>---</view>
				<view class="tit">可消费余额</view>
			</view>
			<view>
				<view class="num" v-if="showbalance">
					<ciy-shownum :value="me.mycashmoney" unit=",100,2|万,1000000,2|亿,10000000000,2"></ciy-shownum>
				</view>
				<view class="num" v-else>---</view>
				<view class="tit">可提现余额</view>
			</view>
			<view>
				<view class="num" v-if="showbalance">
					<ciy-shownum :value="me.mypnt" unit=",1,0|万,10000,2|亿,100000000,2"></ciy-shownum>
				</view>
				<view class="num" v-else>---</view>
				<view class="tit" @tap="gourl" data-url="$/pages/me/pnt_lst">积分</view>
			</view>
		</view>
	</view>
	<view class="maincard px4" v-if="me.id>0">
		<template v-if="me.accounttimes>tostamp()">
			<view class="caption">有效会员</view>
			<view class="expdate">{{ccode(g.userlevel, me.userlevel)}}　有效期至 {{todatetime(me.accounttimes, 'd')}}</view>
		</template>
		<template v-else>
			<view class="caption">会员已到期</view>
			<view class="expdate" style="color:var(--dag5);">{{ccode(g.userlevel, me.userlevel)}}　到期日 {{todatetime(me.accounttimes, 'd')}}</view>
		</template>
		<view class="ciy-hr"></view>
		<view class="caption">选择{{me.accounttimes>tostamp()?'续费':'付费'}}方案</view>
		<view class="userpay" v-if="init.userbuys">
			<view class="item" @tap="buyuser(item)" v-for="(item,index) in init.userbuys" :key="index">
				<view class="price">{{item.usermoney/100}}元</view>
				<view class="memo">{{item.name}}</view>
				<view class="recommend" v-if="init.recommend == item.id">推荐</view>
			</view>
		</view>

	xiaoxi 消息
		<view class="caption">付费会员权益</view>
		<view class="cgrid">
			<view class="item">
				<view class="icon">📇</view>
				<view class="txt">权益1</view>
			</view>
			<view class="item">
				<view class="icon">🤝</view>
				<view class="txt">权益2</view>
			</view>
		</view>
	</view>
	<view class="maincard">
		<view class="ciy-grid">
			<view class="grid" data-url="$/pages/me/cash_charge" @tap="gourl">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.v1)}"></view>
				<view class="name">充值</view>
			</view>
			<view class="grid" data-url="$/pages/me/cashie_lst" @tap="gourl">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.v3)}"></view>
				<view class="name">收支明细</view>
			</view>
			<view class="grid" data-url="$/pages/me/cashout_cash" @tap="gourl">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.v2)}"></view>
				<view class="name">提现</view>
			</view>
			<view class="grid" data-url="$/pages/me/cashoe_lst" @tap="gourl">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.v3)}"></view>
				<view class="name">收益明细</view>
			</view>
		</view>
		<view class="ciy-grid">
			<view class="grid">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.ciy)}"></view>
				<view class="name">图标名称</view>
			</view>
			<view class="grid">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.ciy)}"></view>
				<view class="name">图标名称</view>
			</view>
			<view class="grid">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.ciy)}"></view>
				<view class="name">图标名称</view>
			</view>
			<view class="grid">
				<view class="icon" :style="{backgroundImage:svg2bg(svg.ciy)}"></view>
				<view class="name">图标名称</view>
			</view>
		</view>
	</view>
	<view class="bg5" style="height:0.3rem;"></view>
	<ciy-swipelist v-if="me.id>0" title="众识码" data-url="$/pages/me/safe_ccub" @tap="gourl" :right="tocciy(me.cciy)" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="实名认证" data-url="$/pages/me/safe_real" @tap="gourl" :right="tomsk(me.truename, '#***')" more></ciy-swipelist>
	<view class="bg5" style="height:0.3rem;"></view>
	<ciy-swipelist v-if="me.id>0" title="个人信息" @tap="gourl" data-url="$/pages/me/user_info" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="收款银行" @tap="gourl" data-url="$/pages/me/user_bank" :right="me.bankaccount?'已设置':'未设置'" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="收货地址" @tap="gourl" data-url="$/pages/me/user_shipaddr" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="我要开票" @tap="gourl" data-url="$/pages/me/invoicing" :right="me.myinvmoney>=1000?'可开票':'未达开票金额'" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="分享二维码" @tap="gourl" data-url="$/pages/me/share_qrcode" more></ciy-swipelist>
	<ciy-swipelist v-if="me.mobile" :title="me.needpass?'设置密码':'修改密码'" @tap="gourl" data-url="$/pages/me/safe_password" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="意见建议" @tap="gourl" data-url="$/pages/me/suggest" right="留下您的宝贵建议" more></ciy-swipelist>
	<ciy-swipelist title="帮助中心" @tap="gourl" data-url="/pages/pub/psection?id=1" right="FAQ" more></ciy-swipelist>
	<ciy-swipelist v-if="me.id>0" title="工单提问" @tap="gourl" data-url="$/pages/me/problem_pub" right="提交您的问题" more></ciy-swipelist>

	<ciy-swipelist title="联系客服" more>
		<button open-type="contact" plain class="btn tran" style="color:var(--txt5)">在线客服</button>
	</ciy-swipelist>
	<ciy-swipelist title="关于我们" @tap="gourl" data-url="/pages/pub/paper?id=1" right="众产" more></ciy-swipelist>
	<ciy-swipelist title="软件版本" @tap="upver" :right="version" more></ciy-swipelist>
	<view class="bg5" v-if="me.id>0" style="height:0.5rem;"></view>
	<ciy-swipelist v-if="me.id>0" title="重新登录" @tap="relogin" more></ciy-swipelist>
	<ciy-tabbar ref="tabbar"></ciy-tabbar>
</template>

<script>
	export default {
		data() {
			return {
				svg: {},
				version:'',
				showbalance: false,
			}
		},
		onLoad() {
			var app = getApp();
			this.version = app.globalData._version;
			this.load_svgicon(this.file_stor('/svgicon/me.txt')).then(svgs => {
				this.svg = svgs;
			});
			this.getinit();
		},
		onPullDownRefresh(b) {
			var app = getApp();
			app.globalData._restorage = true;
			uni.stopPullDownRefresh();
		},
		methods: {
			async getinit() {
				await this.getauth();
				var retjson = await this.callfunc({
					func: 'main.me_init',
					//cache: 86400,
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init = retjson;
			},
			async getbalance(act) {
				if (this._loading)
					return;
				await this.getauth();
				if (this.me.id == 0)
					return;
				if (act == 2) {
					this.showbalance = false;
					return;
				}
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.me_balance_get',
					data: {}
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.showbalance = true;
				this.me = this.objdeepmerge(this.me, retjson.user);
				this.setstorage('me', this.me);
			},
			async buyuser(item) {
				if (item.userlevel < this.me.userlevel) {
					if (await this.askmsg('您当前会员等级高于续费等级，\n是否降级续费？', '降级') != 'ok')
						return;
				}
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.me_userbuy_create',
					data: {
						id: item.id
					}
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);

				retjson.provider = 'wxpay';
				try {
					var retpay = await uni.requestPayment(retjson);
					await this.sleep(1000);
					var retjson2 = await this.callfunc({
						func: 'me.me_userbuy_chk',
						data: {
							orderid: retjson.orderid
						}
					});
					if (retjson2.code != 1)
						return this.toast(retjson2.errmsg);
					this.me.accounttimes = retjson2.accounttimes;
					this.me.userlevel = retjson2.userlevel;
					this.setstorage('me', this.me);
					this.toast('支付成功');
				} catch (e) {}
			},
			relogin() {
				this.clearstorage();
				this.getauth('relogin');
			},
			upver() {
				var app = getApp();
				app.appupdate('all', async verinfo => {
					return await this.askmsg(verinfo, '更新') == 'ok';
				});
			},
		}
	}
</script>
<style>
	.topbg {
		height: 10rem;
		overflow: hidden;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
	}

	.topbg::before {
		content: '';
		left: -5rem;
		right: -5rem;
		border-radius: 0 0 100vw 100vw;
		height: 100%;
		background: linear-gradient(60deg, var(--e-userbg1), var(--e-userbg2));
		position: absolute;
		top: 0;
		pointer-events: none;
		z-index: 0;
	}

	.avartop {
		position: relative;
		display: flex;
		margin: 0 0 0 1.5rem;
		width: 5rem;
		height: 5rem;
		border-radius: 50%;
		background: var(--bg2);
		border: 2px solid var(--bg1);
		overflow: hidden;
		z-index: 3;
	}

	.avartop>image {
		width: 100%;
		height: 100%;
	}

	.maincard {
		position: relative;
		background: var(--bg1);
		color: var(--txt6);
		padding: 0.5rem;
		margin: 0 1rem 1rem 1rem;
		border-radius: 0.3rem;
		box-shadow: 0 4px 8px var(--bg6);
	}

	.maincard .nick {
		font-size: 1.2rem;
		font-weight: bold;
		padding-left: 4.5rem;
	}

	.expdate {
		display: block;
		padding-left: 1rem;
		margin-top: -1rem;
		margin-bottom: 1rem;
		font-size: 0.9rem;
		color: var(--succ5);
	}

	.caption {
		font-size: 1.2rem;
		font-weight: bold;
		padding: 1em 0;
	}

	.userpay {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.userpay>.item {
		position: relative;
		width: 30%;
		padding: 1em 0;
		text-align: center;
		border: 1px solid var(--bg4);
		border-radius: 1rem;
	}

	.userpay>.item>.price {
		display: block;
		font-size: 1.2rem;
		font-weight: bold;
		color: var(--man5);
	}

	.userpay>.item>.memo {
		font-size: 13px;
		color: var(--txt4);
	}

	.userpay>.item>.recommend {
		position: absolute;
		top: -0.5rem;
		right: 0.5rem;
		padding: 0.2rem 0.8rem;
		font-size: 0.8rem;
		color: var(--dagt);
		background: var(--dag5);
		border-radius: 1rem;
	}

	.cgrid {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.cgrid .item {
		width: 48%;
		margin-bottom: 1rem;
		padding: 1rem;
		display: flex;
		flex-direction: column;
		align-items: center;
		background: var(--bg3);
		border-radius: 1rem;
	}

	.cgrid .icon {
		width: 2rem;
		height: 2rem;
		margin-bottom: 0.5rem;
		border-radius: 50%;
		background: linear-gradient(-25deg, #1890ff, #c0e1ff);
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 1.5rem;
	}

	.icon {
		width: 1.5rem;
		height: 1.5rem;
	}

	.icon.by {
		background-image: url("data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTkyNi4wMzM5MiAzMzkuODcwNzJjLTkuODY2MjQgMC0xOS4xNjkyOCA0LjE0MjA4LTI2LjE3ODU2IDExLjA4NDgtMTQuMDkwMjQgMTMuOTQ2ODgtMzkuNDQ0NDggMzAuOTQwMTYtNzkuODU2NjQgNDcuMjc4MDgtNzkuODYxNzYgMzIuMjg2NzItMTkyLjEyMjg4IDUwLjgwMDY0LTMwNy45OTM2IDUwLjgwMDY0cy0yMjguMTM2OTYtMTguNTEzOTItMzA3Ljk5MzYtNTAuODAwNjRjLTQwLjQxMjE2LTE2LjMzNzkyLTY1Ljc2NjQtMzMuMzMxMi03OS44NTY2NC00Ny4yNzgwOC03LjAxNDQtNi45NDI3Mi0xNi4zMTIzMi0xMS4wNzk2OC0yNi4xNzg1Ni0xMS4wNzk2OC0zMy4wNTQ3MiAwLTQ4Ljk5ODQg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42ODU0NHoiIGZpbGw9IiM2NjY2NjYiPjwvcGF0aD48cGF0aCBkPSJNNTEyIDQ0Ni4xODc1MmMzNi4yODU0NCAwIDY1LjgxMjQ4IDI5LjUyMTkyIDY1LjgxMjQ4IDY1LjgxMjQ4cy0yOS41MjcwNCA2NS44MTI0OC02NS44MTI0OCA2NS44MTI0OFM0NDYuMTg3NTIgNTQ4LjI5MDU2IDQ0Ni4xODc1MiA1MTIgNDc1LjcxNDU2IDQ0Ni4xODc1MiA1MTIgNDQ2LjE4NzUybTAtNzAuODc2MTZjLTc1LjQ4OTI4IDAtMTM2LjY4ODY0IDYxLjE5NDI0LTEzNi42ODg2NCAxMzYuNjg4NjRTNDM2LjUxMDcyIDY0OC42ODg2NCA1MTIgNjQ4LjY4ODY0czEzNi42ODg2NC02MS4xOTQyNCAxMzYuNjg4NjQtMTM2LjY4ODY0UzU4Ny40ODkyOCAzNzUuMzExMzYgNTEyIDM3NS4zMTEzNnoiIGZpbGw9IiM2NjY2NjYiPjwvcGF0aD48L3N2Zz4=");
	}

	.usrnum {
		padding-top: 1rem;
		padding-bottom: 0.5rem;
		display: flex;
	}

	.usrnum>view {
		flex: 1;
		text-align: center;
	}

	.usrnum .num {
		height: 2.5rem;
		padding-top: 0.2rem;
		font-size: 1.3rem;
	}

	.usrnum .tit {
		font-size: 0.9rem;
	}
</style>