<template>
	<view>

	</view>
</template>

<script>
	var wv = [];
	export default {
		name: "initial",
		props: {
			showModal: {
				type: String,
				default: '0'
			}
		},
		data() {
			return {
				userList: [],
				userListshow: [],
				list: [],
				lastUserName: '',
				userid: '',
				identify: '',
				bool: '',
			}
		},

		created() {
			this.getUserList();
		},
		computed: {
			sisStageIp: function() {
				return this.$store.state.wholeSituationBackStageIp;
			},
			sisStagePort: function() {
				return this.$store.state.wholeSituationBackStagePort;
			},
			backStageIp: function() {
				return this.$store.state.GlobalLocalIp;
			},
			backStagePort: function() {
				return this.$store.state.GlobalLocalPort;
			},
			windpowerstationNameToId: function() {
				return this.$store.state.windpowerstationNameToId;
			},
		},
		methods: {
	
			getUserList() {

				let im_show =uni.getStorageSync('im_show');
				if (im_show != "1") {
					this.lastUserName = uni.getStorageSync('gyeeusername');
					this.userid = uni.getStorageSync('userid');

					let _this = this;
					uni.request({
						url: 'http://' + this.sisStageIp + ':' + this.sisStagePort + '/GyeeuserController/selectUserList',
						data: {},
						method: 'GET',
						success: function(res) {
							_this.userList = [];

							for (var i = 0; i < res.data.length; i++) {

								if (res.data[i].id != _this.userid) {

									var pages = getCurrentPages();
									var page = pages[pages.length - 1];
									let webView = plus.webview.create("", "webview" + res.data[i].id, {
										plusrequire: "none", //禁止远程网页使用plus的API，有些使用mui制作的网页可能会监听plus.key，造成关闭页面混乱，可以通过这种方式禁止
										'uni-app': 'none', //不加载uni-app渲染层框架，避免样式冲突
										top: uni.getSystemInfoSync().statusBarHeight + 44 //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的，可以继续降低TOP值
									})

									let url = "https://" + _this.backStageIp + ":" + _this.backStagePort + "/websocket/usercontroller/view?send=" +
										_this.userid + "&receive=" + res.data[i].id + "&sendname=" + _this.lastUserName + "&receivename=" + res.data[
											i].nickname;
									webView.loadURL(url)
									var currentWebview = page.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效，非v3编译模式使用this.$mp.page.$getAppWebview()
									currentWebview.append(webView); //一定要append到当前的页面里！！！才能跟随当前页面一起做动画，一起关闭
									//wv.setStyle({top:70,height:height});
									
									 setTimeout(function() {
									          
									        }, 1000);//如果是首页的onload调用时需要延时一下，二级页面无需延时，可直接获取
									webView.hide();

									wv.push(webView)

								}

							};


						},
						fail: () => {
							_this.tips = '网络错误，小程序端请检查合法域名';
						},
					});
					
					 uni.setStorageSync('im_show','1');
					
				}else
				{
					var pages = getCurrentPages();
					var page = pages[pages.length - 1];
					var currentWebview = page.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效，非v3编译模式使用this.$mp.page.$getAppWebview()
					
					for (var i = 0; i < wv.length; i++) {
						
						let webView = wv[i];
						
						currentWebview.append(webView); //一定要append到当前的页面里！！！才能跟随当前页面一起做动画，一起关闭
						
					}
				}


			},
			childMethod(id, bool, state) {
				console.log(id);
				this.identify = id;
				this.bool = bool;
				//this.getUserList();
				let webview;
				for (var i = 0; i < wv.length; i++) {
					if (wv[i].id == "webview" + id) {

						webview = wv[i];
						let url = webview.getURL();
						if (bool != null) {
							if (bool == 1) {

								if (url.indexOf("/view?") < 0) {
									url = url.replace("/viewoffline?", "/view?");
									webview.loadURL(url);
								}
							} else {
								if (url.indexOf("/viewoffline?") < 0) {
									url = url.replace("/view?", "/viewoffline?");
									webview.loadURL(url);
								}
							}
						}


						if (state == 1) {

							webview.show()
						} else {
							webview.hide();
						}
						break;
					}
				}

			}

		}
	}
</script>

<style>

</style>
