<template>
	<view class="content">
		<view class="top">
			<view class="topLeft">
				<image src="/static/images/wx.png" mode="" class="carLogo"></image>
			</view>
			<view class="topRight">
				<view class="brand">{{info.carModelInfo.brand}}</view>
				<view class="carModel">{{info.title}}</view>
			</view>
		</view>
		
		<view class="cont">
			<view class="line" v-for="(item,index) in info.supplierlist">
				<view class="lineLeft">
					<view class="lineCK">
						<checkbox-group>
							<label>
								<checkbox value="cb" :checked="true" />
							</label>
						</checkbox-group>
					</view>
					<view class="nameBox">
						<view class="name">{{item.supplierName}}</view>
						<view class="jingying">经营品牌：{{item.brands}}</view>
					</view>
				</view>
				<view class="lineRgiht">
					<view>
						<image class="lineRgihtIMg" src="/static/images/icon_phone@2x.png" mode=""></image>
					</view>
					<view>
						<image @click="goIm(item)"  class="lineRgihtIMg" src="/static/images/chat.png" mode=""></image>
					</view>
				</view>
			</view>
		
		</view>
		
		<view class="qunfa" @click="qunfa">
			一键群发
		</view>
		
	</view>
</template>

<script>
	import EmojiDecoder from '../lib/EmojiDecoder';
	import restApi from '../lib/restapi';
	import {formatDate} from '../lib/utils';
	import RecorderManager from '../lib/RecorderManager';
	
	const IMAGE_MAX_WIDTH = 200;
	const IMAGE_MAX_HEIGHT = 150;
	const recorderManager = new RecorderManager();
	const GoEasy = uni.$GoEasy;
	const GRTC = uni.$GRTC;
	export default {
		data() {
			return {
				vin: 'JHMCM56557C404453',
				list:[],
				info:'',
				currentUser:'',
			}
		},
		onLoad(opt) {
		  var token=opt.token
		  console.log(token)
		   uni.setStorageSync('token', token);
          this.vinSupplier()
		  this.imLoginUrl()
		},
		methods: {
		   qunfa(){
			   uni.setStorageSync('supplierlist', this.info.supplierlist);
			   uni.navigateTo({
			   	url:'qunfa'
			   })
		   },
		   goIm(item){
			   uni.setStorage({
			   		key: 'friend',
			   		data: item,
			   		 success: function () {	
			   				uni.navigateTo({
			   				  url: './privateChat?to=' + item.id
			   				});	
			   		 }
			   });
		   },
           vinSupplier(){
			   this.$http('imSys/vinSupplier', {
			      vin:this.vin,
			     },'GET').then(res => {
			    	  //console.log(res)	
			   		  this.info=res.data[0]	  
			     }) 
		   },
		   imLoginUrl(){
			   this.$http('imSys/imLoginUrl', {
			      token:this.token,
			     },'POST').then(res => {
			    	 // console.log(res)	
			   		  var users={
						  userId:res.data.userId,
						  name:res.data.users.name,
						  avatar:'',
					  }
					  this.currentUser=users
					  this.connectGoEasy()
					 uni.setStorageSync('users', users);
			     }) 
		   },
		   connectGoEasy(){
			   console.log(this.currentUser)
			   this.currentUser.id="2C3E3A5C-D449-4439-842F-8E1C5C9EF91E"
			   uni.setStorageSync('currentUser', this.currentUser);
			   GoEasy.connect({
			     id: this.currentUser.id,
			     data: {
			       name: this.currentUser.name,
			       avatar: this.currentUser.avatar
			     },
			     onSuccess: () => {
			       console.log('GoEasy connect successfully.')
			     },
			     onFailed: (error) => {
			       console.log('Failed to connect GoEasy, code:' + error.code + ',error:' + error.content);
			     },
			     onProgress: (attempts) => {
			       console.log('GoEasy is connecting', attempts);
			     }
			   });
		   }
		}
	}
</script>

<style scoped>
.content{
	min-height: 100vh;
	background: #F4F5F7;
}
	.carLogo{
		width: 80rpx;height: 80rpx;
	}
.top{
	padding: 24rpx;
	display: flex;
	background: #FFF;
}
.topRight{
	padding-left: 10rpx;
}
.brand{
	font-size: 28rpx;
	color: #333;
}
.carModel{
	font-size: 26rpx;
	padding-top: 8rpx;
	color: #999;
}
.lineRgihtIMg{
	width: 40rpx;
	height: 40rpx;
}
.cont{
	margin-top: 20rpx;
	background: #FFF;
}
.line{
	display: flex;justify-content: space-between;
	padding: 20rpx;
	border-bottom: 1px solid #F4F5F7;
}
.lineLeft{
	display: flex;
}
.nameBox{
	padding-left: 10rpx;
}
.name{
	font-size: 30rpx;color: #333;
}
.jingying{
	font-size: 26rpx;color: #999;padding-top: 10rpx;
}
.lineCK{
	display: flex;
	align-items: center;
}
.qunfa{
	width: 650rpx;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	background: #3F90F7;
	color: #ffffff;
	font-size: 30rpx;
	border-radius: 10rpx;
	margin: 0 auto;
	margin-top: 100rpx;
}
</style>
