/** * 管理初始化 */ var TbBanner = { id: "TbBannerTable", //表格id seItem: null, //选中的条目 table: null, layerIndex: -1 }; var language =$("#language").val() /** * 初始化表格的列 */ TbBanner.initColumn = function () { return [ {field: 'selectItem', radio: true}, {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'}, {title: language==1?'添加时间':(language==2?'Add Time':'Tambahkan waktu'), field: 'insertTime', visible: true, align: 'center', valign: 'middle', formatter:function (data){ return currentTime(data) } }, {title:language==1?'类型':(language==2?'Type':'Tipe'), field: 'usePort', visible: true, align: 'center', valign: 'middle', formatter:function (data) { if(language==1){ if(data==1){ return "用户端"; }else { return "司机端" } }else if(language==2){ if(data==1){ return "User's end"; }else { return "Driver's end" } }else { if(data==1){ return "Akhir pengguna"; }else { return "Akhir pengemudi" } } } }, {title: language==1?'icon名称':(language==2?'Icon name':'Nama ikon'), field: 'name', visible: true, align: 'center', valign: 'middle', }, {title: language==1?'显示时间':(language==2?'viewing time':'waktu melihat'), field: 'showStartTime', visible: true, align: 'center', valign: 'middle' }, {title: language==1?'icon图标':(language==2?'Icon logo':'Logo Ikon'), field: 'url', visible: true, align: 'center', valign: 'middle', formatter:function(data){ return '' } }, {title: language==1?'操作':(language==2?'Operate':'Beroperasi'), field: 'state', visible: true, align: 'center', valign: 'middle', formatter:function (value,row){ if(language==1){ if(value==1){ return '正常' } if(value==2){ return '隐藏' } }else if(language==2){ if(value==1){ return 'normal' } if(value==2){ return 'hide' } }else { if(value==1){ return 'normal' } if(value==2){ return 'Sembunyikan' } } } } ]; }; function currentTime(timestamp){ var time = timestamp + ''; if(time.length != 13){ timestamp = timestamp * 1000; } var date = new Date(timestamp);; var Y = date.getFullYear() + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' '; var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':'; var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds()); var strDate = Y + M + D + h + m + s; return strDate } /** * 检查是否选中 */ TbBanner.check = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length == 0){ Feng.info("请先选中表格中的某一记录!"); return false; }else{ TbBanner.seItem = selected[0]; return true; } }; TbBanner.reset = function () { $("#time").val(''); TbBanner.search(); }; /** * 点击添加 */ TbBanner.openAddTbBanner = function () { var index = layer.open({ type: 2, title: language==1?'添加':(language==2?'Add':'Tambahkan'), area: ['80%', '80%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tbBanner/tbBanner_add' }); this.layerIndex = index; }; /** * 打开查看详情 */ TbBanner.openTbBannerDetail = function () { if (this.check()) { var index = layer.open({ type: 2, title: language==1?'详情':(language==2?'details':'details'), area: ['80%', '80%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/tbBanner/tbBanner_update/' + TbBanner.seItem.id }); this.layerIndex = index; } }; /** * 删除 */ TbBanner.delete = function () { if (this.check()) { let a = this.seItem.id var operation = function () { var ajax = new $ax(Feng.ctxPath + "/tbBanner/delete", function (data) { if(language==1){ Feng.success("删除成功!"); }else if(language==2){ Feng.success("Delete succeeded!"); }else { Feng.success("Hapus berhasil!"); } TbBanner.table.refresh(); }, function (data) { if(language==1){ Feng.error("删除失败!" + data.responseJSON.message + "!"); }else if(language==2){ Feng.error("Delete failed!" + data.responseJSON.message + "!"); }else { Feng.error("Hapus gagal!" + data.responseJSON.message + "!"); } }); ajax.set("tbBannerId", a); ajax.start(); } if(language==1){ Feng.confirm("确定要删除该icon?", operation); }else if(language==2){ Feng.confirm("Are you sureto delete this icon?", operation); }else { Feng.confirm("Apakah Anda yakin menghapus ikon ini?", operation); } } }; TbBanner.updateState1 = function (v) { var ajax = new $ax(Feng.ctxPath + "/tbBanner/updateState", function (data) { if(language==1){ swal.success("操作成功!", ""); }else if(language==2){ swal.success("Operate successfully!", ""); }else { swal.success("Operasi berhasil!", ""); } TbBanner.table.refresh(); }, function (data) { if(language==1){ swal("操作失败", data.responseJSON.message + "!", "warning"); }else if(language==2){ swal("Operation failure!", data.responseJSON.message + "!", "warning"); }else { swal("Operasi gagal!", data.responseJSON.message + "!", "warning"); } }); ajax.set("id", v); ajax.set("state", 2); ajax.start(); }; TbBanner.updateState2 = function (v) { var ajax = new $ax(Feng.ctxPath + "/tbBanner/updateState", function (data) { if(language==1){ swal.success("操作成功!", ""); }else if(language==2){ swal.success("Operate successfully!", ""); }else { swal.success("Operasi berhasil!", ""); } TbBanner.table.refresh(); }, function (data) { if(language==1){ swal("操作失败", data.responseJSON.message + "!", "warning"); }else if(language==2){ swal("Operation failure!", data.responseJSON.message + "!", "warning"); }else { swal("Operasi gagal!", data.responseJSON.message + "!", "warning"); } }); ajax.set("id", v); ajax.set("state", 1); ajax.start(); }; /** * 查询列表 */ TbBanner.search = function () { var queryData = {}; TbBanner.table.refresh({query: queryData}); }; $(function () { var defaultColunms = TbBanner.initColumn(); var table = new BSTable(TbBanner.id, "/tbBanner/list", defaultColunms); table.setPaginationType("client"); TbBanner.table = table.init(); });