<template>
	<view class="content">
		<view class="row">
			<view class="left">
				<text class="tit" style="width: 160upx;">{{ $t('foo.zh') }}</text>
				<view class="tit">ID:{{ userInfo.id }}</view>
			</view>
			<input class="input" type="text" disabled="true" v-model="userInfo.username" placeholder-class="placeholder" />
		</view>
		<view class="row1">
			<text class="tit">{{ $t('foo.tx') }}</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" style="width: 160upx; color: #bdbdbd;">{{ $t('foo.nc') }}*</text>
			<input class="input" type="text" v-model="userInfo.nickname" placeholder-class="placeholder" placeholder="请填写" />
		</view>
		<view class="row">
			<text class="tit" style="width: 160upx; color: #bdbdbd;">{{ $t('foo.yhzh') }}*</text>
			<input class="input" type="text" v-model="userInfo.bank_card_no" placeholder-class="placeholder" placeholder="请填写" />
		</view>
		<view class="row">
			<view class="left">
				<text class="tit" style="width: 160upx; color: #bdbdbd;">{{ $t('foo.scyh') }}*</text>
				<view class="image"><image src="../../static/img/user-bank.png" mode=""></image></view>
			</view>

			<input class="input" type="text" v-model="userInfo.bank_of_deposit" placeholder-class="placeholder" 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="row1">
			<view class="left">
				<text class="tit">{{ $t('foo.zfbskm') }}</text>
				<view class="image"><image src="../../static/img/ali.png" mode=""></image></view>
			</view>

			<view class="background-img1" @click.stop="imgsubali">
				<image class="background-img1" :src="userInfo.ali || '../../static/img/upload.png'" mode="aspectFill"></image>
			</view>
		</view>
		<view class="row1">
			<view class="left">
				<text class="tit">{{ $t('foo.wxskm') }}</text>
				<view class="image"><image src="../../static/img/weixin.png" mode=""></image></view>
			</view>

			<view class="background-img1" @click.stop="imgsubwechat">
				<image class="background-img1" :src="userInfo.wechat || '../../static/img/upload.png'" mode="aspectFill"></image>
			</view>
		</view>
		<view class="row">
			<text class="tit" style="width: 140upx; color: #bdbdbd;">{{ $t('foo.jjlxrdh') }}*</text>
			<input class="input" type="text" v-model="userInfo.ext_mobile" placeholder-class="placeholder" placeholder="请填写" />
		</view>
		<view class="tishi">*{{ $t('foo.bt') }}</view>
		<view class="add-btn" @click="confirm">{{ $t('foo.tj') }}</view>
		<view class="out" @click="toLogout">{{ $t('foo.tcdl') }}</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() {
		let i = this.userInfo.id + '';
		console.log(i.length);
		if (i.length < 8) {
			let k = '';
			for (let j = 0; j < 8 - i.length; j++) {
				k += '0';
			}
			this.userInfo.id = k + this.userInfo.id;
		}
		uni.setNavigationBarTitle({
			title: this.$t('foo.sz')
		});
	},
	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() {
			let data = '';
			if (this.userInfo.nickname == '') {
				uni.showModal({
					title: this.$t('foo.ts'),
					content: this.$t('foo.jtxzsxm')
				});
				return;
			}
			if (this.userInfo.bank_card_no == '') {
				uni.showModal({
					title: this.$t('foo.ts'),
					content: this.$t('foo.jtxyhkh')
				});
				return;
			}
			if (this.userInfo.bank_of_deposit == '') {
				uni.showModal({
					title: this.$t('foo.ts'),
					content: this.$t('foo.jtxkhh')
				});
				return;
			}
			if (this.userInfo.ext_mobile == '' || this.userInfo.ext_mobile == null) {
				uni.showModal({
					title: this.$t('foo.ts'),
					content: this.$t('foo.jtxjjlxrdh')
				});
				return;
			}
			if (this.userInfo.avatar.length < 255) {
				data = {
					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,
					ext_mobile: this.userInfo.ext_mobile
				};
			} else {
				data = {
					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,
					ext_mobile: this.userInfo.ext_mobile
				};
			}
			userEdit(data)
				.then(e => {
					this.$api.msg('修改成功');
					setTimeout(() => {
						uni.navigateBack({});
					}, 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);
						// })
						logout({}).then()
						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;
	.toux {
		display: inline-block;
	}
	.tit {
		flex-shrink: 0;
		width: 120upx;
		font-size: $font-lg;
		color: #fff;
	}
	.left {
		display: flex;
		justify-content: start;
	}
	.image {
		width: 100rpx;
		height: 100rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.background-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		background: #f2f2f2;
	}
	.background-img1 {
		width: 100rpx;
		height: 100rpx;
		background: #000000;
	}
}
.row {
	display: flex;
	align-items: center;
	padding: 0 30upx;
	height: 110upx;
	background: #000;
	.left {
		display: flex;
		justify-content: start;
		align-items: center;
	}
	.image {
		width: 100rpx;
		height: 100rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.tit {
		flex-shrink: 0;
		width: 120upx;
		font-size: $font-lg;
		color: #fff;
	}
	.input {
		flex: 1;
		text-align: right;
		font-size: $font-base;
		color: #fff;
	}
}
.tishi {
	padding: 20rpx 0 120rpx 24rpx;
	color: #fff;
	font-size: 26rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
}
.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>
