<script>
	import StringUtil from '@/utils/StringUtil.js'
	var md5 = require("./utils/md5.js");
	export default {
		data() {
			return {
				param: null
			};
		},
		onLaunch: function(e) {
			// uni.setEnableDebug({
			//     enableDebug: true
			// })
			
			//更新版本
			const updateManager = uni.getUpdateManager();
			
			updateManager.onCheckForUpdate(function (res) {
			  // 请求完新版本信息的回调
			  console.log("是否有新版本：",res.hasUpdate);
			});
			
			updateManager.onUpdateReady(function (res) {
			  uni.showModal({
			    title: '更新提示',
			    content: '新版本已经准备好，是否重启应用？',
			    success(res) {
			      if (res.confirm) {
			        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
			        updateManager.applyUpdate();
			      }
			    }
			  });
			
			});
			
			updateManager.onUpdateFailed(function (res) {
			  // 新的版本下载失败
			});
			
			this.param = e;
			this.execParam();
			this.globalData.checkIsIPhoneX();
			
			this.getOpenId();
		},
		onShow: function(e) {
			this.param = e;
			this.execParam();
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			execParam() {
				if (this.param == null || this.param.referrerInfo == null) return;
				let path = this.param.path;
				if (StringUtil.startEqualsIgnoreCase(path, 'pages/pages/')) {
					path = StringUtil.replace(path, 'pages/pages/', 'pages/');
					if (StringUtil.eqlObjIgnoreCase(path, '/pagesM/pages/goods_des')) {
						let query = this.param.query;
						if (query == null || query.id == null || parseInt(query.id) == null || parseInt(query.id) <= 0) {
							path = `pages/life`;
						} else {
							path = `pages/life?type=share&id=${query.id}&path=${path}`;
						}
					}
					this.param.path = path;
					uni.reLaunch({ url: path });
					return;
				}
				this.param.path = path;
				let reqParam = this.param.referrerInfo.extraData;
				wx.setStorageSync('reqParam', reqParam);
				this.param.referrerInfo = null;
			},
			getOpenId() {
			  var that = this;
			    uni.login({
			      success: res => {
			        let params = {};
			        params['js_code'] = res.code;
					params['name'] = 'community';
					params['app_type'] =1;
			        // let operation = 'miniprogram/getOpenid'; //发起请求
			        that.$http.getOpenid(params).then(res =>{
			          //获取成功
			          if (res.data.result_code == 1) {
						  console.log("获取openid成功")
			            //openid存入缓存
			            uni.setStorageSync("openid", res.data.openid);
						uni.setStorageSync("appletType", res.data.appletType);
						that.$u.vuex('vuex_appletType',res.data.appletType)
			          } else {
			            that.globalData.oneFailHint(res.data.result_msg);
			          }
			        }
					);
			      }
			    });
			}
		},
		globalData: {
			//机构id
			org_id: "1",
			token: "j2qctr89u1xfmbjkp69hegfmqhwquycw",
			//对接后台的api地址
			apiurl: "http://192.168.1.69/app-service/app/",
			//远程的
			// apiurl: "https://community.58fo.com/api/app/",
			// apiurl: "http://192.168.1.19:9082/app/",
			// apiurl: "http://25d3f66612.zicp.vip/wuye/app-gateway/app/",
			// apiurl: "http://192.168.1.218:9082/app/",
			// apiurl: "http://192.168.1.244:9082/app/",
			member: null,
			//用户信息--后台
			userInfo: null,
			//小程序用户信息,
			room_list: null,
			//会员的房屋列表 
			own_room_list: null,
			//业主身份的房子
			device_list: null,
			//会员的授权设备列表
			anyHousePass: false, //判断是否是第二次认证,
			//封装request请求
			/**
			 * params 参数
			 * operation 操作
			 * callBack 回调函数
			 */
			postRequest: function (params, operation, callBack) {
			  let that = this; //公共参数
			  params['org_id'] = that.org_id;
			  params['token'] = that.token; 
			  // uni.showLoading({
			  //   mask: true
			  // });
			
			  let jsonStr = JSON.stringify(params); //数据md5签名
			
			  let dataSign = md5.hex_md5(jsonStr);
			  uni.request({
			    url: that.apiurl + operation,
			    method: 'POST',
			    header: {
			      'content-type': 'application/json',
			      'data-sign': dataSign
			    },
			    data: jsonStr,
			    success: function (res) {
			      // console.info(res.header['data-sign']);
			      // console.info(md5.hex_md5(JSON.stringify(res.data)));
			      // uni.hideLoading(); 
			
			      callBack(res);
			    },
			    fail: function (res) {
			      uni.hideLoading();
			      uni.showModal({
			        title: '警告',
			        content: '网络异常' + res.errMsg,
			        showCancel: false,
			        confirmText: '确认'
			      });
			    }
			  });
			},
			postRequestAsync: function (params,operation) {
			  let that = this; //公共参数
			  params['org_id'] = that.org_id;
			  params['token'] = that.token; 
			  let jsonStr = JSON.stringify(params); //数据md5签名
			  let dataSign = md5.hex_md5(jsonStr);
			   return new Promise((resolve,reject)=>{
				  uni.request({
					  url: that.apiurl + operation,
					  method: 'POST',
					  header: {
						'content-type': 'application/json',
						'data-sign': dataSign
					  },
					  data: jsonStr,
					  success: (res)=>{
						  resolve(res)
					  },
					  fail: (err)=>{
						  uni.hideLoading();
						  uni.showModal({
							title: '警告',
							content: '网络异常' + res.errMsg,
							showCancel: false,
							confirmText: '确认'
						  });
					  }
				  })
			  })
			},
			
			//上传文件
			uploadBase64: function (base_64_str, is_need_md5, callback) {
			  let that = this;
			  let params = {};
			  params['base_64_str'] = base_64_str;
			  params['is_need_md5'] = is_need_md5; //公共参数
			
			  params['org_id'] = that.org_id;
			  params['token'] = that.token;
			  let operation = 'applyUser/uploadBase64File';
			  that.postRequest(params, operation, function (res) {
			    if (res.data.result_code == 1) {
			      callback(res);
			    } else {
			      that.autoFailHint(res.data.result_msg);
			    }
			  });
			},
			
			/**
			 * 失败提示方法方法--单按钮--手动点击关闭
			 */
			oneFailHint: function (result_msg, callBack) {
			  uni.showModal({
			    content: result_msg,
			    showCancel: false,
			    confirmText: '确认',
			    success: function (res) {
			      if (res.confirm) {
			        if (callBack) {
			          callBack();
			        }
			      }
			    }
			  });
			},
			
			/**
			 * 失败提示方法方法--双按钮--手动点击关闭
			 */
			twoFailHint: function (result_msg, callBack) {
			  uni.showModal({
			    content: result_msg,
			    confirmText: '确认',
			    success: function (res) {
			      if (res.confirm) {
			        if (callBack) {
			          callBack();
			        }
			      }
			    }
			  });
			},
			
			/**
			  * 失败提示方法方法--自动关闭
			  */
			autoFailHint: function (result_msg, callBack) {
			  uni.showToast({
			    title: result_msg,
			    icon: 'none',
			    duration: 2000,
			    success: function () {
			      if (callBack) {
			        callBack();
			      }
			    }
			  });
			},
			
			/**
			* 提示用户身份注册
			*/
			footaddmore: function () {
			  uni.showModal({
			    title: '提示',
			    content: ' 请先完成注册',
			    //cancelText:'去绑定',
			    cancelText: '取消',
			    confirmText: '去注册',
			    success: function (res) {
			      if (res.confirm) {
			        //跳转到认证页面
			        uni.navigateTo({
			        	url:"/pages/register/register"
			        })
			      } else {//res.cancel
			        //绑定界面--暂时不用
			        // wx.navigateTo({
			        //   url: '/pages/binding/binding',
			        // })
			      }
			    }
			  });
			},
			//房屋信息完善
			choosePlot: function () {
			  uni.showModal({
			    title: '提示',
			    content: ' 未获取到房屋信息，是否去完善',
			    //cancelText:'去绑定',
			    cancelText: '取消',
			    confirmText: '去完善',
			    success: function (res) {
			      if (res.confirm) {
			        console.log('用户点击了确认-去完善'); //跳转到认证页面
					if(!this.$isEmpty(this.globalData.totalStep)){
						this.globalData.totalStep=2
					}
			        uni.navigateTo({
			          url: "/pages/auth/auth"
			        });
			      }
			    }
			  });
			},
			//检测是否是iphonex以上的机型
			checkIsIPhoneX: function () {
			  const self = this;
			  uni.getSystemInfo({
			    success: function (res) {
			      // 根据 model 进行判断
			      if (res.model.search('iPhone X') != -1) {
			        //self.isIPX = true
			        uni.setStorageSync("isIPX", true);
			      } else {
			        uni.setStorageSync("isIPX", false);
			      }
			    }
			  });
			},
		},
	}
</script>

<style lang="scss">
	// 引入样式
	@import  '@/assets/css/app.scss';
	@import "uview-ui/index.scss";
	@import "@/assets/css/main.css";
	@import "@/assets/css/icon.css";
	@import "@/assets/css/app.css";
	
	
	// 社区样式 begin
	navigator-hover {
	  background-color: rgba(0, 0, 0, 0.1);
	  opacity: 0.7;
	}
	
	input {
	  font-family: "PingFang SC",
	                 "Hiragino Sans GB",
	                 "Heiti SC",
	                 "Microsoft YaHei",
	                 "WenQuanYi Micro Hei",
	                 sans-serif;
	}
	
	.fix_nav_wp-IPX {
	padding-bottom:68rpx;
	
	}
	
	.mt20 {
	  margin-top: 20rpx;
	}
	
	.submit_btn {
	  position: fixed;
	  bottom: 0;
	  left: 0;
	  padding: 0rpx 0rpx;
	  width: 100%;
	  box-sizing: border-box;
	  background: #fff;
	}
	
	.ar_btn {
	  background: $base-btn-color;
	  font-size: 32rpx;
	  color: #fff;
	  // border-radius: 10rpx;
	  margin: 0rpx 0rpx;
	  padding: 0rpx 60rpx;
	  height: 100rpx;
	  line-height: 100rpx;
	}
	/* 小图标 */
	@font-face {
	  font-family: 'iconfont';  /* project id 930679 */
	  src: url('//at.alicdn.com/t/font_930679_y7aw8dju2ha.eot');
	  src: url('//at.alicdn.com/t/font_930679_y7aw8dju2ha.eot?#iefix') format('embedded-opentype'),
	  url('//at.alicdn.com/t/font_930679_y7aw8dju2ha.woff') format('woff'),
	  url('//at.alicdn.com/t/font_930679_y7aw8dju2ha.ttf') format('truetype'),
	  url('//at.alicdn.com/t/font_930679_y7aw8dju2ha.svg#iconfont') format('svg');
	}
	
	.iconfont {
	  font-family: "iconfont" !important;
	  font-size: 16px;
	  font-style: normal;
	  -webkit-font-smoothing: antialiased;
	  -moz-osx-font-smoothing: grayscale;
	}
	.icon-lianxigray:before { content: "\e61b"; }
	
	.icon-dispirited:before { content: "\e650"; }
	
	.icon-cha:before { content: "\e601"; }
	
	.icon-arrow-left:before { content: "\e604"; }
	
	.icon-mima:before { content: "\e603"; }
	
	.icon-xiaoxi:before { content: "\e633"; }
	
	.icon-shuoming:before { content: "\e605"; }
	
	.icon-icon-test:before { content: "\e626"; }
	
	.icon-shiming:before { content: "\e6d4"; }
	
	.icon-dingwei:before { content: "\e822"; }
	
	.icon-yemian:before { content: "\e659"; }
	
	.icon-icon-test1:before { content: "\e600"; }
	
	.icon-user:before { content: "\e602"; }
	
	.flex {
	  display: -webkit-flex;
	  display: flex;
	  width: 100%;
	}
	
	/*  底部悬浮导航  */
	
	.fix_nav_wp {
	  margin-top: 110rpx;
	  height: 110rpx;
	  position: fixed;
	  left: 0;
	  bottom: 0;
	  background: #fff;
	  z-index: 10;
	}
	
	.fix_nav_wp .nav_link {
	  flex: 1;
	}
	
	.fix_nav_wp button {
	  height: 110rpx;
	  display: flex;
	  justify-content: space-between;
	  align-items: center;
	  padding: 0;
	  font-size: 22rpx;
	  flex-direction: column;
	  color: #999;
	  position: relative;
	}
	
	.fix_nav_wp .tip_tip {
	  position: absolute;
	  right: 25rpx;
	  top: 5rpx;
	  min-width: 28rpx;
	  line-height: 32rpx;
	  height: 32rpx;
	  padding: 0 8rpx;
	  color: #fff;
	  background: #f00;
	  border-radius: 50em;
	  border: 1rpx solid #fff;
	}
	
	.fix_nav_wp .nav_link .iconfont {
	  height: 60rpx;
	  font-size: 48rpx;
	  line-height: 80rpx;
	  color: #c4c8cc;
	}
	
	.fix_nav_wp .nav_link .plus_wp {
	  width: 120rpx;
	  height: 120rpx;
	  margin-top: -60rpx;
	}
	
	.fix_nav_wp .nav_link  image {
	  width: 120rpx;
	  height: 120rpx;
	}
	
	.fix_nav_wp .nav_link .txt {
	  height: 70rpx;
	  line-height: 60rpx;
	  color: #444;
	  font-size: 28rpx;
	}
	
	.fix_nav_wp .nav_link .iconfont {
	  color: #444;
	}
	
	
	
	.fix_nav_wp .nav_link .del_ico {
	  display: block;
	}
	
	.fix_nav_wp .nav_link .cur_ico {
	  display: none;
	}
	
	.fix_nav_wp .nav_link.current .del_ico {
	  display: none;
	}
	
	.fix_nav_wp .nav_link.current .cur_ico {
	  display: block;
	  color: $base-btn-color;
	}
	
	.fix_nav_wp .nav_link .txt_fb {
	  line-height: 60rpx;
	}
	
	.fix_nav_wp .nav_link .mp_ico {
	  font-size: 50rpx;
	  line-height: 80rpx;
	}
	
	.fix_nav_wp .nav_link .xiaox_ico {
	  font-size: 64rpx;
	  line-height: 70rpx;
	}
	
	.fix_nav_wp .nav_link .my_ico {
	  font-size: 56rpx;
	}
	
	.fix_nav_wp .on_cor .del_ico, .fix_nav_wp .on_cor .txt {
	  color: $base-btn-color;
	}
	
	/* 清楚按钮的默认样式  */
	
	.defalut_btn {
	  background: transparent;
	  border: none;
	  overflow: visible;
	  padding-left: 0;
	  padding-right: 0;
	  margin-left: 0;
	  margin-right: 0;
	  border-radius: 0;
	}
	
	.defalut_btn:after {
	  display: none;
	}
	
	.text-primary {
	  color: $base-btn-color;
	}
	
	.submit_btn1 {
	  margin: 60rpx 0 20rpx;
	  padding: 0rpx 80rpx;
	  width: 100%;
	  box-sizing: border-box;
	}
	//社区样式 end
	
	// 商城
	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
	
	.pageBg {
		background: #f2f2f2;
		height: auto;
		min-height: 100vh;
	}
	.one_line_ellipsis {
		display: -webkit-box;
		overflow: hidden;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	.two_line_ellipsis {
		display: -webkit-box;
		overflow: hidden;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	.three_line_ellipsis {
		display: -webkit-box;
		overflow: hidden;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
	}
</style>
