(function($, doc) {
$.init({
swipeBack: false,
pullRefresh: {
container: '#pullrefresh',
up: {
contentrefresh: "正在加载...", //可选,正在刷新状态时,下拉刷新控件上显示的标题内容
callback: pullupRefresh
}
},
gestureConfig: {
tap: true, //默认为true
doubletap: true, //默认为false
longtap: true, //默认为false
swipe: true, //默认为true
drag: true, //默认为true
hold: false, //默认为false,不监听
release: false //默认为false,不监听
}
});
/*上拉加载具体业务实现 */
var count = 1
var countItem = false;
function pullupRefresh() {
if(!countItem) {
var detailPage = plus.webview.getWebviewById('communicate.html');
mui.fire(detailPage, 'sendMsg', {
count: count,
});
count++;
}
this.endPullupToRefresh(countItem)
};
$.plusReady(function() {
var code;
var Input;
var str = plus.storage.getItem('user');
var user = JSON.parse(str);
var token = user.Data.Token;
var exist = user.Data.CompanyCode;
$('#img')[0].innerHTML = '
';
$('.mui-scroll-wrapper').scroll({
deceleration: 0.0005, //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
scrollX: false, //是否横向滚动
});
$(doc.body).on('tap', '.li', function() {
for(var i = 0; i < $('.li').length; i++) {
$('.li')[i].className = 'li'
}
mui(this)[0].className = 'li li active-li';
});
//跳转分享动态
$('body').on('tap', '.share', function() {
$.openWindow({
url: 'tpl/communicate/share.html',
waiting: {
autoShow: false, //自动显示等待框,默认为true
},
show: {
autoShow: true, //页面loaded事件发生后自动显示,默认为true
duration: 300, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
aniShow: 'slide-in-bottom',
}
});
});
//收起
$(doc.body).on('tap', '.aa', function() {
if($(this)[0].innerHTML == '查看全文↓') {
$(this)[0].parentNode.childNodes[1].style.display = "block";
$(this)[0].innerHTML = '收起↑'
} else {
$(this)[0].parentNode.childNodes[1].style.display = "none";
$(this)[0].innerHTML = '查看全文↓'
}
});
//获取列表
window.addEventListener('reload', function() {
GetdataList(0, 10);
});
GetdataList(0, 10);
window.addEventListener('sendMsg', function(event) {
setTimeout(function() {
GetdataList(event.detail.count, 3);
}, 3000)
});
/**
* 获取列表
*/
function GetdataList(pageNum, pageSize) {
var postData = {
"pageIndex": pageNum + 1,
"pageSize": pageSize,
"exist": exist,
};
$.ajax("http://www.bosshand.cn/api/Customer/GetBusinessPageList", {
data: postData,
dataType: 'json',
type: "post",
timeout: 10000, //超时时间设置为10秒;
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(resp) {
var html = '';
// var data = data.Data.list;
if(resp.Data.list != null) {
var resilt = resp.Data.list;
for(var i = 0; i < resilt.length; i++) {
//头部
html += '
'
html += '
';
//内容区
html += '
'
html += '
'
html += ''
var nameList = "";
if(resilt[i].list_LikesNum != null) {
for(var q = 0; q < resilt[i].list_LikesNum.length; q++) {
nameList += resilt[i].list_LikesNum[q].UserName + " ";
html += '' + resilt[i].list_LikesNum[q].UserName + ' ' + ''
}
}
html += '
'
html += ''
html += '
'
}
var div = document.createElement("div");
div.innerHTML = html;
if(pageNum >= 1) {
mui('#bossiness')[0].appendChild(div)
} else {
mui('#bossiness')[0].innerHTML = '' + html + '
'
isItem = true
}
if(html == "") {
countItem = true;
}
}
}
});
};
function getLocalDate(now) {
var date = now.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
var arr = date.split(' ');
//日期
var arrDate = arr[0].split('-');
//时间
var arrTime = arr[1].split(':');
return arrDate[0] + '年' + arrDate[1] + '月' + arrDate[2] + '日' + ' ' + arrTime[0] + ':' + arrTime[1];
};
/**
* 1.关注
* @param {Object} nS
*/
// $(doc.body).on('tap', '.com-con-btn', function() {
// var div = $(this)[0];
// var code = $(this)[0].id
// var nowDiv = div.parentNode.parentNode.parentNode;
// if(div.innerHTML == '') {
// plus.nativeUI.actionSheet({
// cancel: "取消",
// buttons: [{
// title: "关闭该条动态"
// }, {
// title: "取消关注"
// }]
// }, function(e) {
// if(e.index == 1) {
// nowDiv.parentNode.removeChild(nowDiv);
// }
// if(e.index == 2) {
// var postData = {
// "": code
// }
// mui.ajax("http://www.bosshand.cn/api/Customer/UpdateFollowCompany", {
// data: postData,
// dataType: 'json',
// type: "post",
// timeout: 10000, //超时时间设置为10秒;
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// authorization: token
// },
// success: function(resp) {
// if(resp.Code == 200) {
// div.innerHTML = ''
// $.toast('已取消关注');
// }
// }
// });
//
// }
//
// });
// } else {
// var postData = {
// "": code
// }
// mui.ajax("http://www.bosshand.cn/api/Customer/UpdateYesFollowCompany", {
// data: postData,
// dataType: 'json',
// type: "post",
// timeout: 10000, //超时时间设置为10秒;
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// authorization: token
// },
// success: function(resp) {
// if(resp.Code == 200) {
// div.innerHTML = '';
// $.toast('已关注')
// }
// }
// });
//
// }
// });
/**
* 预览图片
* @param {Object} nS
*/
$(doc.body).on('tap', '.imgs', function() {
$('.bg .imgss')[0].innerHTML = '
';
$('.bg')[0].style.display = 'block';
});
$(doc.body).on('tap', '.close', function() {
$('.bg')[0].style.display = 'none';
});
/**
* 2.点赞
* @param {Object} nS
*/
$(doc.body).on('tap', '.like', function() {
var code = $(this)[0].id;
var div = $(this)[0];
if($(this)[0].className == 'like') {
var postData = {
CompanyLogCode: code, //日志编码
CommentType: 3, //1-企业日志发布,2-商圈动态,3-点赞,4-评论
CommentContent: "", //内容
CommentCode: user.Data.Phone, //评论账号
CommentNumber: 1, //点赞数
}
$.ajax('http://www.bosshand.cn/api/Customer/UpdateLikesNum', {
data: postData,
dataType: 'json',
type: "post",
timeout: 10000, //超时时间设置为10秒;
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(resp) {
div.classList.add('likes');
div.childNodes[1].innerHTML = '已赞';
var span = doc.createElement("span");
span.innerHTML = user.Data.Name + ' ';
div.parentNode.parentNode.parentNode.childNodes[2].appendChild(span);
}
});
} else {
div.classList.remove('likes');
div.childNodes[1].innerHTML = '点赞';
var l = div.parentNode.parentNode.parentNode.childNodes[2].childNodes;
var nowspan = div.parentNode.parentNode.parentNode.childNodes[2].childNodes;
for(var i = 0; i < l.length; i++) {
if(nowspan[i].innerHTML == user.Data.Name + ' ') {
nowspan[i].parentNode.removeChild(nowspan[i]);
}
}
}
});
/**
* 3.评论
* @param {Object} nS
*/
$(doc.body).on('tap', '.value', function() {
code = $(this)[0].lastChild.id;
Input = $(this)[0].parentNode.parentNode.childNodes[1];
$('.val')[0].style.display = 'block';
});
//修整评论输入框
mui(document.body).on('tap', '.btns', function() {
var detailPage = plus.webview.getWebviewById('communicate.html');
var val = mui('.val input')[0].value;
mui.fire(detailPage, 'sendValue', {
val: val
});
mui('.val input')[0].blur();
$('.val')[0].style.display = 'none';
mui('.val input')[0].value="";
GetdataList(0, 10);
window.addEventListener('sendMsg', function(event) {
setTimeout(function() {
GetdataList(event.detail.count, 3);
}, 3000)
});
});
//点击取消按钮,取消评论
mui(document.body).on('tap', '.btnscancle', function() {
mui('.val input')[0].blur();
$('.val')[0].style.display = 'none';
mui('.val input')[0].value="";
});
/**
* 4.发表评论
* @param {Object} nS
*/
window.addEventListener('sendValue', function(event) {
var val = event.detail.val;
var div = doc.createElement("div");
var postData = {
CompanyLogCode: code, //日志编码
CommentType: 4, //1-企业日志发布,2-商圈动态,3-点赞,4-评论
CommentContent: val, //内容
CommentCode: 0, //评论账号
}
mui.ajax('http://www.bosshand.cn/api/Customer/CompanyCommentAdd', {
data: postData,
dataType: 'json',
type: "post",
timeout: 10000, //超时时间设置为10秒;
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(resp) {
div.innerHTML = '' + user.Data.Name + ':' + val + '
';
Input.appendChild(div);
}
});
});
/**
* 5.分享
* @param {Object} nS
*/
$(doc.body).on('tap', '.shares', function() {
var Intent = null,
File = null,
Uri = null,
main = null;
var shares = null;
var shareImageUrl = '';
mui.plusReady(function() {
updateSerivces();
if(plus.os.name == "Android") {
Intent = plus.android.importClass("android.content.Intent");
File = plus.android.importClass("java.io.File");
Uri = plus.android.importClass("android.net.Uri");
main = plus.android.runtimeMainActivity();
}
});
/**
* 更新分享服务
*/
function updateSerivces() {
plus.share.getServices(function(s) {
shares = {};
for(var i in s) {
var t = s[i];
shares[t.id] = t;
}
//outSet("获取分享服务列表成功");
}, function(e) {
//outSet("获取分享服务列表失败:" + e.message);
});
}
/**
* 分享操作
*/
function shareAction(id, ex) {
var s = null;
if(!id || !(s = shares[id])) {
//outLine("无效的分享服务!");
return;
}
if(s.authenticated) {
//outSet("---已授权---");
shareMessage(s, ex);
} else {
//outSet("---未授权---");
s.authorize(function() {
shareMessage(s, ex);
}, function(e) {
//outLine("认证授权失败");
});
}
}
/**
* 发送分享消息
*/
function shareMessage(s, ex) {
var msg = {
content: 'Bosshand',
href: 'http://www.bosshand.com',
thumbs: ["http://sale.bosshand.com/webhtml/html/weixin/images/pic300.jpg"],
title: '移动办公',
content: '随心掌握',
extra: {
scene: ex
}
};
s.send(msg, function() {
outLine("分享成功!");
}, function(e) {
outLine("分享失败!");
});
}
/**
* 分享按钮点击事件
*/
shareHref();
function shareHref() {
var ids = [{
id: "weixin",
ex: "WXSceneSession" /*微信好友*/
}, {
id: "weixin",
ex: "WXSceneTimeline" /*微信朋友圈*/
}],
bts = [{
title: "发送给微信好友"
}, {
title: "分享到微信朋友圈"
}];
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: bts
},
function(e) {
var i = e.index;
if(i > 0) {
shareAction(ids[i - 1].id, ids[i - 1].ex);
}
}
);
}
// 控制台输出日志
function outSet(msg) {
$.toast(msg);
}
// 界面弹出吐司提示
function outLine(msg) {
$.toast(msg);
}
})
//删除评论的内容
$(doc.body).on('tap', '.contentcancle', function() {
var canclecomment = $(this)[0].childNodes[3];
var contentcancle = $(this)[0];
var code = $(this)[0].id;
if($(this)[0].childNodes[0].innerHTML == (user.Data.Name + ':')) {
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: [{
title: "删除"
}]
},
function(e) {
var i = e.index;
if(i > 0) {
var postdata = {
"": code
}
$.ajax("http://www.bosshand.cn/api/Customer/CompanyCommentDeleteListApp", {
headers: {
authorization: token
},
type: "post",
data: postdata,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(data) {
if(data.Code == 200) {
contentcancle.style.display = "none";
}
}
});
}
}
);
}
});
//解决软键盘唤起时底部input输入框被遮挡问题
$(doc.body).on('tap', '#val', function() {
var bfscrolltop = document.body.scrollTop;//获取软键盘唤起前浏览器滚动部分的高度
interval = setInterval(function(){//设置一个计时器,时间设置与软键盘弹出所需时间相近
document.body.scrollTop = document.body.scrollHeight;//获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
},100)
})
});
})(mui, document);