var myScroll,
startScrollX,
scrollX,
$scrollDom,
searchPage,
lastTeamId,
isTeamOwner,
message,
curDocCode,
self,
docInfo,
members,
teams,
isL = false,
thisTeamsId = 0,
thisTeamCode;//当前账户团队code
var xScroll = 0;
var yOff = 0, xOff = 0;
var $gzbg = $('#gzbg');
mui.plusReady(function() {
self = plus.webview.currentWebview();
message = self.message;
if(message){//“转发给”功能,需要返回按钮
$(".mui-action-back").show();
$(".lin-group-chat .lin-arrow").hide();
}
docInfo = JSON.parse(plus.storage.getItem("docInfo"));
curDocCode = docInfo.code;
// 修复bug#2321 团队选择显示有两个团队被选中状态
// lastTeamId = plus.storage.getItem("teamId");
// myScroll = $('#content').lscroll({pullDownAction: pullDownAction, top: 16,
// scrollCallBack: function(s){
// yOff += Math.abs(s.distY>>0);
// xOff += Math.abs(s.distX>>0);
// if(xScroll==0 && yOff<20 && xOff>yOff)
// xScroll = true;
// }, scrollEndCallBack: function(s){
// xScroll = 0;
// yOff = 0;
// xOff = 0;
// }
// });
teams = JSON.parse(plus.storage.getItem("teamInfo"));
initTeams(teams);
/**
* 预加载查询页面
*/
searchPage = mui.preload({
url: 'search.html',
id: 'search.html' + self.message
});
initScroller();
});
function initScroller(){
//阻尼系数
var deceleration = mui.os.ios?0.003:0.0009;
mui('.mui-scroll-wrapper').scroll({
scrollX: true,
bounce: false,
indicators: true, //是否显示滚动条
deceleration:deceleration
});
myScroll = mui(".mui-scroll").pullToRefresh({
down: {
callback: function() {
var self = this;
setTimeout(function() {
initMembers(lastTeamId, true);
self.endPullDownToRefresh();
}, 1000);
}
},
scrollLeft: function(){
xScroll = true;
}
});
}
// function pullDownAction(){
// initMembers(lastTeamId, true);
// }
template.helper("setQyzs", function(level, qyzs) {
if(level==1)
return "";
return "签约总数: "+ (qyzs? qyzs : '0');
});
template.helper("setInfo", function(info) {
return JSON.stringify(info);
});
var qkys = [], zkys = [], jgs= [];
/**
* 初始化成员
* @param {Object} teamId
*/
function initMembers(teamId, isRefresh){
// plus.nativeUI.showWaiting();
getReqPromises(
[
{url: "/doctor/admin-teams/"+ teamId +"/members", reqType: "GET"}
],true
).then(function(datas) {
if(datas[0].status==200){
appendMembers(datas[0].data, isRefresh);
} else
mui.toast("获取成员数据失败!");
// plus.nativeUI.closeWaiting();
}).then(function () {
//判断是否是团队长
getReqPromises([{url: '/statistics/checkDoctorIsTeamLeder' ,reqType: 'GET'}]).then(function (res) {
if (res[0].status == 200) {
if ( res[0].data && res[0].data != null) {
thisTeamCode = res[0].data.id;
if (thisTeamsId == docInfo.adminTeamCode) {
$gzbg.show();
} else {
$gzbg.hide();
}
isL = true;
}
} else {
mui.toast(res[0].msg);
}
});
})
.catch(function(e){
mui.toast(e.msg);
});
}
/**
* 初始化选择团队
*/
function initTeams(data){
var isCheck = false;
template.helper("setChecked", function(id, i) {
if(lastTeamId && lastTeamId==id)
return "checked";
return "";
});
thisTeamsId = data.data[0].id;
$('.lin-sel-group').html(template('teams_tmpl', data));
if(!isCheck){
var $dom = $('.lin-sel-group li').eq(0).addClass("checked");
}
setCurTeamName();
setTeamId();
if(lastTeamId)
initMembers(lastTeamId, true);
}
function setCurTeamName(name){
$('.demo-comtop h1').html((name || $('.lin-sel-group li.checked').attr('data-name')) + '');
}
function setTeamId(){
var $cTeam = $('.lin-sel-group li.checked');
lastTeamId = $cTeam.attr('data-code');
isTeamOwner = $cTeam.attr('data-leaderCode')==curDocCode;
console.log("isTeamOwner = "+isTeamOwner);
// 修复bug#2321 团队选择显示有两个团队被选中状态
// plus.storage.setItem('teamId', lastTeamId);
}
/**
* 删除成员
*/
function removeMember(code, $dom){
mui.confirm("删除医生后,该医生将不能进行代理签约等团队内的工作,是否确认继续删除?", "提示", ["不了", "继续删除"], function(e){
if(e.index == 1){
plus.nativeUI.showWaiting();
sendPost("/doctor/admin-teams/"+ lastTeamId +"/members/"+ code +"/remove", {}, null,
function(res){
if(res.status==200){
$dom.parent().parent().parent().remove();
plus.nativeUI.closeWaiting();
mui.toast('删除成功!');
} else{
plus.nativeUI.closeWaiting();
mui.confirm(res.msg, "提示", ["我知道了"], function(e){});
}
},'POST','',true);
}
})
}
/**
* 列表点击事件
*/
var initListEvent = function(){
$('.doc-list')
.on('tap', 'div.zyjm', function(){ // 转移居民按钮
var info = JSON.parse($(this).parent().parent().attr('data-info'));
if(info.level == 3){
mui.openWindow({
id: "zhuanyijumin",
url: "../../search/html/zhuanyijumin.html",
extras: {
level: info.level,
teamCode: lastTeamId,
docCode: info.code,
type:'转移'
}
});
} else {
mui.openWindow({
id: "zyjm-layer.html",
url: "zyjm-layer.html",
styles: {
background: 'transparent'
},
show:{aniShow: "none"},
waiting:{autoShow: false},
extras: {
teamCode: lastTeamId,
docCode: info.code,
type:'转移'
}
})
}
/*var docCode = $(this).parent().parent().attr('data-code');
mui.openWindow({
id: "xuanzezhuanyijumin.html",
url: "xuanzezhuanyijumin.html",
extras: {
teamCode: lastTeamId,
docCode: docCode
}
});*/
return false;
})
.on('tap', 'div.sccy', function(){ // 删除成员按钮
removeMember($(this).parent().parent().attr('data-code'), $(this));
return false;
})
.on('touchstart', '.doc-item', function(e){ //左滑动作开始
e.preventDefault();
startScrollX = e.originalEvent.targetTouches[0].screenX;
})
.on('touchmove', '.doc-item', function(e){ //左滑动作移动
if(!isTeamOwner) return;
if(xScroll != true) return;
e.preventDefault();
scrollX = e.originalEvent.targetTouches[0].screenX - startScrollX;
debugger
var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
if(scrollX<0 && scrollX >= offLeft)
$(e.currentTarget).css('left', scrollX + 'px');
})
.on('touchend', '.doc-item', function(e){ //左滑动作结束
e.preventDefault();
if(scrollX<-50){
$scrollDom = $(e.currentTarget);
var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
$scrollDom.animate({left: offLeft}, "fast");
} else{
startScrollX = undefined;
$scrollDom = undefined;
$(e.currentTarget).animate({left: '0px'}, "fast");
}
scrollX = undefined;
xScroll = false;
myScroll.options.isLeftScroll = false;
})
.on('tap', '.doc-item', function(){
var oCode = $(this).attr("data-code");
if(self.message){
zf(1, oCode, $(this).attr("data-name"));
} else {
mui.openWindow('../../mine/html/zuyuanziliao.html', 'zuyuanziliao', {
extras: {
docCode: oCode,
teamCode: lastTeamId,
isTeamOwner: isTeamOwner
}
});
}
})
}();
function zf(type, code, name){
mui.confirm("是否确认将消息逐条转发给"+name+"?", "提示", ["不了,谢谢", "确认转发"], function(e) {
if(e.index == 0) {
} else {
Promise.all(_.map(self.imMessages,function(msg){
return new Promise(function(resolve, reject) {
if(type==1){
imClient.Sessions.createP2pSession(curDocCode, code, name, function(res){
if(res.status==200){
imClient.Sessions.sendMessage(res.data.id, curDocCode, docInfo.name, msg.content, msg.type, function(){
resolve(true);
}, function(){
console.log(JSON.stringify(msg))
resolve(true);
})
}else{
console.log(JSON.stringify(res))
resolve(true);
}
}, function(msg){
console.log(JSON.stringify(msg))
resolve(true);
})
} else {
imClient.Sessions.createGroupSession(code, name, members, function(res){
if(res.status==200){
imClient.Sessions.sendMessage(res.data.id, curDocCode, docInfo.name, msg.content, msg.type, function(){
resolve(true);
}, function(){
console.log(JSON.stringify(msg))
resolve(true);
})
}else{
console.log(JSON.stringify(res))
resolve(true);
}
}, function(msg){
console.log(JSON.stringify(msg))
resolve(true);
})
}
})
})).then(function() {
mui.toast("转发成功");
mui.fire(self.opener().opener(), "revertZf");
self.opener().close();
self.close();
}).catch(function(e){
console.log(e)
})
}
})
}
/**
* 搜索按钮点击
*/
$('.lin-search').on('tap', function() {
mui.fire(searchPage, "initSearch", {html: $('.doc-list').html(),message:self.message,imMessages:self.imMessages});
searchPage.show();
})
/**
* 取消左移块的事件
*/
$('body').on('touchstart', function(e){
if($scrollDom)
$scrollDom.animate({left: '0px'}, "fast");
}).on('touchmove', function(e){
// if(!e.target.parentElement.classList.contains("lin-sel-group")){
// e.preventDefault();
// }else{
// $("body").scrollTop(0);
// mui('.mui-scroll').pullRefresh().setStopped(true);
// }
})
$gzbg.on( 'tap', function () {
var href = '../html/gongzuobaogao.html',
hrefId = "gongzuobaogao"
if(plus.os.name == "Android") {
var wv = plus.webview.create( href, hrefId, {hardwareAccelerated:false}, {
teamCode: thisTeamCode
} );
wv.show("slide-in-right",250);
} else {
mui.openWindow({
url:href,
id:hrefId,
extras:{
teamCode: thisTeamCode
},
})
}
});
/**
* 初始化头部点击事件
*/
var initHeaderEvent = function(){
/**
* 显示团队选择
*/
var showGroupSel = function(e, isShow){
isShow = isShow || $('.lin-mask:hidden').length != 0;
$('.lin-mask').toggle(isShow);
$('.lin-sel-group').toggle(isShow);
}
$('.lin-mask').on('tap', showGroupSel);
$('.demo-comtop h1').on('tap', showGroupSel);
$('.lin-conf').on('tap', function(){
mui.openWindow({
url: "tuanduishezhi.html",
extras: getTeamInfo()
})
})
$('.lin-gp-add').on('tap', function(){
mui.openWindow({
url: "tianjiachengyuan.html",
extras: getTeamInfo()
})
})
$('.lin-sel-group').on('tap', 'li', function(){
thisTeamsId = $(this).attr('data-code');
showGroupSel(undefined, false);
if(!$(this).hasClass('checked')){
$(this).addClass('checked').siblings().removeClass('checked');
setCurTeamName();
setTeamId();
initMembers(lastTeamId, true);
}
})
$('.lin-group-chat').on('tap', function(){
if(!self.message){
var members = [];
$.each($('.doc-item'), function(i, v) {
members.push( JSON.parse($(v).attr('data-info')) );
});
var info = getTeamInfo();
info.code = info.teamCode;
info.members = members;
mui.openWindow({
url: "../../message/html/tuanduiqunliao.html",
id: "tuanduiqunliao.html",
extras: {
info: info
}
})
} else {
zf(2, lastTeamId, $('.lin-sel-group li.checked').attr('data-name'));
}
})
}();
function getTeamInfo(){
var $team = $('.lin-sel-group li.checked');
return {teamName: $team.attr('data-name'), teamCode: $team.attr('data-code')}
}
function appendMembers(data, isRefresh){
var resData = [];
for(var i=0;i