<template>
	<view class="page flex-col">
		<view class="group_1 flex-col">
			<!-- <image class="image_1" referrerpolicy="no-referrer" src="/static/lanhu_record/ps8pzn4zlg6msqasg8gjmp6oqt1rhjhx4q7bb20938-5f91-446e-853a-08a4a97e4406.png" /> -->
			<!-- <view class="text-wrapper_2 flex-row justify-between">
				<text class="text_3">收款方式</text>
				<picker class="text_3" @change="bindPickerChange" :value="index" :range="array">
					<view class="uni-input">{{ array[index] }}</view>
				</picker>
			</view> -->
			<!-- <image class="image_2" referrerpolicy="no-referrer" src="/static/lanhu_record/pshv0mmbha3hqgycdm25qcsoi99tglg3vvbd334f95-3265-43d9-a16b-5391abaab2b1.png" />
			<view class="text-wrapper_2 flex-row justify-between" v-if="index > 1">
				<text class="text_3">银行名称</text>
				<input class="text_4" style="width: 200px;margin-left: 60px;" placeholder="请输入银行完整名称xx支行" v-model="data.payaccountname" />
			</view> -->
			<image class="image_2" referrerpolicy="no-referrer" src="/static/lanhu_record/pshv0mmbha3hqgycdm25qcsoi99tglg3vvbd334f95-3265-43d9-a16b-5391abaab2b1.png" />
			<view class="text-wrapper_3 flex-row justify-between">
				<text class="text_5">支付宝帐号</text>
				<input class="text_6" placeholder="请输入收款帐号" v-model="data.payaccount" />
			</view>
			<image class="image_3" referrerpolicy="no-referrer" src="/static/lanhu_record/ps896c5etqrer2pa5o17g8gdpc1yu3d6c96124b8dc-5877-464b-9baa-6a8454ae2d29.png" />
			<view class="box_1 flex-row justify-between">
				<text class="text_7">微信收款码</text>
				<view class="image-wrapper_1 flex-col" style="background: none;">
					<image
						v-if="data.payaccountimg"
						style="width: 150px;height: 50px;"
						class="image_4"
						referrerpolicy="no-referrer"
						:src="data.payaccountimg"
						@click="uploadimg('payaccountimg')"
					/>
					<image v-else style="width: 50px;height: 50px;" class="image_4" referrerpolicy="no-referrer" :src="noimg" @click="uploadimg('payaccountimg')" />
				</view>
			</view>
			<image class="image_5" referrerpolicy="no-referrer" src="/static/lanhu_record/psuqgye8xemeeyyhuy0s00d9cscwkd2dlnpd8d71f8e-26c6-4324-a31c-943b803a1647.png" />
			<button class="button_1 flex-col" @click="onClick_1"><text class="text_9">提交保存</text></button>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			constants: {},
			noimg: '/static/lanhu_record/ps3lynngrkw77ya7zb5jydv23q6xcffyj53c6fe453-54c4-4078-b021-8c1b292a08c2.png',
			data: {
				uid: '0',
				realname: '',
				idcard: '',
				idcardimg1: '',
				idcardimg2: '',
				paytype: '',
				payaccountimg: '',
				payaccount: '',
				payaccountname: ''
			},
			userinfo: null,
			array: ['微信', '支付宝', '银行'],
			index: 0
		};
	},
	onShow() {
		var user = this.$api.getUserinfo();
		if (user) {
			this.userinfo = user;
			this.data.uid = this.userinfo.id;
			this.data.realname = this.userinfo.realname;
			this.data.idcard = this.userinfo.idcard;
			this.data.idcardimg1 = this.userinfo.idcardimg1;
			this.data.idcardimg2 = this.userinfo.idcardimg2;
			if(this.userinfo.paytype=="微信"){
				this.index = 0;
			}else if(this.userinfo.paytype=="支付宝"){
				this.index = 1;
			}else{
				this.index = 2;
				this.data.payaccountname=this.userinfo.paytype;
			}
			
			this.data.payaccountimg = this.userinfo.weixin;
			this.data.payaccount = this.userinfo.zfb;
		} else {
			this.userinfo = null;
		}
	},
	methods: {
		bindPickerChange: function(e) {
			// console.log('picker发送选择改变，携带值为', e.detail.value);
			this.index = e.detail.value;
			if (this.index <= 1) {
				this.data.paytype = this.array[this.index];
			} else {
				this.data.paytype = this.array[this.index];
			}
		},
		onClick_1() {
			
			// data.paytype=this.array[this.index];
			// if(this.index>1){
			// 	data.paytype=data.payaccountname;
			// }
			if (this.data.uid == '0') {
				uni.showToast({
					title: '请重新登录',
					icon: 'none'
				});
				uni.switchTab({
					url: '/pages/my/index'
				});
				return;
			}
			var data = new Object();
			data.uid=this.data.uid;
			data.zfb=this.data.payaccount;
			data.weixin=this.data.payaccountimg;
			this.$api
				.MhPostModel(data, 'user/shoukuan')
				.then(res => {
					// console.log('user/shoukuan信息', JSON.stringify(res));
					if (res.data.code != 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
						this.getCode();
						return;
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
						
					}
				})
				.catch(err => {
					// console.log('request fail', JSON.stringify(err));
				});
		},
		uploadimg(id) {
			var that = this;
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], //从相册选择
				success: function(res) {
					// console.log(JSON.stringify(res.tempFilePaths));
					uni.uploadFile({
						url: that.$api.getUploadurl2,
						filePath: res.tempFilePaths[0],
						name: 'file',
						success: function(res) {
							// console.log(res.data);
							var img=JSON.parse(res.data);
							// console.log(img.data);
							that.data.payaccountimg = img.data.url;
						}
					});
				}
			});
		}
	}
};
</script>
<style lang="css">
@import '../common/common.css';
@import './assets/style/index.rpx.css';
</style>
