puzhibing
2023-11-28 7b726d5ff439e7b8bb66369ecc5881e370286bc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/**
 * 角色管理的单例
 */
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 '<a href="#" onclick="Task.openTaskInfo(\'' + row.id + '\')">' + value + '</a>';
            }
        },
        {title: '图片', field: 'icon', align: 'center', valign: 'middle', width: '150px',
            formatter: function (value) {
                return '<img src="' + value + '" style="width: 150px;" onclick="showImg(this)"/>'
            }
        },
        {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 '<a href="#" onclick="Task.openClickUser(\'' + row.id + '\',2)">' + value + '</a>';
            }
        },
        {title: '完成人数', field: 'wcnumber', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a href="#" onclick="Task.openClickUser(\'' + row.id + '\',3)">' + value + '</a>';
            }
        },
        {title: '奖励人数', field: 'ljnumber', align: 'center', valign: 'middle', width: '100px',
            formatter: function (value, row) {
                return '<a href="#" onclick="Task.openClickUser(\'' + row.id + '\',4)">' + value + '</a>';
            }
        },
        {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();
 
});