/* ** Author : hzhang.Ashe ** Date : 2014.12.11 ** Descri : 报告管理 */ var ReportManager = (function () { //获取数据 function InitGrid(searchCondition) { //获取表格高度 var _height = getGridHeight(); var setLoading = setTimeout(function () { showLoading(); }, 1000); var parameterArray = [searchCondition]; var dataParameters = { MethodAlias: "MFRB_GetReportList", Parameter: parameterArray }; var colOpt = [[{ display: ‘序号‘, name: ‘Index‘, width: ‘20px‘, align: "center", render: displayIndexRow } , { display: ‘报告名‘, name: ‘Name‘, width: ‘180px‘, align: "left", render: displayNameRow } , { display: ‘作者‘, name: ‘Author‘, width: ‘40px‘, align: "left", render: displayAuthorRow } , { display: ‘修改日期‘, name: ‘UpdateTime‘, width: ‘60px‘, align: ‘left‘, render: displayUpdateTimeRow } , { display: ‘描述‘, name: ‘Description‘, width: ‘260px‘, align: "left", render: displayDescriptionRow } ]]; var option = { url: ajaxSecureUnlockHandler, method: "POST", colModel: colOpt, height: _height, fixTableHead: true, showTableToggleBtn: true, resizable: false, showPercent: false, params: dataParameters, preProcess:function(data){ clearTimeout(setLoading); //清理loading事件 $(".table-panel").unblock({fadeOut: 0}); //关闭loading return data; }, onComplete: function (grid) { $(".table-panel .line").show(); //解决下边线的问题 if (grid.d && grid.d.length == 0) { $(".sflexigrid .divB").find("table").hide(); var msg; if (searchCondition) { msg = "未查询到匹配报告。"; } else { msg = "您暂时没有报告,点击“新建报告”开始体验吧~"; } $(".sflexigrid .divB").append("<div class=‘notfindDiv‘><div class=‘floater‘></div><div class=‘msgDiv‘><span>" + msg + "</span></div></div>") } else { $(".sflexigrid .divB").find("table").show(); $(".sflexigrid .divB").find(".notfindDiv").remove(); } InitSelectedEvent(); } }; $(".div_table").sflexigrid(option); function displayIndexRow(name, index, data) { var html = ""; html += "<label class=‘s-index‘ >" + (index + 1).toString() || "" + "</label>"; return html; } function displayNameRow(name, index, data) { var _name = (data[index][‘Name‘] || ""); var html = ""; html += "<input type=hidden columnname=‘ReportId‘ value=‘" + (data[index][‘ReportId‘] || "") + "‘ />"; html += "<input type=hidden columnname=‘ShareId‘ value=‘" + (data[index][‘ShareId‘] || "") + "‘ />"; html += "<input type=hidden columnname=‘Author‘ value=‘" + (data[index][‘Author‘] || "") + "‘ />" html += "<a class=‘name‘ columnname=‘Name‘ columnvalue=‘" + _name + "‘>" + _name + "</a>"; return html; } function displayAuthorRow(name, index, data) { var l = (data[index][‘Author‘] || ""); return "<label columnname=‘Author‘ columnvalue=‘" + l + "‘>" + l + "</label>"; } function displayUpdateTimeRow(name, index, data) { var l = data[index][‘UpdateTime‘] ? data[index][‘UpdateTime‘].substr(0, 10) : ""; return "<label columnname=‘UpdateTime‘ columnvalue=‘" + l + "‘>" + l + "</label>"; } function displayDescriptionRow(name, index, data) { var l = data[index][‘Description‘] || ""; var __description = l; if (l.length > 25) { __description = l.substr(0, 25) + "..."; } return "<div class=‘description‘><label columnname=‘Description‘ columnvalue=‘" + l + "‘>" + __description + "</label></div>"; } }; var flag; function InitSearchEvent() { $("#reportname").focus(function () { var $input = $(this); if ($input.val() == $input.attr("placeholder")) { $input.val(‘‘); $input.removeClass(‘placeholder‘); } }).blur(function () { var $input = $(this); if ($input.val() == ‘‘ || $input.val() == $input.attr("placeholder")) { $input.val($input.attr("placeholder")); $input.addClass(‘placeholder‘); $(".clearSearchReport").hide(); } }).blur(); $("#reportname").keyup(function () { var _self = this; if (!$(_self).val() || $(_self).val() == $(_self).attr("placeholder")) { $(".clearSearchReport").hide(); } else { $(".clearSearchReport").show(); } clearTimeout(flag); flag = setTimeout(function () { InitGrid($(_self).val()); }, 500) }); //绑定查询框的hover效果 $(".operate-panel .search-panel-fields").hover(function () { $(this).addClass("ui-state-hover"); }).mouseleave(function () { $(this).removeClass("ui-state-hover"); }); } function InitClearEvent() { $(".clearSearchReport").click(function () { $("#reportname").val("").blur(); InitGrid(""); }); } function InitSelectedEvent() { //鼠标划过事件 $(".sflexigrid .divB tr").mouseenter(function () { var $optDiv = $(".operateDiv"); if ($optDiv.length == 0) { $optDiv = $("<div class=‘operateDiv‘><a href=‘javascript:void(0)‘ onclick=‘openContactPanel(this)‘ class=‘iconfont‘ title=‘分享‘></a><a href=‘javascript:void(0)‘ onclick=‘openEditPanel(this)‘ class=‘iconfont‘ title=‘编辑‘></a><a href=‘javascript:void(0)‘ onclick=‘openDeletePanel(this)‘ class=‘iconfont‘ title=‘删除‘></a></div>") } $optDiv.show(); $(this).addClass("ui-state-hover"); $(this).find(".description").append($optDiv); }).mouseleave(function () { $(this).removeClass("ui-state-hover"); $(".operateDiv").hide(); }); //鼠标点击事件 $(".sflexigrid .divB tr").click(function () { $(".sflexigrid tr.ui-state-active").removeClass("ui-state-active"); $(this).addClass("ui-state-active"); }); //打开报告事件 $(".sflexigrid .divB tr td a.name").click(function () { openReport(this); }); } function DeleteRow(selTr) { var $selTr = $(selTr); if ($selTr) { $selTr.remove(); } //重排序号 var $tdIndexs = $(".sflexigrid .divB tr td label.s-index"); if ($tdIndexs.length > 0) { for (var i = 0; i < $tdIndexs.length; i++) { $tdIndexs.eq(i).text(i + 1); } } else { var searchCondition = $("#reportname").val(); if (searchCondition && searchCondition !== $("#reportname").attr("placeholder")) { msg = "未查询到匹配报告。"; } else { msg = "您暂时没有报告,点击“新建报告”开始体验吧~"; } $(".sflexigrid .divB").append("<div class=‘notfindDiv‘><div class=‘floater‘></div><div class=‘msgDiv‘><span>" + msg + "</span></div></div>") $(".sflexigrid .divB table").hide(); } } function UpdateRow(obj, selTr) { var $selTr = $(selTr); var _name = obj.Name || ""; $selTr.find("a[ columnname=‘Name‘]").attr("columnvalue", _name).text(_name); var _updatetime = obj.UpdateTime ? obj.UpdateTime.substr(0, 10) : ""; $selTr.find("label[columnname=‘UpdateTime‘]").attr("columnvalue", _updatetime).text(_updatetime); var _author = obj.Author || ""; $selTr.find("label[columnname=‘Author‘]").attr("columnvalue", _author).text(_author); //描述 var _description = obj.Description || ""; $selTr.find("label[columnname=‘Description‘]").attr("columnvalue", _description); if (_description.length > 25) { _description = __description.substr(0, 25) + "..."; } $selTr.find("label[columnname=‘Description‘]").text(_description); } //loading function showLoading() { $(".table-panel").block({ message: (‘<span class="blockMsg">正在努力加载中...</span>‘), baseZ: 900, css: { padding: 0, margin: 0, textAlign: ‘center‘, color: ‘#fff‘, width: ‘80%‘, fontSize: ‘20px‘, cursor: ‘default‘ }, overlayCSS: { backgroundColor: ‘#282828‘, opacity: 1, cursor: ‘default‘ } }); } window.onresize = function () { $(".div_table").sflexResize({ height: getGridHeight() }); }; function getGridHeight() { var panelHeight = $(".content").height() - $(".warpper").outerHeight(true) - 10; $(".reporttable").height(panelHeight); var _temp = (panelHeight - $(".operate-panel").outerHeight() - 10) || 600; //此处根据每一列计算表格高度,以便刚好最底部的列和边框重合 _temp = (parseInt(_temp / 31) * 31) + 1; $(".table-panel").height(_temp); return _temp; } return { Init: function (searchCondition) { InitGrid(searchCondition); //initMyContact(); InitSearchEvent(); InitClearEvent(); }, UpdateRow: function (obj, selTr) { UpdateRow(obj, selTr); }, DeleteRow: function (selTr) { DeleteRow(selTr); } } })(); //加载共享报告 function isShareReportAndCreate(selTr, dosomething) { var _reportid = $(selTr).find("input[columnname=‘ReportId‘]").val(); var _shareid = $(selTr).find("input[columnname=‘ShareId‘]").val(); //若不存在报告Id则说明该共享报告尚未创建,先创建再执行其他操作 if (!_reportid && _shareid) { ajaxForCreateShareReport(selTr,_shareid, dosomething); } else { dosomething(); } } function ajaxForCreateShareReport(selTr,shareId, dosomething) { var parameters = [shareId]; var dataParameters = { MethodAlias: "MFRB_CreateReportByShareReportId", Parameter: parameters }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) { if (result.State === 0) { $(selTr).find("input[columnname=‘ReportId‘]").val(result.Data.ReportId); dosomething(); } }); } //共享报告给他人 function openContactPanel(selTd) { var $selTr = $(selTd).closest("tr"); if (!isImFriendsLoaded) { isImFriendsLoaded = true; initMyContact(); } else { //重置共享界面 $(".ContactPanel tr.ui-state-active").find("input:checkbox").attr("checked", false); //复选框 $(".ContactPanel tr.ui-state-active").removeClass("ui-state-active"); //选中列 $(".ContactPanel tr td.shareState").text(""); //分享标识 } $(".ContactPanel").dialog({ title: ‘分享报告‘, resizable: false, width: 380, modal: true, buttons: [ { text: "确定", click: function () { var $selUsers = $(".contactTable tr.ui-state-active"); if($selUsers.length==0){ showAlert("未选择分享好友。"); return; } isShareReportAndCreate($selTr, function () { ajaxForShareReport($selTr,$selUsers); }); $("#ContactPanel").dialog(‘close‘); } } ] , open: function (event, ui) { //取消dialog自动focus(在终端中ie11下会有绿色边框) $(this).parent(‘.ui-dialog‘).find(‘.ui-state-focus‘).blur(); } }); } function ajaxForShareReport(selTr,selUsers) { var _reportid = $(selTr).find("input[columnname=‘ReportId‘]").val(); var _userIds = ""; for (var i = 0; i < selUsers.length; i++) { _userIds += selUsers.eq(i).attr("crmuserid"); if (i !== selUsers.length - 1) { _userIds += ","; } } var parameters = [_reportid, _userIds]; var dataParameters = { MethodAlias: "MFRB_ShareReport", Parameter: parameters }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) { if (result.State === 0) { $(".ContactPanel").dialog("close"); showAlert("恭喜分享成功!请联系对方查看报告。","分享报告","info"); } else { showAlert("共享出现错误。","分享报告","warning"); } }); } //编辑 function openEditPanel(selTd) { var $selTr = $(selTd).closest("tr"); var _name = $selTr.find("a[columnname=‘Name‘]").attr("columnvalue"); var _author = $selTr.find("label[columnname=‘Author‘]").attr("columnvalue"); var _description = $selTr.find("label[columnname=‘Description‘]").attr("columnvalue"); //绑定编辑前的值 $("#editPanel .s-name").val(_name); $("#editPanel .s-author").val(_author); $("#editPanel .s-description").val(_description); //弹出编辑框 $("#editPanel").dialog({ title: ‘报告编辑‘, resizable: false, width: 364, modal: true, buttons: [ { text: "确定", click: function () { if(!validateReport()){ return; } $("#editPanel").dialog(‘close‘); isShareReportAndCreate($selTr,function () { ajaxForSaveReport($("#editPanel .s-name").val(), $("#editPanel .s-author").val(), $("#editPanel .s-description").val(), $selTr); }); } } ] , open: function (event, ui) { //取消dialog自动focus(在终端中ie11下会有绿色边框) $(this).parent(‘.ui-dialog‘).find(‘.ui-state-focus‘).blur(); } }); } function ajaxForSaveReport(name, author, descri, selTr) { var _reportid = $(selTr).find("input[ columnname=‘ReportId‘]").val(); var parameters = [_reportid, name, author, descri]; var dataParameters = { MethodAlias: "MFRB_UpdateReportBasicInfo", Parameter: parameters }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) { if (result.State === 0) { ReportManager.UpdateRow(result.Data, selTr); } else { showAlert(getResultMsg(result)); } }); } //删除 function openDeletePanel(selTd) { var $selTr = $(selTd).closest("tr"); showConfirm("你确定要永久删除该报告吗?", "删除报告", function () { isShareReportAndCreate($selTr, function () { ajaxForDeleteReport($selTr); }); $("#DeleteTip").dialog(‘close‘); }); } function ajaxForDeleteReport(selTr) { var $selTr = $(selTr); var _reportid = $selTr.find("input[ columnname=‘ReportId‘]").val(); var parameters = [_reportid]; var dataParameters = { MethodAlias: "MFRB_DeleteReport", Parameter: parameters }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) { if (result.State === 0) { ReportManager.DeleteRow(selTr); } else { showAlert(getResultMsg(result)); } }); } //打开报告 function openReport(selTd) { var $selTr = $(selTd).closest("tr"); isShareReportAndCreate($selTr, function () { var _reportid = $selTr.find("input[columnname=‘ReportId‘]").val(); window.location.href = "/WealthManagement/MFRB/Frame/ReportPage.aspx?reportId=" + _reportid; }); } function validateReport(){ var _name=$("#editPanel .s-name").val(); var _author=$("#editPanel .s-author").val(); var _description=$("#editPanel .s-description").val(); var msg=""; if(!_name){ msg += "名称必须填写。"; } if(_name&&_name.length>50){ msg += "名称不能超过50字。"; } if(_author&&_author.length>20){ msg += "作者不能超过20字。"; } if(_description&&_description.length>200){ msg += "描述不能超过200字。"; } if(msg.length>0){ showAlert(msg); return false; } return true; } /*************加载共享用户列表*****************/ var userIdList = ""; var isImFriendsLoaded = false; function initMyContact() { getMyContact(); } function getMyContact() { var parameterArray = []; var dataParameters = { MethodAlias: "MFRB_GetMyContactList", Parameter: parameterArray }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, bindMyContact); } function bindMyContact(xmlhttp) { xmlhttp = $.extend({ Data: [], ErrorCode: "", ErrorMessage: "", State: "", Page: {} }, xmlhttp); if (xmlhttp != null) { if (xmlhttp.State == 0) { var data = xmlhttp.Data; var content = ""; $.each(data, function (i, n) { var isShow="display:none"; if(i===0){ isShow=""; } content = content + "<tbody onclick=‘groupOperate(this)‘ >" + "<tr><td class=‘ui-state-default groupTitle‘ style=‘border-top:0;border-left:0;border-right:0;‘><span class=‘ui-accordion-header-icon ui-icon ui-icon-triangle-1-e‘></span>" + data[i].Key + "(" + data[i].UserList.length + ")</td></tr>" + "</tbody>" + "<tbody style=‘"+isShow+"‘><tr><td>"; $.each(data[i].UserList, function (j, m) { if (data[i].UserList[j].IsShare == 1) { content = content + "<table cellpadding=‘0‘ cellspacing=‘0‘ cellpadding=‘0‘ style=‘width:100%;table-layout:fixed;‘>" + "<tr IMID=‘" + data[i].UserList[j].IMID + "‘ CRMUserId=‘" + data[i].UserList[j].CRMUserId + "‘ name=‘" + data[i].UserList[j].UserId + "‘ onclick=‘checkShare(this)‘ class=‘friendRow ui-state-active isShared‘>" + "<td class=‘friendName‘ style=‘width:60px;‘>" + data[i].UserList[j].UserName + "</td>" + "<td class=‘userId‘ style=‘width:70px;text-align:left;‘>" + data[i].UserList[j].UserId + "</td>" + "<td style=‘overflow: hidden;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;‘>" + data[i].UserList[j].Company + "</td>" //+ "<td class=‘shareState‘>共享</td>" + "</tr></table>"; if (userIdList.indexOf(data[i].UserList[j].CRMUserId + ",") < 0) userIdList = userIdList + data[i].UserList[j].CRMUserId + ","; } else { content = content + "<table cellpadding=‘0‘ cellspacing=‘0‘ cellpadding=‘0‘ style=‘width:100%;table-layout:fixed;‘>" + "<tr IMID=‘" + data[i].UserList[j].IMID + "‘ CRMUserId=‘" + data[i].UserList[j].CRMUserId + "‘ name=‘" + data[i].UserList[j].UserId + "‘ class=‘friendRow‘>" + "<td class=‘friendName‘ style=‘width:20px;‘><input type=‘checkbox‘ onclick=‘checkShare(this)‘ /></td>" + "<td class=‘friendName‘ style=‘width:60px;‘>" + data[i].UserList[j].UserName + "</td>" + "<td class=‘userId‘ style=‘width:70px;text-align:left;‘>" + data[i].UserList[j].UserId + "</td>" + "<td style=‘overflow: hidden;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;‘>" + data[i].UserList[j].Company + "</td>" //+ "<td class=‘shareState‘></td>" + "</tr></table>"; } }); content = content + "</td></tr></tbody>" }); $(".contactTable").show(); $(".contactTable").append(content); $(".contactTable .friendRow").mouseenter(function () { $(this).addClass("ui-state-hover"); }).mouseleave(function () { $(this).removeClass("ui-state-hover"); }); } else { //showAlert(GetResultMsg(xmlhttp), "错误"); } } } //用户组单击操作 function groupOperate(obj) { if ($(obj).next("tbody").is(":visible")) { $(obj).next("tbody").hide(); $(obj).find(".ui-icon").removeClass("ui-icon-triangle-1-s"); } else { $(obj).next("tbody").show(); $(obj).find(".ui-icon").addClass("ui-icon-triangle-1-s"); } } var $tr; //用户单击操作 function checkShare(obj) { $tr=$(obj).closest("tr"); //$tr = $("tr[IMID=‘" + $(obj).attr("IMID") + "‘]"); if ($tr.hasClass("ui-state-active")) { $tr.removeClass("ui-state-active"); clearState($tr.attr("CRMUserId")); if ($tr.hasClass("isShared")) { setUnsharedState(); } } else { $tr.addClass("ui-state-active"); if ($tr.hasClass("isShared")) { setGoodState(); } else { if ($tr.attr("CRMUserId").length > 0) setGoodState(); else setBadState(); } } } //可共享设置 function setGoodState() { //$tr.children(".shareState").text("共享"); userIdList = userIdList + $tr.first().attr("CRMUserId") + ","; } //不可共享设置 function setBadState() { $tr.children(".shareState").text("不可共享"); } //取消共享 function setUnsharedState() { $tr.children(".shareState").text(""); } //清除设置样式 function clearState() { $tr.children(".shareState").text(""); var userID = $tr.first().attr("CRMUserId"); if (userID.length > 0) { if (userIdList.indexOf(userID + ",") >= 0) userIdList = userIdList.replace(userID + ",", ""); } } function shareProd() { if (userIdList.length > 0) { var parameterArray = [productId, windCode, userIdList, imUserName]; var dataParameters = { MethodAlias: "AddUserShareProduct", Parameter: parameterArray }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, closeWindow); } else { var parameterArray = [productId, windCode]; var dataParameters = { MethodAlias: "UnshareProduct", Parameter: parameterArray }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, unshareCloseWindow); } } function closeWindow(xmlhttp) { xmlhttp = $.extend({ Data: [], ErrorCode: "", ErrorMessage: "", State: "", Page: {} }, xmlhttp); if (xmlhttp != null) { if (xmlhttp.State == 0) { window.parent.$(".selectedRow").closest("td").prev().html("已共享"); } else showAlert(getResultMsg(xmlhttp), "错误"); } } function unshareCloseWindow(xmlhttp) { xmlhttp = $.extend({ Data: [], ErrorCode: "", ErrorMessage: "", State: "", Page: {} }, xmlhttp); if (xmlhttp != null) { if (xmlhttp.State == 0) { window.parent.$(".selectedRow").closest("td").prev().html(""); } else if (xmlhttp.ErrorCode && xmlhttp.ErrorMessage) { showAlert(getResultMsg(xmlhttp), "错误"); } } }
时间: 2024-10-16 00:27:42