<template>
	<view class="content">
		<view class="row1">
			<text class="tit">头像</text>
			<view class="background-img" @click.stop="imgsub"><image class="background-img" :src="userInfo.avatar" mode="aspectFill"></image></view>
		</view>
		<view class="row">
			<text class="tit">昵称</text>
			<input class="input" type="text" v-model="userInfo.nickname" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit" style="width: 240upx;">银行账号</text>
			<input class="input" type="text"  v-model="userInfo.bank_card_no" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit" style="width: 240upx;">所属银行</text>
			<input class="input" type="text"  v-model="userInfo.bank_of_deposit" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit">ID</text>
			<input class="input" type="text"  disabled="true" v-model="userInfo.id" placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit">账户</text>
			<input class="input" type="text"  disabled="true" v-model="userInfo.username" placeholder-class="placeholder" />
		</view>
		<view class="row1">
			<text class="tit">支付宝收款码</text>
			<view class="background-img1" @click.stop="imgsubali"><image class="background-img1" :src="userInfo.ali" mode="aspectFill"></image></view>
		</view>
		<view class="row1">
			<text class="tit">微信收款码</text>
			<view class="background-img1" @click.stop="imgsubwechat"><image class="background-img1" :src="userInfo.wechat" mode="aspectFill"></image></view>
		</view>
		<view class="add-btn" @click="confirm">提交</view>
		<view class="out" @click="toLogout">退出登录</view>
	</view>
</template>

<script>
import { mapState,mapMutations } from 'vuex';
import { uploads } from '@/api/user.js';
import {userEdit,logout} from '@/api/set.js';

export default{
	data(){
		return{
			
		}
	},
	onLoad() {
		console.log(this.userInfo)
	},
	computed: {
		...mapState('user',['userInfo'])
	},
	methods: {
		...mapMutations('user',['logout']),
		imgsub() {
			console.log('上传头像')
			uploads({
				filename: ''
			}).then(res => {
				// console.log("data",data);
				// this.userInfo.avatar = data.fullurl;
				console.log(res,'++++++++++++++++')
				this.userInfo.avatar = res[0].fullurl;
			})
		},
		imgsubali() {
			console.log('上传支付宝二维码')
			uploads({
				filename: ''
			}).then(res => {
				// console.log("data",data);
				// this.userInfo.avatar = data.fullurl;
				console.log(res,'++++++++++++++++')
				this.userInfo.ali = res[0].fullurl;
			})
		},
		imgsubwechat() {
			console.log('上传微信二维码')
			uploads({
				filename: ''
			}).then(res => {
				// console.log("data",data);
				// this.userInfo.avatar = data.fullurl;
				console.log(res,'++++++++++++++++')
				this.userInfo.wechat = res[0].fullurl;
			})
		},
		confirm() {
			userEdit({ avatar: this.userInfo.avatar ,nickname: this.userInfo.nickname,bank_of_deposit:this.userInfo.bank_of_deposit,bank_card_no:this.userInfo.bank_card_no,ali: this.userInfo.ali,wechat: this.userInfo.wechat})
				.then(e => {
					this.$api.msg('修改成功');
					setTimeout(()=> {
						uni.switchTab({
							url:'/pages/user/user'
						});
					}, 1000);
					console.log(e);
				})
				.catch(e => {
					console.log(e);
				});
		},
		toLogout(){
			let obj = this;
			uni.showModal({
			    content: '确定要退出登录么',
			    success: (e)=>{
			    	if(e.confirm){
						// logout({}).then((e) => {
						// 	uni.navigateBack();
						// }).catch((e) => {
						// 	console.log(e);
						// })
						uni.navigateBack();
			    		obj.logout();
			    	}
			    }
			});
		},
	}
}
</script>

<style lang="scss">
	.row1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		padding: 0 30upx;
		height: 110upx;
		background: #000;
		margin-bottom: 20upx;
		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-lg;
			color: #fff;
		}
		
		.background-img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background: #f2f2f2;
		}
		.background-img1 {
			width: 80rpx;
			height: 80rpx;
			background: #f2f2f2;
		}
	}
	.row {
		display: flex;
		align-items: center;
		padding: 0 30upx;
		height: 110upx;
		background: #000;
	
		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-lg;
			color: #fff;
		}
		.input {
			flex: 1;
			text-align: right;
			font-size: $font-base;
			color: #fff;
		}
	}
	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 158rpx auto 30rpx;
		width: 560rpx;
		height: 80rpx;
		background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
		border-radius: 40px;
		color: #FFFFFF;
	}
	.out {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 auto 30rpx;
		width: 560rpx;
		height: 80rpx;
		border: 1px solid #FFECD6;
		background: #FFFFFF;
		border-radius: 40px;
		color: #CE9C6D;
	}
</style>