<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="url"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: "",
				webviewStyles: {
					progress: {
						color: '#F07423'
					}
				},
				type: "",
			};
		},
		onLoad(param) {
			this.type = param.type;
			let title = ""
			if (this.type == 1) {
				title = "用户使用协议"
			} else if (this.type == 2) {
				title = "隐私协议"
			} else if (this.type == 3) {
				title = "入驻协议"
			}
			uni.setNavigationBarTitle({
				title: title
			})
			this.webviewStyles.progress.color = getApp().globalData.color1;
			this.queryProtocolConfigView();
		},
		methods: {
			async queryProtocolConfigView() {
				let res = await this.$myRequest({
					url: "/project/queryProtocolConfigView",
					data: {},
				})
				if (res.data.success) {
					const curryUrl =  this.curry("/hybrid/html/web/viewer.html?file=")
					if (this.type == '1') { //使用协议
						this.url = curryUrl(res.data.single.userUseProtocol);
					} else if (this.type == '2') { //隐私协议
					    this.url = curryUrl(res.data.single.userPrivacyProtocol);
					} else if (this.type == '3') { //业主注册协议
						this.url = curryUrl(res.data.single.ownerRegistProtocol);
					}
				}
			},
			curry(baseUrl){
				return function(url){
					let index = url.lastIndexOf('.');
					if(url.substring(index+1).indexOf('pdf')>-1){
						return baseUrl+url;
					}else{
						return url;
					}
				}
			}
		}
	}
</script>

<style lang="scss">

</style>
