You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

449 lines
17 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(function(require, exports, module) {
var sendWindow = require('apps/edp/frs/frs008/send');
var viewWindow = require('apps/edp/frs/frs008/view');
var BasePage = require('system/views/pages/page');
var Main = require(Store.mainPageJs);
// var MSG = require('../../../../locale/{lang}/frs');
// _.extend(Store.MSG, MSG);
function Email(id, node, template) {
this.node = node;
this.id = id;
var newtpl = Store.compile(template, Store.MSG);
var EmailVM = avalon.define({
$id: id,
tpl: newtpl,
category: 0,
//写信窗口
writeemail: function() {
//sendWindow与变量一致出现第二次不能加载
options = {
onClose: function() {
EmailVM.refresh();
},
}
sendwindow = new sendWindow(options);
sendwindow.open();
},
//刷新
refresh: function() {
EmailVM.ecount();
EmailVM.emalist();
},
//邮箱数量统计
ecount: function() {
Store.services.emailCount({}, function(isok, data) {
if (isok) {
$("edp_email_unreadbox").text(data.unread); //未读数
Main.setMsgBadge(data.unread);
$("edp_email_readbox").text(data.read);
$("edp_email_outbox").text(data.draft); //草稿数
$("edp_email_sentbox").text(data.sended); //已发送数
$("edp_email_delbox").text(data.deleted);
$(".delbox1").text(data.delunread);
$(".delbox2").text(data.delread);
$(".delbox3").text(data.delsended);
$(".delbox4").text(data.deldraft);
} else {
Store.showError(data.returnMessage || Store.MSG.FRS008_19);
}
});
},
//获取邮箱列表
emalist: function() {
//获取请求的数据
var pageopt = $('.email').datagrid('getPager').data("pagination").options;
var params = {
"Category": EmailVM.category,
"pageIndex": pageopt.pageNumber == 0 ? 1 : pageopt.pageNumber,
"pageSize": pageopt.pageSize
};
if (EmailVM.category == 0) {
$('.setr').show();
$('.setunr').hide();
} else if (EmailVM.category == 1) {
$('.setunr').show();
$('.setr').hide();
} else {
$('.setunr').hide();
$('.setr').hide();
}
if (EmailVM.category >= 0 && EmailVM.category <= 3) {
$('.delbutab').hide();
$('.delbut').show();
}
if (EmailVM.category >= 5 && EmailVM.category <= 8) {
$('.delbut').hide();
$('.delbutab').show();
}
if (EmailVM.category == 1 || EmailVM.category == 0 || EmailVM.category == 5 || EmailVM.category == 6) {
$('.email').datagrid('hideColumn', 'addresseeer');
$('.email').datagrid('showColumn', 'sender');
}
if (EmailVM.category == 2 || EmailVM.category == 3 || EmailVM.category == 7 || EmailVM.category == 8) {
$('.email').datagrid('hideColumn', 'sender');
$('.email').datagrid('showColumn', 'addresseeer');
}
/* if(EmailVM.category>=4){
$('.delbut').hide();
$('.email').datagrid('hideColumn','addresseeer');
$('.email').datagrid('showColumn','sender');
}*/
Store.services.emailList(
params,
function(isok, data) {
if (isok) {
if (data.emailList.length > 0) {
//处理内部表格
var elist = {
"total": data.total,
"rows": data.emailList,
}
$('.email').datagrid('loadData', elist);
} else {
var elist = {
"total": 0,
"rows": [],
}
$('.email').datagrid('loadData', elist);
}
} else {
Store.showError(data.returnMessage || Store.MSG.FRS008_19);
// 获取邮件数量出错!
}
});
},
delete_share: function(deletemark) {
var self = this;
var elist = [];
var str = $('.email').datagrid('getSelections');
if (str.length == 0) {
Store.messager.warn(Store.MSG.FRS008_20);
// 未选中邮件!
} else {
for (var i in str) {
elist.push(str[i].emailid);
}
params = {
"category": EmailVM.category,
"eidlist": elist,
"deletemark": deletemark
}
if (deletemark == 1) {
Store.messager.confirm(Store.MSG.FRS008_21, function(replace) { // "邮件,是否删除?"
if (replace) {
Store.services.delete(
params,
function(isok, data) {
if (isok) {
EmailVM.refresh();
Store.messager.tip(Store.MSG.FRS008_22); //邮件删除成功!
} else {
Store.showError(data.returnMessage || Store.MSG.FRS008_23); //邮件删除出错
}
});
}
});
} else {
Store.messager.confirm("邮件,是否彻底删除?", function(replace) {
if (replace) {
Store.services.delete(
params,
function(isok, data) {
if (isok) {
EmailVM.refresh();
Store.messager.tip("邮件彻底删除成功!"); //删除成功展示
} else {
Store.showError(data.returnMessage || '邮件彻底删除出错!');
}
});
}
});
}
}
},
setIsRead: function(isread) {
var self = this;
var elist = [];
var str = $('.email').datagrid('getSelections');
if (str.length == 0) {
Store.messager.warn("未选中邮件!");
} else {
for (var i in str) {
elist.push(str[i].emailid);
}
params = {
"isread": isread,
"eidlist": elist,
},
Store.services.setIsRead(
params,
function(isok, data) {
if (isok) {
EmailVM.refresh();
if (isread == 1) {
Store.messager.tip("已读设置成功!");
} else {
Store.messager.tip("未读设置成功!");
}
} else {
Store.showError(data.returnMessage || '已读未读设置出错!');
}
});
}
},
//回收站
emaildelbox: function() {
$('.delbut').hide();
$('.delbutab').show();
$("li").removeClass('active');
$(this).addClass('active');
},
publicEmailList: function(pageIndex, category) {
$(".recy").removeClass('in');
EmailVM.pageIndex = pageIndex,
EmailVM.category = category,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},
publicDelEmailList: function(pageIndex, category) {
EmailVM.pageIndex = pageIndex,
EmailVM.category = category,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},
/* //未读
emailunread: function() {
$(".recy").removeClass('in');
EmailVM.pageIndex = 1,
EmailVM.category = 0,
EmailVM.refresh();
},
//已读
emailreaded: function() {
$(".recy").removeClass('in');
EmailVM.pageIndex = 1,
EmailVM.category = 1,
EmailVM.refresh();
},
//草稿箱
emailoutbox: function() {
$(".recy").removeClass('in');
EmailVM.pageIndex = 1,
EmailVM.category = 2,
EmailVM.refresh();
},
//已发送
emailsentbox: function() {
$(".recy").removeClass('in');
EmailVM.pageIndex = 1,
EmailVM.category = 3,
EmailVM.refresh();
},*/
/* listactive: function() {
$("li").removeClass('active');
$(this).addClass('active');
},
delunread: function() {
EmailVM.pageIndex = 1,
EmailVM.category = 5,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},
delread: function() {
EmailVM.pageIndex = 1,
EmailVM.category = 6,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},
delsended: function() {
EmailVM.pageIndex = 1,
EmailVM.category = 7,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},
deldraft: function() {
EmailVM.pageIndex = 1,
EmailVM.category = 8,
EmailVM.refresh();
$("li").removeClass('active');
$(this).addClass('active');
},*/
})
this.EmailVM = EmailVM;
}
inherits(Email, BasePage);
Email.prototype.initgrid = function() {
var self = this;
var $em = $('edpEmailRightMenu');
self.$emaillist.datagrid({
pagination: true, //显示分页
fit: true, //datagrid自适应宽度
fitColumn: false, //列自适应宽度
striped: true, //行背景交换
nowap: true, //列内容多时自动折至第二行
border: false,
checkOnSelect: true,
selectOnCheck: true,
singleSelect: false,
ctrlSelect: true,
remoteSort: false,
onRefresh: function() {
self.EmailVM.ecount();
self.EmailVM.emalist();
},
onDblClickRow: function(rowIndex, rowData) {
params = {
emailId: rowData.emailid
}
Store.services.viewEmail(
params,
function(isok, data) {
if (isok) {
self.view(data);
} else {
Store.showError(data.returnMessage || '获取邮件详情出错!');
}
});
},
onRowContextMenu: function(e, rowIndex, rowData) {
var abdel = $('edp_email_abdel');
var del = $('edp_email_del');
var unread = $('edp_email_unread');
var read = $('edp_email_read');
if (self.EmailVM.category >= 0 && self.EmailVM.category <= 3) {
$em.menu('showItem', abdel);
$em.menu('showItem', del);
}
if (self.EmailVM.category >= 4 && self.EmailVM.category <= 8) {
$em.menu('hideItem', del);
$em.menu('showItem', abdel);
}
if (self.EmailVM.category == 0) {
$em.menu('hideItem', unread);
$em.menu('showItem', read);
} else if (self.EmailVM.category == 1) {
$em.menu('hideItem', read);
$em.menu('showItem', unread);
} else {
$em.menu('hideItem', read);
$em.menu('hideItem', unread);
}
self.$emaillist.datagrid('selectRow', rowIndex);
var test = self.$emaillist.datagrid('getSelected');
if (test != null) {
$em.menu('show', {
left: e.pageX, //弹出窗口的方位坐标
top: e.pageY
});
e.preventDefault(); //阻止浏览器自带的右键菜单弹出
}
},
});
var p = self.$emaillist.datagrid('getPager');
self.initpage(p);
self.initmenu($em);
};
Email.prototype.initpage = function($p) {
var self = this;
$($p).pagination({
pageNumber: 1,
pageSize: 20, //每页显示的记录条数默认为10
pageList: [15, 20, 25, 30], //可以设置每页记录条数的列表
onSelectPage: function() {
self.EmailVM.ecount()
self.EmailVM.emalist();
}
});
};
Email.prototype.initmenu = function($em) {
var self = this;
$em.menu({
onClick: function(item) {
if (item.text == '设置未读') {
if (self.EmailVM.category == 1) {
self.EmailVM.setIsRead(0);
}
}
if (item.text == '设置已读') {
if (self.EmailVM.category == 0) {
self.EmailVM.setIsRead(1);
}
}
if (item.text == '删除') {
self.EmailVM.delete_share(1);
}
if (item.text == '彻底删除') {
self.EmailVM.delete_share(2);
}
}
});
};
Email.prototype.view = function(pdata) {
var self = this;
if (self.EmailVM.category == 2 || self.EmailVM.category == 8) {
pdata.draft = 1;
options = {
onBeforeClose: function() {
self.EmailVM.ecount();
self.EmailVM.emalist();
},
onClose: function() {
self.EmailVM.ecount();
self.EmailVM.emalist();
},
data: pdata,
}
sendwindow = new sendWindow(options);
sendwindow.open();
} else {
options = {
onClose: function() {
self.EmailVM.ecount();
self.EmailVM.emalist();
},
data: pdata,
}
var viewwindow = new viewWindow(options);
viewwindow.open();
}
};
//初始化完成
Email.prototype.initCompleted = function($container) {
var self = this;
this.$emaillist = this.getElement('table.email');
self.initgrid();
self.EmailVM.ecount();
self.EmailVM.emalist();
};
return Email;
});