/** * Created by jinxs on 2016.08.02. */ var webroot = $("#hdWebroot").val(); var rootUrl = webroot + '/Inbox/'; var deleteUrl = rootUrl + "delete"; $(function () { var firstLoad = true; var listUrl = rootUrl + "list"; var changeStatus = rootUrl + "changeMsgStatus"; var dialogSize = {width: 540, height: '80%'};//弹出窗口大小 //----------------------------------------------------------------------- var grid = $('#grid'); var grid1 = $('#grid1'); var dialog = $('#dialog'); var grid_form = $('#grid_form'); var tab = $('#tabForm').uiTabs({ onSelect: function (id, index) { if (id == "modifyPass" && firstLoad) { initReadGrid(); firstLoad = false; } } }); initNoReadGrid(); initBaseInfoForm(); addEvents(); //----------------------------------------------------------------------- function initNoReadGrid() { //初始化搜索框 $('#searchbox').uiSearchbox({ width: 240, prompt: '标题|内容|发送人', searcher: function (v) { grid.uiGrid('loadData', {queryParams: {key: $.trim(v)}, pageIndex: 1}); } }); //初始化grid grid.uiGrid({ url: listUrl, queryParams: {msgstatus: 0}, defaultSortField: 'list.sendtime', }); } function initReadGrid() { //初始化搜索框 $('#searchbox1').uiSearchbox({ width: 240, prompt: '标题|内容|发送人', searcher: function (v) { grid1.uiGrid('loadData', {queryParams: {key: $.trim(v)}, pageIndex: 1}); } }); //初始化grid grid1.uiGrid({ url: listUrl, queryParams: {msgstatus: 1}, defaultSortField: 'list.sendtime' }); } function initBaseInfoForm() { dialog.uiDialog({ title: '查看', width: dialogSize.width, height:dialogSize.height, onOpen: function () { var dialogP = $('#dialog').uiDialog('getUserParam'); var type = dialogP.type; var selGrid; if(type==0){ selGrid=grid; }else{ selGrid=grid1; } grid_form.uiForm('load', selGrid.uiGrid('selectedData')[0]); }, onClose:function () { var dialogP = $('#dialog').uiDialog('getUserParam'); var type = dialogP.type; if(type==0){ var ids = grid.uiGrid('selectedData', 'id'); ajaxChangeStatus(ids,1); } }, buttons: [ { id: 'btnCancel', label: '关闭', icons: {left: 'icon_cancel'}, disabled: false, style: 'button_cancel', onClick: function () { dialog.uiDialog('close'); } } ] }); grid_form.uiForm({ template: 'grid_form_temp', onLoadSuccess: function (data) { } }); } function addEvents() { $('#btnRead').bind('click', function () { changeMsgStatus(grid, 1); }); $('#btnDelete').bind('click', function () { var ids = grid.uiGrid('selectedData', 'id'); if (ids.length == 0) { showResult(false, '请选择要删除的行!', 'alert'); } else { deleteRow(ids, grid); } }); $('#btnNoRead').bind('click', function () { changeMsgStatus(grid1, 0); }); $('#btnDeleteRead').bind('click', function () { var ids = grid1.uiGrid('selectedData', 'id'); if (ids.length == 0) { showResult(false, '请选择要删除的行!', 'alert'); } else { deleteRow(ids, grid1); } }); } function changeMsgStatus(currentGrid, status) { var ids = currentGrid.uiGrid('selectedData', 'id'); if (ids.length == 0) { showResult(false, '请选择要操作的行!', 'alert'); return; } var confirmText = ''; if (status == 1) { confirmText = '已读'; } if (status == 0) { confirmText = '未读'; } confirmText = '确定将选中的【' + ids.length + '】个消息设置为' + confirmText + '吗?'; $.uiMessagebox.confirm({ title: '确认操作', content: confirmText, onClose: function (value) { if (value) { ajaxChangeStatus(ids,status); } } }); } function ajaxChangeStatus(ids,status) { $.ajax({ type: 'post', url: changeStatus, data: {ids: ids, status: status}, dataType: "json", success: function (result) { grid.uiGrid('loadData'); grid1.uiGrid('loadData'); } }); } //----------------------------------------------------------------------- }); //查看 function viewRow(id, type) { var dialog = $('#dialog'); dialog.uiDialog('setUserParam', {type: type}); dialog.uiDialog('open'); dialog.uiDialog('title').html('查看消息'); } // 删除 function deleteRow(id, grid) { deleteData("确定要删除这些消息吗?", deleteUrl, {ids: id}, function (result) { if (result.success) { grid.uiGrid('loadData'); } }); } //删除 function deleteData(confirmText, url, data, callback) { $.uiMessagebox.confirm({ title: '确认操作', content: confirmText, onClose: function (value) { if (value) { $.ajax({ type: 'post', url: url, data: data, dataType: "json", success: function (result) { callback && callback.call(this, result); } }); } } }); }