luodangjia
2024-05-30 4bd9195ff5beeb416792b50bbaea84c56a1b500b
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
/**
 * 管理初始化
 */
var Generalization = {
    id: "GeneralizationTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
Generalization.initColumn = function () {
    return [
            {field: 'selectItem', radio: true},
            {title: '主键id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '添加时间', field: 'insertTime', visible: true, align: 'center', valign: 'middle'},
            {title: '活动名称', field: 'activityName', visible: true, align: 'center', valign: 'middle'},
            {title: '活动时间', field: 'time', visible: true, align: 'center', valign: 'middle'},
            {title: '最多可参与人数', field: 'participateCount', visible: true, align: 'center', valign: 'middle'},
            {title: '当前参与人数', field: 'count', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row) {
                    return '<a href="#"  style="color:cornflowerblue">'+row.count+'</a>' +'&nbsp;' +'&nbsp;'+'&nbsp;'+'&nbsp;'+'&nbsp;'+
                        '<a href="#" onclick="Generalization.activityRecord('+row.id+')" style="color:cornflowerblue">查看领取记录</a>' +'&nbsp;'
                }
            },
            {title: '当前状态', field: 'state', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row) {
                    if(value==1){
                        return "已开启";
                    }else if(value==2){
                        return "未开启";
                    }else if(value==3){
                        return "已结束";
                    }else if(value==4){
                        return "已暂停";
                    }
                }
            },
            {title: '操作', visible: true, align: 'center', valign: 'middle',width:'16%',
                formatter: function (value, row) {
                    if(row.state==1){
                        return '<a href="#" onclick="Generalization.openQrCodeGeneralization('+row.id+')" style="color:cornflowerblue">二维码</a>' +'&nbsp;' +
                            '<a href="#" onclick="Generalization.openGeneralizationDetail('+row.id+')" style="color:cornflowerblue">详情</a>' +'&nbsp;' +
                            '<a href="#" onclick="Generalization.openUpdateGeneralization('+row.id+')" style="color:cornflowerblue">编辑</a>' +'&nbsp;' +
                            '<a href="#" onclick="Generalization.delete('+row.id+')" style="color:cornflowerblue">删除</a>'
                    }else{
                        return '<a href="#" onclick="Generalization.openQrCodeGeneralization('+row.id+')" style="color:cornflowerblue">二维码</a>' +'&nbsp;' +
                            '<a href="#" onclick="Generalization.openGeneralizationDetail('+row.id+')" style="color:cornflowerblue">详情</a>' +'&nbsp;' +
                            '<a href="#" onclick="Generalization.delete('+row.id+')" style="color:cornflowerblue">删除</a>'
                    }
                }
            }
    ];
};
 
/**
 * 检查是否选中
 */
Generalization.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){
            Generalization.seItem = selected[0];
            return true;
        }else if(type==3 && selected[0].state==3){
            Feng.info("当前状态不能暂停/启动!");
            return false;
        }
        Generalization.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加
 */
Generalization.openAddGeneralization = function () {
    var index = layer.open({
        type: 2,
        title: '添加推广活动',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/generalization/addHtml'
    });
    this.layerIndex = index;
};
/**
 * 打开编辑
 */
Generalization.openUpdateGeneralization = function (id) {
    console.log("111222211==="+id);
    var index = layer.open({
        type: 2,
        title: '编辑推广活动',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/generalization/editHtml/' + id
    });
    this.layerIndex = index;
};
/**
 * 打开二维码
 */
Generalization.openQrCodeGeneralization = function (id) {
    var index = layer.open({
        type: 2,
        title: '推广二维码',
        area: ['50%', '50%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/generalization/qrCodeHtml/' + id
    });
    this.layerIndex = index;
};
 
/**
 * 下载二维码
 */
Generalization.downQrCode = function () {
    var imgElement = document.getElementById('qrCode');
    var imgURL = imgElement.src;
    console.log(imgURL)
    // var downloadLink = document.createElement('a');
    // downloadLink.href = imgURL;
    // downloadLink.download = '二维码.png'; // 自定义下载文件名
    // // 将链接添加到文档中(可以是隐藏的)
    // document.body.appendChild(downloadLink);
    // // 触发点击
    // downloadLink.click();
    // // 清理,可选
    // document.body.removeChild(downloadLink);
    // GeneralizationInfoDlg.close();
 
    var ajax = new $ax(Feng.ctxPath + "/generalization/downQrcode", function(data){
        Feng.success("下载成功!");
        GeneralizationInfoDlg.close();
    },function(data){
        Feng.error("下载失败!" + data.responseJSON.message + "!");
    });
    ajax.set("imgURL",imgURL);
    ajax.start();
 
};
 
/**
 * 打开查看详情
 */
Generalization.openGeneralizationDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '详情',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/generalization/generalization_detail/' + id
    });
    this.layerIndex = index;
};
 
/**
 * 删除
 */
Generalization.delete = function (id) {
    var ajax = new $ax(Feng.ctxPath + "/generalization/delete", function (data) {
        Feng.success("删除成功!");
        Generalization.table.refresh();
    }, function (data) {
        Feng.error("删除失败!" + data.responseJSON.message + "!");
    });
    ajax.set("tActivityGeneralizationId",id);
    ajax.start();
};
 
/**
 * 启动/暂停
 */
Generalization.updateStatus = function () {
    if (this.check(3)) {
        var ajax = new $ax(Feng.ctxPath + "/generalization/updateStatus", function (data) {
            Feng.success("启动/暂停成功!");
            Generalization.table.refresh();
        }, function (data) {
            Feng.error("启动/暂停失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id",this.seItem.id);
        ajax.set("status",this.seItem.state==4?1:4);
        ajax.start();
    }
};
/**
 * 领取记录
 */
Generalization.receiveRecord= function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '领取记录',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/generalization/receiveRecord?activityId='+ Generalization.seItem.id
        });
        this.layerIndex = index;
    }
};
 
/**
 * 查询列表
 */
Generalization.search = function () {
    var queryData = {};
    queryData['createTime'] = $("#createTime").val();
    queryData['activityName'] = $("#activityName").val();
    queryData['state'] = $("#state").val();
    Generalization.table.refresh({query: queryData});
};
Generalization.resetSearch = function () {
    $("#createTime").val("");
    $("#activityName").val("");
    $("#state").val("");
    Generalization.search();
};
$(function () {
    var defaultColunms = Generalization.initColumn();
    var table = new BSTable(Generalization.id, "/generalization/list", defaultColunms);
    table.setPaginationType("server");
    Generalization.table = table.init();
});