<template>
	<view class="notice">
		<view class="a" v-if="isToWrite">
			<view class="notice-bd">
				<view class="contetn" v-html="info"></view>
			</view>
			<view class="notice-fd">
				<view class="btn" @click="openPage()">我已阅读并知晓，下一步</view>
			</view>
		</view>
		<view class="a" v-if="(userInfo && userInfo.status == 10) && userInfo.credit_code">
			<view class="notice-bd">
				<view class="a">
					<image src="https://hys.royaum.com.cn/static/caigou/success.png"></image>
					<view class="title">{{userInfo.status_text}}</view>
				</view>
			</view>
			<view class="notice-fd">
				<view class="btn" @click="openPage1()">立即编辑</view>
			</view>
		</view>
		<view class="a" v-if="(userInfo && userInfo.status >= 20)">
			<view class="notice-bd">
				<view class="a">
					<image src="https://hys.royaum.com.cn/static/caigou/success.png"></image>
					<view class="title">当前已认证</view>
				</view>
			</view>
		</view>
		<addShuiyin />
	</view>
</template>

<script>
	import * as newFunApi from '@/api/newFun'
	import * as Api from '@/api/help'
	export default {
		data() {
			return {
				info: "",
				isToWrite: false,
				userInfo: {}
			};
		},
		onShow() {
			this.wholesalerApplyInfo();
		},
		methods: {
			async wholesalerApplyInfo() {
				const { status, data } = await newFunApi.wholesalerApplyInfo({});
				if (status == 200) {
					this.userInfo = data.info?data.info:{};
					if(!data.info) {
						uni.setNavigationBarTitle({
							title: "注册须知"
						})
						this.isToWrite = true;
						this.getCarousel()
					}else if(data.info.status== 10 && this.userInfo.credit_code) {
						console.log(222)
						this.isToWrite = false;
						uni.setNavigationBarTitle({
							title: "申请记录"
						})
					}else if(data.info.status== 20) {
						this.isToWrite = false;
						uni.setNavigationBarTitle({
							title: "已认证"
						})
					}
				}
			},
			// 获取规则
			getCarousel() {
				const app = this;
				app.list = []
				Api.getAgreement({
						type: 'regist_policy'
					})
					.then(result => {
						if (result.data.detail && result.data.detail.content) {
							app.info = app.formatRichText(result.data.detail.content)
						}else{
							app.info = ""
						}
					})
					.finally(() => app.isLoading = false)
			},
			formatRichText(value) {
				value = value.replace(/\s*/g, ""); //去掉空格
				value = value.replace(/<[^>]+>/g, ""); //去掉所有的html标记
				value = value.replace(/↵/g, ""); //去掉所有的↵符号
				value = value.replace(/[\r\n]/g, "") //去掉回车换行
				value = value.replace(/&nbsp;/g, "") //去掉空格
				value = this.convertIdeogramToNormalCharacter(value);
				return value
			},
			convertIdeogramToNormalCharacter(val) {
				const arrEntities = {
					'lt': '<',
					'gt': '>',
					'nbsp': ' ',
					'amp': '&',
					'quot': '"'
				};
				return val.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) {
					return arrEntities[t];
				});
			},
			openPage() {
				let orcInfo = uni.getStorageSync("orcInfo")
				orcInfo.isToWrite = this.isToWrite;
				uni.setStorageSync("orcInfo",orcInfo)
				uni.navigateTo({
					url: "/pages/news/caigou/notice2"
				})
			},
			openPage1() {
				console.log(this.userInfo)
				let orcInfo = 
				{
					"license_img_id": this.userInfo.license_img_id,
					"license_img_url": this.userInfo.license_img,
					"door_img_id": this.userInfo.door_img_id,
					"door_img_url": this.userInfo.door_img,
					"company_name": this.userInfo.company_name,
					"credit_code": this.userInfo.credit_code,
					"invalid_date": "",
					"issuance_date": "",
					"issuance_office": "",
					"card_front_img_id": this.userInfo.card_front_img_id,
					"card_front_img_url": this.userInfo.card_front_img,
					"card_back_img_id": this.userInfo.card_back_img_id,
					"card_back_img_url": this.userInfo.card_back_img,
					"address": "",
					"sex": "",
					"nation": "",
					"birthday": "",
					"username": this.userInfo.username,
					"card_no": this.userInfo.card_no,
					"region": [{
						"value": this.userInfo.province_id,
						"label": this.userInfo.region.province
					}, {
						"value": this.userInfo.city_id,
						"label": this.userInfo.region.city
					}],
					"cityInfo": {
						"province": this.userInfo.region.province,
						"city": this.userInfo.region.city,
						"area": ""
					},
					"city_id": this.userInfo.city_id,
					"province_id": this.userInfo.province_id,
					"business": this.userInfo.business,
					"mobile": this.userInfo.mobile,
					"avatar_id": this.userInfo.avatar_id,
					"avatar_url": this.userInfo.avatar_img,
					"mobile_code": "",
				}
				orcInfo.isToWrite = this.isToWrite;
				uni.setStorageSync("orcInfo",orcInfo)
				uni.navigateTo({
					url: "/pages/news/caigou/notice2"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.notice{
	padding-bottom: 150rpx;
	&-bd{
		width: 700rpx;
		margin: 20rpx auto;
		font-size: 28rpx;
		color: #333333;
		line-height: 48rpx;
		text-align: justify;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 40rpx 40rpx;
		box-sizing: border-box;
		.a{
			padding: 20rpx 0;
			.title{
				font-size: 36rpx;
				color: #222222;
				text-align: center;
				margin-top: 30rpx;
			}
			.desc{
				width: 450rpx;
				font-size: 28rpx;
				color: #666666;
				line-height: 48rpx;
				text-align: center;
				margin: 0 auto;
				margin-top: 20rpx;
			}
			image{
				width: 189rpx;
				height: 166rpx;
				display: block;
				margin: 0 auto;
				margin-top: 80rpx;
			}
		}
	}
	&-fd{
		height: 140rpx;
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 22;
		background-color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
		.btn{
			width: 662rpx;
			height: 90rpx;
			line-height: 90rpx;
			background: #F34A40;
			border-radius: 90rpx;
			text-align: center;
			font-size: 32rpx;
			color: #FFFFFF;
			&-on{
				background-color: #ccc;
			}
		}
	}
}
</style>
