<script>//com.cityexpress1688.ptsj
	import {
		changeLanguages
	} from '@/pages/api/login';
	import api from "@/pages/api/api.js"
  export default {
	  data() {
	    	return {
	  		audioObj:null
	  	}
	  },
	  globalData:{
	  	_i18n:{},
	  	$t:{},
		token:'',
		imViewOpen:false
	  },
    onLaunch: function() {
      console.log('App Launch');
	  this.globalData._i18n=this.$i18n;
	  this.globalData.$t=str=>this.$t(str);
	
	  let systemInfo = uni.getSystemInfoSync();
	  var isAndroid = systemInfo.platform.toLowerCase() === 'android';
	  var language = uni.getStorageSync('language');
	  if(''==language||null==language||undefined==language){
	  		  uni.setStorageSync('language',"zh-Hant");
	  		  uni.setLocale('zh-Hant');
			  if(!isAndroid){
			  	this.$i18n.locale = 'zh-Hant';
			  }
	  		  this.uploadLanguagesSet('zh-Hant');
	  }
	  else{
	  		  uni.setLocale(language);
			  if(!isAndroid){
			  	this.$i18n.locale = language;
			  }
	  		  this.uploadLanguagesSet(language);
	  }
	  uni.onPushMessage((res) => {
	  	console.log("收到推送消息：",res) //监听推送消息
		if(res.type=='click'){
			var content=res.data.content;
			plus.runtime.setBadgeNumber(0);
			if(content.indexOf("发起通话")!=-1){
				
				return
			}
			plus.runtime.setBadgeNumber(0);
			return
		}
		if(res.type=='receive'){
			var content=res.data.content;
			if(content.indexOf("发起通话")!=-1){
				plus.runtime.setBadgeNumber(0);
				if(this.globalData.imViewOpen==false){
					
				}
				return
			}
			if(content.indexOf("通话")!=-1){
				plus.runtime.setBadgeNumber(0);
				return;
			}
			plus.runtime.setBadgeNumber(0);
			
			if(content.indexOf("新订单")!=-1){
				this.audioObj.play();
			}
			uni.createPushMessage({
				content:res.data.content,
				success: (res) => {
					console.log(res);
				},
				fail(er) {
				}
			});
		}
	  })
	  
	  this.audioObj=uni.createInnerAudioContext();
	  this.audioObj.src='static/nyxddl.mp3';
	  
    },
    onShow: function() {
      console.log('App Show')
	  // uni.onPushMessage((res) => {
		 //  console.log(res);
	  // })
    },
    onHide: function() {
      console.log('App Hide')
    },
	methods:{
		async uploadLanguagesSet(lang){
			var userId = uni.getStorageSync('userId');
			if(lang=='yuenan'){
				lang='vi';
			}
			if(lang=='zh-Hans'){
				lang='zh-CN';
			}
			if(lang=='zh-Hant'){
				lang='zh-TW';
			}
			console.log("changeLanguages");
			api('changeLanguages',{
				id:userId,
				lang:lang
			},
			res=>{
				console.log(res)
				
			},failc=>{
				//console.log('getadvertis----',failc)
				
			});
			
		},
	},
  }
</script>

<style>
  .container {
    padding: 15px;
  }
/*
  button {
    margin-bottom: 15px;
  }
  */
 .ztextfontB1{
 	 font-size: 36rpx;
 }
 .ztextfontB2{
 	 font-size: 34rpx;
 }
 .ztextfontB3{
 	 font-size: 32rpx;
 }
 .ztextfontB4{
 	 font-size: 30rpx;
 }
 .ztextfontB5{
 	 font-size: 28rpx;
 }
 .ztextfontS1{
 	 font-size: 26rpx;
 }
 .ztextfontS2{
 	 font-size: 24rpx;
 }
 .ztextfontS3{
 	 font-size: 22rpx;
 }
 
 .textfontB1{
 	 font-size: 36rpx;
 }
 .textfontB2{
 	 font-size: 34rpx;
 }
 .textfontB3{
 	 font-size: 32rpx;
 }
 .textfontB4{
 	 font-size: 30rpx;
 }
 .textfontB5{
 	 font-size: 28rpx;
 }
 .textfontS1{
 	 font-size: 26rpx;
 }
 .textfontS2{
 	 font-size: 24rpx;
 }
 .textfontS3{
 	 font-size: 22rpx;
 }
 /*每个页面公共css */
 .content{
 	display: flex;
 	flex-direction: column;
 	width: 94%;
 	margin-left: 3%;
 	background-color: white;
 	border-radius: 16rpx;
 	box-shadow: 0rpx 0rpx 10rpx 0rpx lightgray;
 }
 
 .content4{
 	display: flex;
 	flex-direction: column;
 	width: 92%;
 	margin-left: 4%;
 }
 
 .contentInRowL{
 	display: flex;
 	flex-direction: row;
 	justify-content: flex-start;
 }
 
 .contentInRowC{
 	display: flex;
 	flex-direction: row;
 	justify-content: center;
 	align-items: center;
 }
 .contentInRowR{
 	display: flex;
 	flex-direction: row;
 	justify-content: flex-end;
 }
 .contentInRowS{
 	display: flex;
 	flex-direction: row;
 	align-items: center;
 	justify-content: space-between;
 }
 
 .contentColumn{
 	display: flex;
 	flex-direction: column;
 }
 
 .contentColumnC{
 	display: flex;
 	flex-direction: column;
 	align-items: center;
 	justify-content: center;
 }
 .text1row{
 	overflow: hidden;
 	text-overflow: ellipsis;
 	/* #ifndef APP-PLUS-NVUE */
 	display: -webkit-box;
 	-webkit-line-clamp: 1;
 	-webkit-box-orient: vertical;
 	/* #endif */
 }
 .text2row{
 	overflow: hidden;
 	text-overflow: ellipsis;
 	/* #ifndef APP-PLUS-NVUE */
 	display: -webkit-box;
 	-webkit-line-clamp: 2;
 	-webkit-box-orient: vertical;
 	/* #endif */
 }
</style>
