/** * 管理初始化 */ var DriverActivity = { id: "DriverActivityTable", //表格id seItem: null, //选中的条目 table: null, layerIndex: -1 }; var language =$("#language").val() /** * 初始化表格的列 */ DriverActivity.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?'Activity name':'Nama aktivitas'), field: 'name', visible: true, align: 'center', valign: 'middle'}, {title: language==1?'开始时间':(language==2?'Start time':'Waktu awal'), field: 'startTime', visible: true, align: 'center', valign: 'middle', formatter:function (data) { return currentTime(data) }}, {title: language==1?'结束时间':(language==2?'End time':'Waktu akhir'), field: 'endTime', visible: true, align: 'center', valign: 'middle', formatter:function (data) { return currentTime(data) }}, {title: language==1?'领取人次':(language==2?'Number of pickups':'Jumlah penjemputan'), field: 'number', visible: true, align: 'center', valign: 'middle'}, {title: language==1?'备注':(language==2?'Remarks':'Catatan'), field: 'remark', visible: true, align: 'center', valign: 'middle'}, {title: language==1?'状态':(language==2?'State':'Status'), field: 'status', visible: true, align: 'center', valign: 'middle', formatter: function (value, row) { if(language==1){ if(value==1){ return "待审核"; }else if(value==2){ return "已驳回"; }else if(value==3){ if(new Date()new Date(row.endTime)){ return "已结束"; }else{ return "进行中"; } }else if(value==4){ return "已暂停"; } }else if(language==2){ if(value==1){ return "Pending review"; }else if(value==2){ return "Has been rejected"; }else if(value==3){ if(new Date()new Date(row.endTime)){ return "Has ended"; }else{ return "On going"; } }else if(value==4){ return "Has been paused"; } }else { if(value==1){ return "Tinjauan tertunda"; }else if(value==2){ return "Telah ditolak"; }else if(value==3){ if(new Date()new Date(row.endTime)){ return "Telah berakhir"; }else{ return "Sedang berlangsung"; } }else if(value==4){ return "Telah dijeda"; } } } } ]; }; 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 } /** * 检查是否选中 */ DriverActivity.check = function (type) { var selected = $('#' + this.id).bootstrapTable('getSelections'); if(selected.length == 0){ Feng.info("请先选中表格中的某一记录!"); return false; }else{ //验证类型null删除,1=审核,2=编辑,3=启动/暂停 if(type==null){ DriverActivity.seItem = selected[0]; return true; }else if(type==3 && selected[0].status!=3 && selected[0].status!=4){ Feng.info("当前状态不能暂停/启动!"); return false; }else if(type==3 && selected[0].status==3 && (selected[0].startTime>new Date() || new Date()>selected[0].endTime)){ Feng.info("当前状态不能暂停/启动!"); return false; }else if(type==1 && selected[0].status!=1){ Feng.info("当前状态不能审核!"); return false; }else if(type==2 && selected[0].status!=2){ Feng.info("当前状态不能编辑!"); return false; } DriverActivity.seItem = selected[0]; return true; } }; /** * 点击添加 */ DriverActivity.openAddDriverActivity = function () { var index = layer.open({ type: 2, title: language==1?'添加':(language==2?'Add':'Tambahkan'), area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/driverActivity/driverActivity_add' }); this.layerIndex = index; }; /** * 打开编辑 */ DriverActivity.openUpdateDriverActivity = function () { if (this.check(2)) { var index = layer.open({ type: 2, title: language==1?'编辑':(language==2?'Edit':'Edit'), area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/driverActivity/driverActivity_update/' + DriverActivity.seItem.id }); this.layerIndex = index; } }; /** * 打开查看详情 */ DriverActivity.openDriverActivityDetail = function (a) { if (this.check(null)) { if(a == 2 &&DriverActivity.seItem.status!=1){ Feng.info("请在待审核状态下操作") return; } var index = layer.open({ type: 2, title: language==1?'详情':(language==2?'details':'details'), area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/driverActivity/driverActivity_detail/' + DriverActivity.seItem.id+'?type='+a }); this.layerIndex = index; } }; /** * 删除 */ DriverActivity.delete = function () { if (this.check()) { var ajax = new $ax(Feng.ctxPath + "/driverActivity/delete", function (data) { Feng.success("删除成功!"); DriverActivity.table.refresh(); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("driverActivityId",this.seItem.id); ajax.start(); } }; /** * 启动/暂停 */ DriverActivity.updateStatus = function () { if (this.check(3)) { var ajax = new $ax(Feng.ctxPath + "/driverActivity/updateStatus", function (data) { Feng.success("启动/暂停成功!"); DriverActivity.table.refresh(); }, function (data) { Feng.success("启动/暂停失败!"); }); ajax.set("id",this.seItem.id); ajax.set("status",this.seItem.status==3?4:3); ajax.start(); } }; /** * 领取记录 */ DriverActivity.receiveRecord= function () { if (this.check()) { var index = layer.open({ type: 2, title: language==1?'领取记录':(language==2?'Collect records':'Mengumpulkan catatan'), area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/driverActivity/receiveRecord?activityId='+ DriverActivity.seItem.id }); this.layerIndex = index; } }; /** * 打开立即处理页面 */ DriverActivity.immediately = function () { if (this.check(1)) { var index = layer.open({ type: 2, title: language==1?'审核':(language==2?'Audit':'Audit'), area: ['800px', '420px'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/driverActivity/driverActivity_immediately/' + DriverActivity.seItem.id }); this.layerIndex = index; } }; /** * 查询列表 */ DriverActivity.search = function () { var queryData = {}; queryData['createTime'] = $("#createTime").val(); queryData['name'] = $("#name").val(); DriverActivity.table.refresh({query: queryData}); }; DriverActivity.resetSearch = function () { $("#createTime").val(""); $("#name").val(""); DriverActivity.search(); }; $(function () { var defaultColunms = DriverActivity.initColumn(); var table = new BSTable(DriverActivity.id, "/driverActivity/list", defaultColunms); table.setPaginationType("server"); DriverActivity.table = table.init(); });