Commit abb452f9 by 施宇

Merge branch 'master' of http://119.23.72.7/shiyu/icsales

parents 1a6a63f1 ee390f72
......@@ -69,7 +69,7 @@ return array(
'uploadresult' => 'Home/Index/uploadresult',
'integral' => 'Home/Index/integral',
'notice' => 'Home/Index/notice',
'chat' => 'Home/Index/chat'
'chat' => 'Home/Index/chat',
'hotgoods' => 'Home/Cms/getHotGoods',
),
);
\ No newline at end of file
......@@ -32,7 +32,7 @@ class BaseController extends Controller
} else {
return $this->apiReturn(7004, '未找到数据');
}
}
}
/**
* 统一格式返回
......
<?php
namespace Home\Controller;
use Home\Controller\BaseController;
class CmsController extends BaseController
{
// 获取热门商品
public function getHotGoods()
{
$datas = $this->apiBaseCache('pc_hot_goods', '', 5); // 热门商品
return $this->jsonReturn(0, '', $datas['data']);
}
/**
* 统一格式返回
* @param integer $code [description]
* @param string $msg [description]
* @param array $extend [description]
* @return [type] [description]
*/
protected function jsonReturn($code = 0, $msg = '', $extend = array())
{
$data = array(
'err_code' => $code,
'err_msg' => $msg,
'data' => $extend,
);
if(isset($_GET['callback']) && !empty($_GET['callback'])){
echo $_GET['callback'].'('.json_encode($data).')';exit;
}else{
echo json_encode($data);exit;
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ class IndexController extends BaseController
public function _initialize()
{
parent::_initialize();
if (!cookie('token') && ACTION_NAME != 'login' && ACTION_NAME != 'register' && ACTION_NAME != 'index' && ACTION_NAME != 'indexsearch') {
if (!cookie('token') && ACTION_NAME != 'login' && ACTION_NAME != 'register' && ACTION_NAME != 'index' && ACTION_NAME != 'indexsearch' && ACTION_NAME != 'forget') {
$this->redirect('/login');
}
}
......
......@@ -14,192 +14,138 @@
<div class="right_content inquiry_detail_content">
<div class="content">
<div class="nav_title">
询报价 > 我的询价 > 询价详情 STM32F103ZET6
<span class="fr">2019-05-22 15:35</span>
</div>
<div class="goods_detail clr">
</div>
<div class="bj_detail">
</div>
<div class="pagination-with" id="pagination"
style="text-align: right;margin-top: 25px;display:none"></div>
</div>
</div>
</div>
</div>
<include file="public/foot" />
<script src="__PUBLIC__/js/quoteprice/inquirydetail.js"></script>
<script type="text/html" id="navTpl">
<!-- 导航的详情 -->
询报价
>
我的询价
>
询价详情
{{d.goods_name}}
<span class="fr">{{layui.util.toDateString(d.add_time * 1000)}}</span>
</script>
<script type="text/html" id="detailTpl">
<!-- 商品详情 -->
{{# if(d['goods_images']){ }}
<img src="{{d.goods_images}}" alt="" class="fr xj_img">
{{# } else { }}
<img src="__PUBLIC__/images/defaultgood.png" alt="" class="fr xj_img">
{{# } }}
<div class=" goods_desc boxsiz">
<div class="title">
<h3 class="bold fl">{{d.goods_name}}</h3>
<div class="fr">
{{# if(d['audit_status'] == 1){ }}
{{# if(d['status'] == 1){ }}
<span class="mark lineBlock zs"></span><span class="text">展示中</span>
{{# } else { }}
<span class="mark lineBlock xj"></span><span class="text">已下架</span>
{{# } }}
{{# } else { }}
<span class="mark lineBlock jy"></span><span class="text">禁用中</span>
{{# } }}
</div>
</div>
<div class="desc inquiry_desc" style="margin-right:224px">
<div class="brand fl boxsiz ellipsis">
品牌:<span> {{d.brand_name}}</span>
</div>
<div class="fz fl boxsiz ellipsis">
封装:<span> {{d.encap}}</span>
</div>
<div class="price fl boxsiz"> 接受价:
{{# if(!d.price){ }}
<span></span>
{{# } else { }}
<span class="red">
{{# if(d.currency == 1){ }}
{{# } else { }}
$
{{# } }}
{{d.price}}
</span>
{{# } }}
</div>
<div class="num fl boxsiz ellipsis"> 数量:<span class="bold"> {{d.number}} PCS</span></div>
<div class="hq fl boxsiz ellipsis"> 货期:<span>{{d.delivery_time}}</span></div>
<div class="bz fl boxsiz ellipsis"> 备注:<span> {{d.remark||'--'}}</span></div>
</div>
</div>
</script>
<script type="text/html" id="bjTpl">
<div class="bj_title">
<span class="lineBlock"></span>
<b>收到的报价</b>
<b class="bj_num">{{d.length}}</b>
</div>
<div class="bj_lists">
{{# layui.each(d, function(index, item){ }}
<div class="bj_item clr">
<div class="item_right fr boxsiz">
<div class="top">
<!-- <div class="top_right icon iconfont iconjuxing2 fr"></div> -->
<div class="top_left boxsiz ellipsis" style="padding-right:0">
<span class="lineBlock mark">报价</span>
<span class="name bold">{{item.company_name||'--'}}</span>
</div>
</div>
<div class="center">
<div class="center_left boxsiz clr" style="padding-right:0">
{{# if(item.auth_type!==""){ }}
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
{{# if(item.auth_type==0){ }}
未认证
{{# } }}
{{# if(item.auth_type==1){ }}
个人认证
{{# } }}
{{# if(item.auth_type==2){ }}
企业认证
{{# } }}
<img src="__PUBLIC__/images/test.jpg" alt="" class="fr">
<div class=" goods_desc boxsiz">
<div class="title">
<h3 class="bold fl">STM32F103ZET6</h3>
<div class="fr">
<span class="mark lineBlock"></span><span class="text">展示中</span>
</div>
</div>
{{# } }}
{{# if(item.company_type!==""){ }}
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
{{# if(item.company_type==1){ }}
贸易商
{{# } }}
{{# if(item.company_type==2){ }}
代理商
{{# } }}
{{# if(item.company_type==3){ }}
原厂
{{# } }}
{{# if(item.company_type==4){ }}
制造商
{{# } }}
{{# if(item.company_type==5){ }}
个人用户
{{# } }}
<div class="desc inquiry_desc">
<div class="brand fl boxsiz ellipsis">
品牌:<span>Texas InstrumentsTexas</span>
</div>
<div class="fz fl boxsiz ellipsis">
封装:<span>LQFP-144</span>
</div>
<div class="price fl boxsiz ellipsis "> 接受价:<span></span></div>
<div class="num fl boxsiz ellipsis"> 数量:<span class="bold">100,000 PCS</span></div>
<div class="hq fl boxsiz ellipsis"> 货期:<span>现货</span></div>
<div class="bz fl boxsiz ellipsis"> 备注:<span>有货的商家请尽快联系,谢谢!</span></div>
</div>
{{# } }}
</div>
<!-- <div class="center_right ellipsis">
报价:<span class="bold">21</span>
</div> -->
</div>
<div class="bottom clr">
<div class="gt_div fl btn btn_yellow" imid="{{item.im_username}}" userid="{{item.user_id}}" avatar="{{item.avatar}}">
<span class="icon iconfont iconjuxing7 va-m"></span>
在线沟通
</div>
<!-- <div class="phone_div fl btn btn_border">
<span class="icon iconfont iconjuxing23 va-m"></span>
18271408714
</div> -->
</div>
<div class="time">
报价时间:<span>{{layui.util.toDateString(d.add_time * 1000)}}</span>
</div>
</div>
<div class="item_left boxsiz" style="padding-right:474px;">
<div class="item_left_top">
<h3 class="bold fl ellipsis boxsiz goods_name">{{item.goods_name}}</h3>
<div class="price fl bold ellipsis boxsiz">
{{# if(item.currency == 1){ }}
{{# } else { }}
$
{{# } }}
{{item.price}}
</div>
</div>
<div class="desc">
<div class="brand fl boxsiz ellipsis">
品牌:<span>{{item.brand_name}}
</span>
<div class="bj_detail">
<div class="bj_title">
<span class="lineBlock"></span>
<b>收到的报价</b>
<b class="bj_num">2</b>
</div>
<div class="fz fl boxsiz ellipsis">
封装:<span>{{item.encap}}</span>
<div class="bj_lists">
<div class="bj_item clr">
<div class="item_right fr boxsiz">
<div class="top">
<div class="top_right icon iconfont iconjuxing2 fr"></div>
<div class="top_left boxsiz ellipsis">
<span class="lineBlock mark">报价</span>
<span class="name bold">深圳邦马特科技有限公司深圳邦马特科技有限公司</span>
</div>
</div>
<div class="center">
<div class="center_left boxsiz clr">
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
公司认证
</div>
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
贸易商
</div>
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
贸易商
</div>
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
贸易商
</div>
<div class="fl">
<span class="icon iconfont iconjuxing10"></span>
贸易商
</div>
</div>
<div class="center_right ellipsis">
报价:<span class="bold">21次</span>
</div>
</div>
<div class="bottom clr">
<div class="gt_div fl btn btn_yellow">
<span class="icon iconfont iconjuxing7 va-m"></span>
在线沟通
</div>
<div class="phone_div fl btn btn_border">
<span class="icon iconfont iconjuxing23 va-m"></span>
18271408714
</div>
</div>
<div class="time">
报价时间:<span>2019-05-23 15:57</span>
</div>
</div>
<div class="item_left boxsiz">
<div class="item_left_top">
<h3 class="bold fl ellipsis boxsiz">STM32F103ZET6</h3>
<div class="price fl bold ellipsis boxsiz">¥67.9800</div>
</div>
<div class="desc">
<div class="brand fl boxsiz ellipsis">
品牌:<span>Texas Instruments
</span>
</div>
<div class="fz fl boxsiz ellipsis">
封装:<span>LQFP-144</span>
</div>
<div class="num fl boxsiz ellipsis"> 数量:<span class="bold">100,000 PCS</span>
</div>
<div class="hq fl boxsiz ellipsis"> 货期:<span>现货</span></div>
<div class="bz fl boxsiz ellipsis">
备注:<span>我们有大量的现货,随时都可以出库。我们有大量的现货,随时都可以出库。</span></div>
</div>
</div>
</div>
</div>
<div class="num fl boxsiz ellipsis"> 数量:<span class="bold">{{item.number}} PCS</span>
<div class="no_data" style="display: none">
<img src="__PUBLIC__/images/nodata.png" alt="">
<p>暂无报价信息</p>
</div>
<div class="hq fl boxsiz ellipsis"> 货期:<span>{{item.delivery_time}}</span></div>
<div class="bz fl boxsiz ellipsis">
备注:<span>{{item.remark||'--'}}</span></div>
</div>
</div>
</div>
{{# }); }}
</div>
{{# if(d.length === 0){ }}
<div class="no_data">
<img src="__PUBLIC__/images/nodata.png" alt="">
<p>暂无报价信息</p>
</div>
{{# } }}
</div>
<include file="public/foot" />
<script>
$('.gt_div ').on('click', function () {
var obj = {
userId: '18271408717',
type: "STM32F103ZET6",
price: "67.9800",
brand: "Texas Instruments",
fz: "LQFP-144",
num: "100,000",
hq: "现货",
};
Util.setCookie('template', JSON.stringify(obj), 1)
window.location.href = '/chat'
})
</script>
</body>
......
......@@ -24,7 +24,7 @@
<span class="li_right icon iconfont">
</a>
<dl <if condition="(ACTION_NAME eq 'inquiry') || (ACTION_NAME eq 'releaseinquiry') || (ACTION_NAME eq 'inquirydetail') || (ACTION_NAME eq 'quote') || (ACTION_NAME eq 'quotedetail')">style="display:block"</if>>
<dd <if condition="(ACTION_NAME eq 'inquiry') || (ACTION_NAME eq 'releaseinquiry') || (ACTION_NAME eq 'inquirydetail')">class="active"</if>><a href="homeicsales/inquiry">我的询价</a></dd>
<dd <if condition="(ACTION_NAME eq 'inquiry') || (ACTION_NAME eq 'releaseinquiry') || (ACTION_NAME eq 'inquirydetail')">class="active"</if>><a href="/inquiry">我的询价</a></dd>
<dd <if condition="(ACTION_NAME eq 'quote') || (ACTION_NAME eq 'quotedetail')">class="active"</if>><a href="homeicsales/quote">我的报价</a></dd>
</dl>
</li>
......
......@@ -3,168 +3,91 @@ $(function () {
conn: {},
orgName: "1113190618181018",
appName: "icsales",
defaultName: "18664936975",
templateObj: JSON.parse(Util.getCookie('template') || "{}"),
customerText: Util.getCookie('customer') || "",
isLoginSuccess: false,
img: "",
name: "",
id: "",
init: function () {
this.getUserInfo();
// this.ieFun();
this.ieFun()
this.connection();
this.connListen();
this.login();
this.bindFunction();
},
deleteCookie: function () {
Util.delCookie('template', cookieHostname);
Util.delCookie('templateBoolean', cookieHostname);
Util.delCookie('customer', cookieHostname);
},
getUserInfo: function () { //获取用户的基本信息
var self = this;
IcController.getData(apis.authme, 'GET', {
"token": Util.getCookie('token') || '',
}, function (res) {
if (res.err_code == 0) {
self.img = res.data.avatar;
self.name = res.data.company_name || '--';
self.id = res.data.user_id + '';
self.getHistoryUsers(res.data.im_username, res.data.im_password);
var data = JSON.stringify({
"grant_type": "client_credentials",
"client_id": "YXA6UWJlUJGNEemA0XUSlr6mDA",
"client_secret": "YXA6n8pckF065e7FPtukjJHAoa-4G74"
}, )
$.ajax({
type: 'post',
url: 'http://a1.easemob.com/1113190618181018/icsales/token',
data: data,
contentType: "application/json",
success: function (data) {
var token = data.access_token;
$.ajax({
type: 'get',
url: 'http://a1.easemob.com/1113190618181018/icsales/chatmessages/2019062513',
headers: {
Authorization: 'Bearer ' + token
},
success: function (data) {
},
error: function () {
layer.msg('网络出现问题,请重试!');
}
});
} else {
console.log('获取用户名失败');
layer.msg('聊天系统出错');
self.deleteCookie()
}
}, true, false)
},
getHistoryUsers: function (name, password) {
//获取用户聊天的成员记录
var self = this;
IcController.getData(apis.listrecord, 'GET', {
"token": Util.getCookie('token') || '',
}, function (res) {
if (res.errcode === 0) {
self.rendChatSection(res.data);
self.login(name, password);
} else {
layer.msg('获取历史纪录失败');
self.deleteCookie()
},
error: function () {
layer.msg('网络出现问题,请重试!');
}
});
},
addChatMember: function (id) {
IcController.getData(apis.addrecord, 'GET', {
"token": Util.getCookie('token') || '',
"user_id": id
}, function (res) {
if (res.errcode === 0) {
} else {
console.log('添加聊天成员失败')
}
}, false);
},
rendChatSection: function (data) {
console.log('获取成员')
this.addUser({}, true);
for (var i = 0; i < data.length; i++) {
this.addUser(data[i])
}
},
singleChat: function () {
if (JSON.stringify(this.templateObj) == '{}') {
$(".notice_classify[userid=" + this.defaultName + "]").click();
} else {
Util.delCookie('template', cookieHostname);
this.addUser({}, false, true);
var html = $(".notice_classify[userid=" + this.templateObj.userId + "]").clone();
$(".notice_classify[userid=" + this.templateObj.userId + "]").remove();
$(".notice_classify[userid=" + this.defaultName + "]").after(html);
$(".notice_classify[userid=" + this.templateObj.userId + "]").attr('isTemplate', true); //先获取历史纪录再发送模板,否则可能出现发送的消息显示两条
$(".notice_classify[userid=" + this.templateObj.userId + "]").click();
defaultUser: function () {
//默认客服
var message = {
from: "18664936975",
data: ''
}
this.receiveData(1, message, false);
},
customerChat: function () {
if (Util.getCookie('customer')) {
Util.delCookie('customer', cookieHostname);
$(".notice_classify[userid=" + this.defaultName + "]").attr('isCustomer', true);
singleChat: function () {
var templateStr = Util.getCookie('template');
var templateObj = {};
if (templateStr) {
templateObj = JSON.parse(templateStr)
}
if (JSON.stringify(templateObj) !== '{}') {
},
addUser: function (obj, isDefault, isFirst) {
var id, name, img, touserid;
if (isDefault) {
id = this.defaultName;
name = 'IC助手客服';
touserid = "";
img = dist + "/images/timg.jpg";
} else {
if (isFirst) {
id = this.templateObj.userId;
touserid = this.templateObj.touserid;
name = this.templateObj.userName;
img = this.templateObj.userImg || (dist + "/images/default.jpg");
} else {
id = obj.im_username;
name = obj.company_name || '--';
touserid = obj.user_id;
img = obj.avatar || (dist + "/images/default.jpg")
}
var message = {
from: templateObj.userId,
data: ''
};
this.receiveData(1, message, false);
$(".notice_classify[userid=" + templateObj.userId + "]").click();
this.sendCmd(templateObj);
Util.delCookie('template');
}
var userLen = $('.chat_item_content').find('#' + id).length;
if (userLen) { //用户存在
return;
} else { //用户不存在
var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true" touserid=' + touserid + '>' + this.userHtml(0, {
name: name,
id: id,
img: img
}, '') + '</div>';;
var righthtml = '<div class="chat_item" id="' + id + '">' +
'<div class="title clr">' +
// '<div class="fr btn btn_border">' +
// '<span class="icon iconfont iconjuxing23"></span>' +
// '<i>' + id + '</i>' +
// '</div>' +
'<h3 class="bold boxsiz">' + name + '</h3>' +
'</div>' +
'<div class="notice_list boxsiz">' +
'<div class="notice_item_content">' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$('.notice_left_content').append(lefthtml);
$('.chat_item_content').append(righthtml)
}
},
connection: function () {
WebIM.config = config;
//建立聊天链接
this.conn = WebIM.conn = new WebIM.default.connection({
appKey: WebIM.config.appkey,
isHttpDNS: WebIM.config.isHttpDNS,
this.conn = new WebIM.connection({
isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
host: WebIM.config.Host,
https: WebIM.config.https,
https: typeof WebIM.config.https === 'boolean' ? WebIM.config.https : location.protocol ===
'https:',
url: WebIM.config.xmppURL,
apiUrl: WebIM.config.apiURL,
isAutoLogin: true,
heartBeatWait: WebIM.config.heartBeatWait,
autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
autoReconnectInterval: WebIM.config.autoReconnectInterval,
isStropheLog: WebIM.config.isStropheLog,
delivery: WebIM.config.delivery
autoReconnectInterval: WebIM.config.autoReconnectInterval
});
// 初始化上传组件 fileInputId对应页面上的file组件id
WebIM.flashUpload = UploadShim({
fileInputId: 'image'
}, this.conn).flashUpload;
//增加表情
WebIM.Emoji = {
path: dist + '/faces/',
......@@ -243,48 +166,47 @@ $(function () {
clock += ss;
return (clock);
},
userHtml: function (num, obj, message) {
userHtml: function (num, user, message) {
//左边用户的dom拼接
if (num == 0) {
return '<img src="' + obj.img + '" alt="" class="user_logo">' +
return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' +
'<div class="user_right">' +
'<div class="clr">' +
'<h3 class="boxsiz ellipsis">' + obj.name + '</h3>' +
'<h3 class="boxsiz ellipsis">' + user + '</h3>' +
'</div>' +
'<div class="message ellipsis">' + message + '</div>' +
'</div>'
} else {
return '<img src="' + obj.img + '" alt="" class="user_logo">' +
return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' +
'<div class="user_right">' +
'<div class="clr">' +
'<span class="num fr">' + num + '</span>' +
'<h3 class="boxsiz ellipsis">' + obj.name + '</h3>' +
'<h3 class="boxsiz ellipsis">' + user + '</h3>' +
'</div>' +
'<div class="message ellipsis">' + message + '</div>' +
'</div>'
}
},
messageHtml: function (leftOrRight, html, isTemplate, isHistory, time) {
messageHtml: function (leftOrRight, html, isTemplate) {
//右边消息的dom拼接 isTemplate 是否是模板
var htmlp = '<p>' + html.message + '</p>';
var img = html.img || (dist + '/images/default.jpg')
var htmlp = '<p>' + html + '</p>';
if (isTemplate) {
var htmlp = '<div class="template lineBlock boxsiz">' +
'<img src="' + (html.goodImage || dist + "/images/defaultgood.png") + '" alt="">' +
'<img src="http://resic.liexin.com/images/test.jpg" alt="">' +
'<div class="template_right">' +
'<div class="template_right_top clr">' +
'<h3 class="bold fl">' + html.type + '</h3>' +
'<div class="price bold fr">' + html.price + '</div>' +
'<h3 class="bold fl">'+html.type+'</h3>' +
'<div class="price bold fr">'+html.price+'</div>' +
'</div>' +
'<div class="template_right_bottom">' +
'<div class="desc1 clr">' +
'<div class="brand fl">品牌:<i>' + html.brand + '</i></div>' +
'<div class="hq fl">货期:<i>' + html.hq + '</i></div>' +
'<div class="brand fl">品牌:<i>'+html.brand+'</i></div>' +
'<div class="hq fl">货期:<i>'+html.hq+'</i></div>' +
'</div>' +
'<div class="desc2 clr">' +
'<div class="num fl">数量:<i class="bold">' + html.num + '</i></div>' +
'<div class="time fl">时间:<i>' + html.time + '</i></div>' +
'<div class="num fl">数量:<i class="bold">'+html.num+'PCS</i></div>' +
'<div class="time fl">时间:<i>2019-05-23 15:57 </i></div>' +
'</div>' +
'</div>' +
'</div>' +
......@@ -293,23 +215,22 @@ $(function () {
if (leftOrRight == 1) { //右边
if (html) {
return '<div class="notice_item right clr">' +
'<img src="' + img + '" alt="" class="fr user_logo">' +
'<img src="' + dist + '/images/test.jpg" alt="" class="fr user_logo">' +
'<div class="notice_content">' +
htmlp +
'<div>' + (isHistory ? time : this.curentTime()) + '</div>' +
'</div>' +
'<div>' + this.curentTime() + '</div>' +
'</div>'
} else {
return ''
}
} else { //左边
if (html) {
return '<div class = "notice_item left clr" > ' +
'<img src="' + img + '" alt="" class="fl user_logo">' +
'<img src="' + dist + '/images/test.jpg" alt="" class="fl user_logo">' +
'<div class="notice_content">' +
htmlp +
'<div>' + (isHistory ? time : this.curentTime()) + '</div>' +
'</div>' +
'<div>' + this.curentTime() + '</div>' +
'</div>'
} else {
return ''
......@@ -322,126 +243,87 @@ $(function () {
var regContent = "";
var htmlStr = "";
var self = this;
var emojiTxt = ""
if (type == 1) {
if (isTemplate) {
regContent = message.type + ' ' + message.price;
htmlStr = message;
regContent = message.ext.type + ' ' + message.ext.price;
htmlStr = message.ext;
} else {
regContent = message.message;
htmlStr = message;
regContent = message.data;
htmlStr = message.data;
}
} else if (type == 2) {
regContent = '[图片]';
htmlStr = {
message: '<img src ="' + message.url + '" class="edit_img"/>',
name: message.name,
img: message.img,
id: message.id
}
htmlStr = '<img src ="' + message.url + '" class="edit_img"/>';
} else {
var data = message.message;
var data = message.data;
for (var i = 0, l = data.length; i < l; i++) {
if (data[i].type == 'emoji') {
regContent += '[表情]';
emojiTxt += '<img src ="' + data[i].data + '" width=25 height=25/>';
htmlStr += '<img src ="' + data[i].data + '" width=25 height=25/>';
} else {
regContent += data[i].data;
emojiTxt += data[i].data;
htmlStr += data[i].data;
}
};
htmlStr = {
message: emojiTxt,
name: message.name,
img: message.img,
id: message.id
}
}
var len = $('.notice_classify').length;
var messageSigleStr =
'<div class="title clr">' +
// '<div class="fr btn btn_border">' +
// '<span class="icon iconfont iconjuxing23"></span>' +
// '<i>' + message.to + '</i>' +
// '</div>' +
'<h3 class="bold boxsiz">' + message.name + '</h3>' +
'<div class="fr btn btn_border">' +
'<span class="icon iconfont iconjuxing23"></span>' +
'<i>' + message.from + '</i>' +
'</div>' +
'<h3 class="bold boxsiz">' + message.from + '</h3>' +
'</div>' +
'<div class="notice_list boxsiz">' +
'<div class="notice_item_content">' +
self.messageHtml(2, message, isTemplate) +
self.messageHtml(2, htmlStr, isTemplate) +
'</div>' +
'</div>' +
'</div>';
if (!len) {
//新用户
Util.delCookie('templateBoolean', cookieHostname);
var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true" touserid=' + message.touserid + '>' +
self.userHtml(0, message, regContent) + '</div>';
var userStr = '<div class="notice_classify active" userid="' + message.from + '">' +
self.userHtml(0, message.from, regContent) + '</div>';
var messageStr = '<div class="chat_item active" id="' + message.from + '">' +
messageSigleStr + '</div>'
$(".notice_classify[userid=" + self.defaultName + "]").after(userStr);
// $('.notice_left_content').append(userStr);
$('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr)
} else {
$('.notice_classify').each(function (index) {
var userId = $(this).attr('userid');
var isNowChat = $('.notice_classify').eq(index).hasClass('active');
var firstClick = $(this).attr('firstClick');
if (userId == message.from) {
//已有用户
if (isNowChat) {
//当前用户
$(this).html(self.userHtml(0, message, regContent));
if (Util.getCookie('templateBoolean')) {
Util.delCookie('templateBoolean', cookieHostname);
} else {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
}
var imgLen = $('#' + userId).find('img').length;
if (!imgLen) {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
} else {
$('#' + userId).find('img:last').load(function () {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
})
}
$(this).html(self.userHtml(0, message.from, regContent));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
} else {
//非当前用户
Util.delCookie('templateBoolean', cookieHostname);
var num = Number($(this).find('.num').text());
$(this).html(self.userHtml(num + 1, message, regContent));
var html = $(this).clone();
$(this).remove();
$(".notice_classify[userid=" + self.defaultName + "]").after(html);
if (!firstClick) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
}
$(this).html(self.userHtml(num + 1, message.from, regContent));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
}
return false;
} else {
if (index == len - 1) {
//新用户
Util.delCookie('templateBoolean', cookieHostname);
var userStr = '<div class="notice_classify" userid="' +
message.from + '" newMember="true" touserid=' + message.touserid + '>' +
self.userHtml(1, message, regContent) + '</div>';
message.from + '">' +
self.userHtml(1, message.from, regContent) + '</div>';
var messageStr = '<div class="chat_item" id="' +
message.from + '">' +
messageSigleStr + '</div>';
$(".notice_classify[userid=" + self.defaultName + "]").after(userStr);
messageSigleStr + '</div>'
$('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr)
}
}
......@@ -453,50 +335,19 @@ $(function () {
// listern,添加回调函数;
self.conn.listen({
onOpened: function (message) {
console.log('登入成功')
self.isLoginSuccess = true;
self.customerChat();
self.defaultUser();
self.singleChat();
},
onTextMessage: function (message) {
self.receiveData(1, {
name: message.ext.name || '--',
id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"),
message: message.data,
from: message.from,
touserid: message.ext.touserid
}, false)
self.receiveData(1, message, false)
}, //收到文本消息;
onEmojiMessage: function (message) {
self.receiveData(3, {
name: message.ext.name || '--',
id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"),
message: message.data,
from: message.from,
touserid: message.ext.touserid
}, false)
self.receiveData(3, message, false)
}, //收到表情消息;
onCmdMessage: function (message) {
console.log(message)
self.receiveData(1, {
name: message.ext.name || '--',
id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"),
from: message.from,
type: message.ext.type,
price: message.ext.price,
goodImage: message.ext.goodImage,
brand: message.ext.brand,
hq: message.ext.hq,
num: message.ext.num,
hq: message.ext.hq,
time: message.ext.time,
touserid: message.ext.touserid
}, true);
self.addChatMember(message.ext.id)
// console.log('CMD');
self.receiveData(1, message, true)
}, //收到命令消息;
onPictureMessage: function (message) {
var options = {
......@@ -504,22 +355,15 @@ $(function () {
};
options.onFileDownloadComplete = function () {
// 图片下载成功;
self.receiveData(2, {
name: message.ext.name || '--',
id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"),
from: message.from,
url: message.url,
touserid: message.ext.touserid
}, false)
self.receiveData(2, message, false)
};
options.onFileDownloadError = function () {
// 图片下载失败
// console.log('Image download failed!');
// console.log('Image download failed!');
};
WebIM.default.utils.download.call(self.conn, options); // 意义待查;
WebIM.utils.download.call(self.conn, options); // 意义待查;
}, //收到图片消息;
......@@ -531,26 +375,24 @@ $(function () {
}, //本机网络掉线;
onError: function (message) {
// console.log('Error', WebIM.utils.stringify(message));
console.log('onError: ', message);
// layer.msg('聊天系统出错');
console.log("Error: " + WebIM.utils.stringify(message));
}, //失败回调;
});
},
login: function (user, password) {
login: function () {
// open,登录;
var options = {
apiUrl: WebIM.config.apiURL,
user: user,
pwd: password,
user: "18589050841",
pwd: "123456",
appKey: WebIM.config.appkey
};
try {
this.conn.open(options);
} catch (e) {
console.log(e);
layer.msg('登入失败');
this.deleteCookie();
console.log(WebIM.config.apiURL)
// alert('open fail' + e.message)
}
},
......@@ -558,165 +400,84 @@ $(function () {
var self = this;
// 私聊发送文本消息,发送表情同发送文本消息,只是会在对方客户端将表情文本进行解析成图片;
var userId = $('.notice_left ').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid');
var id = this.conn.getUniqueId();
var msg = new WebIM.default.message('txt', id);
var emojiMessage = WebIM.default.utils.parseEmoji(content); //表情解析工具
var ext = {
timer: self.curentTime(),
id: self.id,
name: self.name,
img: self.img,
touserid: touserid
};
var msg = new WebIM.message('txt', id);
var emojiMessage = WebIM.utils.parseEmoji(content); //表情解析工具
msg.set({
msg: content, // 消息内容;
to: userId, // 接收消息对象;
ext: ext,
roomType: false,
success: function (id, serverMsgId) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, {
message: emojiMessage,
name: self.name,
img: self.img,
id: self.id
}, false));
var imgLen = $('#' + userId).find('img').length;
if (!imgLen) {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
} else {
$('#' + userId).find('img:last').load(function () {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
})
}
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1,
emojiMessage, false));
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
$('#chat_textarea').val('');
},
fail: function (e) {
console.log("Send private text failed", e);
layer.msg('消息发送失败');
fail: function () {
console.log("Send private text failed");
}
});
// console.log(msg.body)
this.conn.send(msg.body);
},
sendCmd: function (templateObj) {
var self = this;
var userId = $('.notice_left ').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid');
var id = this.conn.getUniqueId();
var msg = new WebIM.default.message('cmd', id);
var params = $.extend({}, templateObj, {
timer: self.curentTime(),
name: self.name,
id: self.id,
img: self.img,
touserid: touserid
});
var msg = new WebIM.message('cmd', id);
msg.set({
msg: 'template',
to: userId,
roomType: false,
action: "template",
ext: params,
success: function () {
self.addChatMember(templateObj.targetId);
ext: templateObj,
success: function (id, serverMsgId) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1,
params, true));
var imgLen = $('#' + userId).find('img').length;
if (!imgLen) {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
} else {
$('#' + userId).find('img:last').load(function () {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
})
}
templateObj, true));
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
},
fail: function () {
console.log("Send Cmd failed");
layer.msg('消息发送失败');
}
});
this.conn.send(msg.body);
Util.delCookie('templateBoolean', cookieHostname);
},
sendPrivateImg: function () {
// 私聊发送图片消息;
var self = this;
var id = this.conn.getUniqueId();
var msg = new WebIM.default.message('img', id);
var msg = new WebIM.message('img', id);
var input = $('#img_upload')[0]; // 选择图片的input;
var file = WebIM.default.utils.getFileUrl(input); // 将图片转化为二进制文件;
var file = WebIM.utils.getFileUrl(input); // 将图片转化为二进制文件;
var userId = $('.notice_left').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid');
var option = {
apiUrl: WebIM.config.apiURL,
file: file,
to: userId,
ext: {
timer: self.curentTime(),
id: self.id,
name: self.name,
img: self.img,
touserid: touserid
},
to: '18664936975',
roomType: false,
// chatType: 'singleChat',
flashUpload: WebIM.flashUpload,
onFileUploadError: function () {
console.log(file);
console.log('失败')
},
onFileUploadComplete: function () {
console.log('消息上传成功')
},
onFileUploadComplete: function () {},
success: function () {
var htmlStr = '<img src ="' + file.url + '" class="edit_img"/>';
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, {
message: htmlStr,
name: self.name,
img: self.img,
id: self.id
}, false));
var imgLen = $('#' + userId).find('img').length;
if (!imgLen) {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
} else {
$('#' + userId).find('img:last').load(function () {
setTimeout(function () {
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
}, 200)
})
}
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1,
htmlStr, false));
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
$('#img_upload').val('');
},
fail: function () {
console.log("Send Image failed");
layer.msg('消息发送失败');
}
};
msg.set(option);
console.log(msg.body)
this.conn.send(msg.body);
},
......@@ -762,166 +523,18 @@ $(function () {
})
$('.notice_left').on('click', '.notice_classify', function () {
var id = $(this).attr('userid');
var isTemplate = $(this).attr('isTemplate');
var isCustomer = $(this).attr('iscustomer');
var firstClick = $(this).attr('firstClick');
var newMember = $(this).attr('newMember');
$('#' + id).addClass('active').siblings('.chat_item').removeClass('active');
$(this).find('.num').remove();
$(this).addClass('active').siblings('.notice_classify').removeClass('active');
if (isCustomer) {
$(this).removeAttr('iscustomer');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, false, true)
} else {
layer.msg('聊天系统出错');
return;
}
return;
}
if (isTemplate) {
$(this).removeAttr('isTemplate');
$(this).removeAttr('firstClick');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, true)
} else {
layer.msg('聊天系统出错');
return;
}
} else {
if (newMember) {
setTimeout(function () {
var contentHeight = $('#' + id).find('.notice_item_content')
.height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
}, 200)
return
}
if (firstClick) {
$(this).removeAttr('firstClick');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id);
} else {
layer.msg('聊天系统出错');
return;
}
} else {
setTimeout(function () {
var contentHeight = $('#' + id).find('.notice_item_content')
.height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
}, 200)
}
}
var contentHeight = $('#' + id).find('.notice_item_content').height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
});
$('.notice_right ').on('click', '.edit_img', function () {
})
},
getHistoryData: function (id, isTemplate, isCustomer) {
var self = this;
this.conn.fetchHistoryMessages({
queue: id,
count: '50',
success: function (data) {
self.rendHistoryMessage(id, data, isTemplate)
if (isTemplate) {
self.sendCmd(self.templateObj);
}
if (isCustomer) {
if (self.customerText) {
self.sendPrivateText(self.customerText)
} else {
return
}
}
},
fail: function (e) {
console.log(e)
layer.msg('获取历史纪录失败');
if (isTemplate) {
self.sendCmd(self.templateObj);
}
if (isCustomer) {
if (self.customerText) {
self.sendPrivateText(self.customerText)
} else {
return
}
}
}
})
},
rendHistoryMessage: function (id, data, isTemplate) {
var chatCon = "";
for (var i = 0; i < data.length; i++) {
var fromId = data[i].from;
var rightOrLeft = 1; //默认右边
var emojiTxt = "";
if (fromId == id) { //接收的 左边
rightOrLeft = 2;
}
if (data[i].data) { //消息或者表情
if (typeof (data[i].data) == 'string') {
chatCon += this.messageHtml(rightOrLeft, {
message: data[i].data,
name: data[i].ext.name,
img: data[i].ext.img,
id: data[i].ext.id
}, false, true, data[i].ext.timer);
} else {
for (var j = 0; j < data[i].data.length; j++) {
if (data[i].data[j].type == "txt") {
emojiTxt += data[i].data[j].data
} else {
emojiTxt += '<img src ="' + data[i].data[j].data + '" width=25 height=25/>';
}
}
chatCon += this.messageHtml(rightOrLeft, {
message: emojiTxt,
name: data[i].ext.name,
img: data[i].ext.img,
id: data[i].ext.id
}, false, true, data[i].ext.timer);
}
}
} else if (data[i].url) { //图片
chatCon += this.messageHtml(rightOrLeft, {
message: '<img src ="' + data[i].url + '" class="edit_img"/>',
name: data[i].ext.name,
img: data[i].ext.img,
id: data[i].ext.id
}, false, true, data[i].ext.timer);
} else if (data[i].action == 'template') { //模板
chatCon += this.messageHtml(rightOrLeft, data[i].ext, true, true, data[i].ext.timer);
}
}
$('#' + id).find('.notice_item_content').prepend(chatCon);
if (!isTemplate) {
var imgLen = $('#' + id).find('img').length;
if (!imgLen) {
setTimeout(function () {
var contentHeight = $('#' + id).find('.notice_item_content')
.height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
}, 200)
} else {
$('#' + id).find('img:last').load(function () {
setTimeout(function () {
var contentHeight = $('#' + id).find('.notice_item_content')
.height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
}, 200)
})
}
}
},
};
chatObj.init();
})
\ No newline at end of file
......@@ -107,6 +107,8 @@
if (!$mobile.val()) {
$mobile.parent('.input-wrap').addClass('error');
$(".error-text").show().find("span").text('请填写手机号');
return false;
......@@ -115,6 +117,8 @@
if (!$password.val() && type === 1) {
$password.parent().parent('.input-wrap').addClass('error');
$(".error-text").show().find("span").text('请填写密码');
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment