<template>
	<view class="cmain">
		<view class="form_group">
			<view class="lable re">认证类型</view>
			<u-radio-group v-model="item.type" style="margin-top: 15px;">
				<u-radio :name=1 label="企业收购商"></u-radio>
				<u-radio :name=2 label="个人收购商" style="margin-left: 20px;"></u-radio>
			</u-radio-group>

		</view>
		<view class="form_group">
			<view class="lable re">（企业）名称</view>
			<input type="text" placeholder="请输入" v-model="item.name" />
		</view>
		<view class="form_group">
			<view class="lable re">（法人）姓名</view>
			<input type="text" placeholder="请输入" v-model="item.legalPerson" />
		</view>
		<view class="form_group">
			<view class="lable re">身份证</view>
			<input type="text" placeholder="请输入" v-model="item.idCard" />
		</view>
		<view class="form_group">
			<view class="lable re">联系号码</view>
			<input type="text" placeholder="请输入" v-model="item.contact" />
		</view>
		<view class="form_group">
			<view class="lable re">银行账号</view>
			<input type="text" placeholder="请输入" v-model="item.bankAccount" />
		</view>
		<view class="form_group" v-if="item.type==1">
			<view class="lable re">营业执照</view>
			<card v-model="item.businessLicense" pic="../../static/images/yyzz.png"></card>
		</view>
		<button class="btn" @click="save()" v-if="item.judgeStatus != 1">提交审核</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: {}
			};
		},
		onLoad(e) {
			this.http.request({
				url: '/level-two-server/app/TbPurchaser/info',
				success: res => {
					if (res.data.data) {
						this.item = res.data.data;
						uni.setNavigationBarTitle({
							title: '我的认证资料'
						});
					} else {
						this.item.type = 1
						uni.setNavigationBarTitle({
							title: '填写认证资料'
						});
					}
				}
			});
		},
		methods: {
			save() {
				let rule = [{
						name: 'name',
						checkType: 'notnull',
						errorMsg: '请填写(企业)名称'
					},
					{
						name: 'legalPerson',
						checkType: 'notnull',
						errorMsg: '请填写(法人)姓名'
					},
					{
						name: 'idCard',
						checkType: 'notnull',
						errorMsg: '请填写身份证'
					},
					{
						name: 'contact',
						checkType: 'notnull',
						errorMsg: '请填写联系号码'
					},
					{
						name: 'bankAccount',
						checkType: 'notnull',
						errorMsg: '请填写银行账号'
					},

				];
				if (this.item.type == 1) {
					rule.push({
						name: 'businessLicense',
						checkType: 'notnull',
						errorMsg: '请上传营业执照'
					} )
				}
				if (!this.verify.check(this.item, rule)) {
					uni.showModal({
						content: this.verify.error,
						showCancel: false
					});
					return false;
				}
				this.http.request({
					url: '/level-two-server/app/TbPurchaser/identification',
					method: 'POST',
					data: this.item,
					success: res => {
						uni.showToast({
							title: '提交成功'
						});
						setTimeout(() => {
							uni.$emit('authentication');
							uni.navigateBack();
						}, 1000);
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.btn {
		margin-top: 25px;
	}
</style>