/** * 角色管理的单例 */ var Task = { id: "TaskTable", //表格id seItem: null, //选中的条目 table: null, layerIndex: -1 }; /** * 初始化表格的列 */ Task.initColumn = function () { var columns = [ {field: 'select_item', radio: true}, {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'}, {title: 'ID', field: 'code', align: 'center', valign: 'middle', width: '100px'}, {title: '任务名称', field: 'name', align: 'center', valign: 'middle', width: '100px', formatter: function (value, row) { return '' + value + ''; } }, {title: '图片', field: 'icon', align: 'center', valign: 'middle', width: '150px', formatter: function (value) { return '' } }, {title: '有效期', field: 'time', align: 'center', valign: 'middle', width: '300px'}, {title: '投放频率', field: 'frequency', align: 'center', valign: 'middle', width: '200px', formatter: function (value,row) { if(value==1){ if(row.frequencyTime == "[]"){ return "每周"; }else { return "每周"+row.frequencyTime.replace("[","(").replace("]",")"); } }else if(value==2){ if(row.frequencyTime == "[]"){ return "每月"; }else { return "每月"+row.frequencyTime.replace("[","(").replace("]",")"); } }else if(value == 0){ return "全部"; } } }, {title: '投放时间点', field: 'pointTime', align: 'center', valign: 'middle', width: '300px', formatter:function (value,row){ if(value!=null && value!=undefined){ value = value.replace("[","(").replace("]",")") } return value; } }, {title: '任务类型', field: 'taskType', align: 'center', valign: 'middle', width: '150px', formatter: function (value) { if(value == 1){ return '长期任务'; } if(value == 2){ return '不定时任务'; } } }, {title: '排序', field: 'sort', align: 'center', valign: 'middle', width: '100px'}, {title: '奖励积分', field: 'bonusPoints', align: 'center', valign: 'middle', width: '100px'}, {title: '领取人数', field: 'lqnumber', align: 'center', valign: 'middle', width: '100px', formatter: function (value, row) { return '' + value + ''; } }, {title: '完成人数', field: 'wcnumber', align: 'center', valign: 'middle', width: '100px', formatter: function (value, row) { return '' + value + ''; } }, {title: '奖励人数', field: 'ljnumber', align: 'center', valign: 'middle', width: '100px', formatter: function (value, row) { return '' + value + ''; } }, {title: '配置人', field: 'updateUser', align: 'center', valign: 'middle', width: '100px'}, {title: '配置时间', field: 'updateTime', align: 'center', valign: 'middle', width: '150px'}, {title: '状态', field: 'state', align: 'center', valign: 'middle', width: '100px', formatter: function (value) { switch (value) { case 1: return '已上架'; case 2: return '已下架'; } } } ] return columns; }; /** * 检查是否选中 */ Task.check = function () { var selected = $('#' + this.id).bootstrapTable('getSelections'); if (selected.length == 0) { Feng.info("请先选中表格中的某一记录!"); return false; } else { Task.seItem = selected[0]; return true; } }; /** * 点击添加 */ Task.openAddTask = function () { var index = layer.open({ type: 2, title: '添加任务', area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/task/openAddTask' }); this.layerIndex = index; }; /** * 点击修改 */ Task.openChangeTask = function () { if (this.check()) { var index = layer.open({ type: 2, title: '编辑任务', area: ['100%', '100%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/task/openChangeTask?id=' + Task.seItem.id }); this.layerIndex = index; } }; /** * 拷贝 */ Task.openCloneTask = function () { if (this.check()) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/task/cloneTask", function (data) { if(data.code == 200 ){ Feng.success("克隆成功!"); Task.table.refresh(); }else{ Feng.error(data.msg); } }, function (data) { Feng.error("克隆失败!" + data.responseJSON.message + "!"); }); ajax.set("id", Task.seItem.id); ajax.start(); }; Feng.confirm("是否确认克隆?", operation); } }; /** * 删除 */ Task.delTask = function () { if (this.check()) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/task/delTask", function (data) { if(data.code == 200 ){ Feng.success("删除成功!"); Task.table.refresh(); }else{ Feng.error(data.msg); } }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", Task.seItem.id); ajax.start(); }; Feng.confirm("是否刪除该任务?", operation); } }; /** * 上架 */ Task.putTask = function () { if (this.check()) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/task/putTask", function (data) { if(data.code == 200 ){ Feng.success("上架成功!"); Task.table.refresh(); }else{ Feng.error(data.msg); } }, function (data) { Feng.error("上架失败!" + data.responseJSON.message + "!"); }); ajax.set("id", Task.seItem.id); ajax.start(); }; Feng.confirm("是否确认上架?", operation); } }; /** * 下架 */ Task.offTask = function () { if (this.check()) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/task/offTask", function (data) { if(data.code == 200 ){ Feng.success("下架成功!"); Task.table.refresh(); }else{ Feng.error(data.msg); } }, function (data) { Feng.error("下架失败!" + data.responseJSON.message + "!"); }); ajax.set("id", Task.seItem.id); ajax.start(); }; Feng.confirm("是否确认下架?", operation); } }; /** * 详情 * @param id */ Task.openTaskInfo = function(id){ var index = layer.open({ type: 2, title: '任务详情', area: ['80%', '90%'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/task/openTaskInfo?id=' + id }); this.layerIndex = index; } /** * 点击用户列表 */ Task.openClickUser = function(id, type){ var index = layer.open({ type: 2, title: '操作用户列表', area: ['1100px', '700px'], //宽高 fix: false, //不固定 maxmin: true, content: Feng.ctxPath + '/task/openClickUser?id=' + id + "&type=" + type }); this.layerIndex = index; } /** * 搜索 */ Task.search = function () { var queryData = {}; queryData['code'] = $("#code").val(); queryData['name'] = $("#name").val(); queryData['taskType'] = $("#taskType").val(); queryData['startIntegral'] = $("#startIntegral").val(); queryData['endIntegral'] = $("#endIntegral").val(); queryData['state'] = $("#state").val(); queryData['createUser'] = $("#createUser").val(); Task.table.setQueryParams({}) Task.table.refresh({query: queryData}); } /** * 重置 */ Task.resetSearch = function(){ var queryData = {}; $("#code").val(''); $("#name").val(''); $("#taskType").val(''); $("#startIntegral").val(''); $("#endIntegral").val(''); $("#state").val(''); $("#createUser").val(''); Task.table.setQueryParams({}) Task.table.refresh({query: queryData}); } $(function () { var defaultColunms = Task.initColumn(); var table = new BSTable(Task.id, "/task/queryTaskList", defaultColunms); table.setPaginationType("server"); Task.table = table.init(); });