<template>
	<ciy-header title="申请众识码"></ciy-header>
	<view v-if="init.code != 1" class="px4 py4">
		<view style="height:60vw;width:100%;" class="ciy-skeleton"></view>
	</view>
	<view v-else-if="me.cciy.length > 10" class="txt-center py4">
		您已申请成功
		<view @tap="copyboard(me.cciy)" class="txt-lgg py4">{{me.cciy}}</view>
	</view>
	<view v-else-if="init.data && init.data.auditstatus != 90">
		<view class="ciy-tip" v-if="init.data.auditstatus == 20">您已提交申请，等待审核...</view>
		<view class="ciy-tip" v-if="init.data.auditstatus == 50">您的申请正在审核中...</view>
		<view class="ciy-tip" v-if="init.data.auditstatus == 100">您已申请通过</view>
		<view class="ciy-list">
			<view class="l1">{{init.data.name}}</view>
			<view class="l1">{{init.data.country}}</view>
			<view class="rb">{{todatetime(init.data.addtimes)}} 申请</view>
		</view>
	</view>
	<view v-else>
		<view class="ciy-tip" v-if="init.data?.auditmsg">
			{{init.data.auditmsg}}
		</view>
		<view class="ciy-card char4">
			<view class="ciy-form">
				<label class="imp">主体国籍</label>
				<view>
					<ciy-input bb v-model="editdata.country" type="idcard"></ciy-input>
				</view>
				<view class="flexnone px4" @tap="editdata.country='中国'">
					中国
				</view>
			</view>
			<view class="ciy-form">
				<label class="imp">多国身份</label>
				<view class="txt-left">
					<ciy-selbool v-model="editdata.dualcitizen" y="存在" n="没有"></ciy-selbool>
				</view>
			</view>
			<view class="ciy-form-bottom">
				<button class="btn lg cc" @tap="submit">申请众识码</button>
			</view>
		</view>
		<view class="ciy-tip"><ciy-markdown :md="init.tip"></ciy-markdown></view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {
			}
		},
		onLoad() {
			this.getinit();
		},
		methods: {
			async getinit() {
				await this.getauth('real');
				if(this.me.cciy.length > 11)
					return this.init.code = 1;
				this.editdata.dualcitizen = 2;
				var retjson = await this.callfunc({
					func: 'me.safe_ccub_init'
				});
				this.init = retjson;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				if (retjson.data && retjson.data.auditstatus == 100 && this.me.cciy.length < 12) {
					this.me.cciy = retjson.data.cciy;
					this.setstorage('me', this.me);
					var app = getApp();
					var page = app.getpage(1);
					page.me = this.me;
				}
			},
			async submit(e) {
				if (this.editdata.country.length < 1)
					return this.toast('请输入主体国籍');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.safe_ccub_submit',
					data: this.editdata
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				await this.toast('申请提交成功');
				uni.navigateBack();
			},
		}
	}
</script>