<template>
	<view class="realname">
		<u-top-tips ref="uTips"></u-top-tips>
		<view class="header">
			<u-cell-item
			v-for="(item,key) in cellList"
			:key="key"
			:title="item.title"
			:value="item.value"
			:arrow="false"></u-cell-item>
		</view>
		<view class="container">
			<view class="tip">
				<text>{{tip}}</text>
			</view>
			<view class="positive">
				<u-upload
				:file-list="fileList1"
				:maxCount="1"
				width="650"
				height="350"
				uploadText="请上传身份证正面照片"
				:action="action1"
				:form-data="formData1"
				:header="header"
				:before-upload="beforeUpload1"
				@on-success="uploadSuccess1"
				>
				</u-upload>
			</view>
			<view class="positive">
				<u-upload
				:file-list="fileList2"
				:maxCount="1"
				width="650"
				height="350"
				uploadText="请上传身份证背面照片"
				:action="action2"
				:form-data="formData2"
				:header="header"
				:before-upload="beforeUpload2"
				@on-success="uploadSuccess2"
				>
				</u-upload>
			</view>
			<view class="btn">
				<u-button :custom-style="btnStyle" @click="save">保存</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {uploadpic} from '../../api/api.js'
	import {apiBaseUrl} from '../../api/request.js'
	export default {
		onLoad(){
			this.url = apiBaseUrl
			this.cellList[1].value = this.$store.state.userInfo.FCARD
			uni.$u.mpShare.title = '页面分享';
		},
		data(){
			return {
				btnStyle:{
					background:"#7D5AFC",
					color:'#FFFFFF'
				},
				cellList:[
					{
						title:'真实姓名',
						name:'name',
						value:''
					},
					{
						title:'身份证号码',
						name:'card',
						value:''
					}
				],
				tip:'提现账户必须与身份证姓名一致，图片大小不超过（5MB）',
				header:{
					test:11
				},
				url:'',
				fileList1:[],
				formData1:{file:''},
				fileList2:[],
				formData2:{file:''},
				fileList2:[]
			}
		},
		methods:{
			beforeUpload1(index,list){
				this.formData1.file = list[index].url
			},
			beforeUpload2(index,list){
				this.formData2.file = list[index].url
			},
			uploadSuccess1(data, index, lists){
				if(data.code == 100){
					this.$refs.uTips.show({
						title:data.message,
						type: 'error',
						duration: '2300'
					})
					lists.splice(index,1)
				}else{
					console.log(data)
					this.formData1.file = data.result.fileurl
				}
			},
			uploadSuccess2(data, index, lists){
				if(data.code == 100){
					this.$refs.uTips.show({
						title:data.message,
						type: 'error',
						duration: '2300'
					})
					lists.splice(index,1)
				}else{
					console.log(data)
					this.formData2.file = data.result.fileurl
				}
			},
			save(){
				uni.navigateBack()
			}
		},
		computed:{
			action1:function(){
				return this.url + '/api/Idcard/front'
			},
			action2:function(){
				return this.url + '/api/Idcard/back'
			}
		}
	}
</script>

<style>
	.realname{
		
	}
	.container{
		padding: 0 5%;
		background-color: #f0eff4;
	}
	.tip{
		margin: 3% 0;
		color: #ddbd19;
		font-size: 12px;
	}
	.pic{
		background-color: white;
	}
	.btn{
		margin-top: 20%;
	}
</style>
