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
/**
 * 初始化加油站活动详情对话框
 */
var GasStationActivityInfoDlg = {
    gasStationActivityInfoData : {}
};
 
/**
 * 清除数据
 */
GasStationActivityInfoDlg.clearData = function() {
    this.gasStationActivityInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GasStationActivityInfoDlg.set = function(key, val) {
    this.gasStationActivityInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GasStationActivityInfoDlg.get = function(key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
GasStationActivityInfoDlg.close = function() {
    parent.layer.close(window.parent.GasStationActivity.layerIndex);
}
 
/**
 * 收集数据
 */
GasStationActivityInfoDlg.collectData = function() {
    this
    .set('id')
    .set('code')
    .set('name')
    .set('state')
    .set('createUserId')
    .set('createTime')
    .set('updateUserId')
    .set('updateTime')
    .set('startTime')
    .set('endTime')
    .set('priceShow');
}
 
/**
 * 提交添加
 */
GasStationActivityInfoDlg.addSubmit = function(x) {
 
    const activityId = $("#activityId").val();
    const icon = $("#icon"+x+"").val();
    const iconOld = $("#iconOld"+x+"").val();
    if(null == icon || '' == icon){
        Feng.error("icon图标不能为空");
        return
    }
    var formData = new FormData()  //创建一个forData
    formData.append('file', $("#file"+x+"")[0].files[0]) //把file添加进去  name命名为img
    formData.append("gasStationActivityId", activityId);
    formData.append("icon", icon);
    formData.append("iconOld", iconOld);
    layer.load(); //上传loading
    $.ajax({
        url: Feng.ctxPath + "/gasStationIcon/add",
        data: formData,
        type: "POST",
        async: true,
        cache: false,
        contentType: false,
        processData: false,
        success: function(res) {
            layer.closeAll('loading'); //关闭loading
            if(res.code == 200){
                Feng.success("操作成功!");
                location.reload();
                window.parent.GasStation.table.refresh();
            }else if(res.code == 800){
                layer.alert(res.msg, {
                    icon: 5,
                    title: "提示"
                });
            }else{
                Feng.error(res.msg);
            }
        }
    })
}
 
//icon板块删除数据
GasStationActivityInfoDlg.deleteIcon = function(e,x){
    var operation = function () {
        const activityId = $("#activityId").val();
        const iconOld = $("#iconOld"+x+"").val();
        console.log(iconOld);
        var formData = new FormData()  //创建一个forData
        formData.append("gasStationActivityId", activityId);
        formData.append("icon", iconOld);
        layer.load(); //上传loading
        $.ajax({
            url: Feng.ctxPath + "/gasStationIcon/delete",
            data: formData,
            type: "POST",
            async: true,
            cache: false,
            contentType: false,
            processData: false,
            success: function (res) {
                layer.closeAll('loading'); //关闭loading
                if (res.code == 200) {
                    Feng.success("删除成功!");
                    $(e).parent().parent().parent().parent().remove();
                    location.reload();
                    window.parent.GasStation.table.refresh();
                } else {
                    Feng.error(res.msg);
                }
            }
        })
    };
    Feng.confirm("是否刪除该加油站图标数据?", operation);
 
}
//icon板块减少
GasStationActivityInfoDlg.subtractIcon = function(e){
    $(e).parent().parent().parent().parent().remove();
}
 
//icon板块新增
GasStationActivityInfoDlg.addIcon = function(){
    var x = 1;
    $('.moduleDiv').each(function (e, i) {
        x=x+1;
    })
    var moduleDiv='<div class="moduleDiv"><hr><div class="row">\n' +
        '                    <div class="form-group">\n' +
        '                        <label class="col-sm-3 control-label head-scu-label">加油站icon</label>\n' +
        '                        <div class="col-sm-4">\n' +
        '                            <div id="icon' + x + 'PreId">\n' +
        '                                <div><img width="100px" height="100px" src="'+Feng.ctxPath+'/static/img/NoPIC.png"></div>\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '                        <div class="col-sm-2">\n' +
        '                            <div class="head-scu-btn upload-btn" id="icon' + x + 'BtnId">\n' +
        '                                <i class="fa fa-upload"></i>&nbsp;上传\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '                        <input type="hidden" id="icon' + x + '" value=""/>\n' +
        '                        <div class="col-sm-1" >\n' +
        '                            <i class="fa fa-plus-square" style="font-size:24px" onclick="GasStationActivityInfoDlg.addIcon()"></i>\n' +
        '                            <i class="fa fa-minus-square" style="font-size:24px" onclick="GasStationActivityInfoDlg.subtractIcon(this)"></i>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                    <div class="form-group">\n' +
        '                        <label class="col-sm-3 control-label head-scu-label"></label>\n' +
        '                        <div class="col-sm-8">\n' +
        '                            <div style="color: red;" id="size">推荐尺寸:64px * 90px(宽*高)<br/>推荐大小:不超过300K</div>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                    <div class="form-group">\n' +
        '                        <label class="col-sm-3 control-label"></label>\n' +
        '                        <div class="col-sm-8">\n' +
        '                            <input type="file" id="file'+x+'" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" style="display: none;">\n' +
        '                            <button style="width: 150px;height: 40px;line-height: 30px;background-color: #0E6828;color: #ffffff;" id="chooseFile'+x+'">导入活动加油站</button>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                    <div class="form-group">\n' +
        '                        <label class="col-sm-3 control-label">excel</label>\n' +
        '                        <div class="col-sm-8">\n' +
        '                            <span id="excelName'+x+'"></span>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="row btn-group-m-t">\n' +
        '                    <div class="col-sm-10">\n' +
        '                        <button type="button" class="btn btn-info " onclick="GasStationActivityInfoDlg.addSubmit('+x+')" id="ensure">\n' +
        '                            <i class="fa fa-check"></i>&nbsp;保存\n' +
        '                        </button>\n' +
        '                    </div>\n' +
        '                </div>'+
        '              </div>';
    $(".moduleDiv").last().after(moduleDiv);
    // 初始化icon上传
    var iconUp = new $WebUpload("icon"+x);
    iconUp.setUploadBarId("progressBar");
    iconUp.init();
 
    $("#chooseFile"+x+"").on('click', function () {
        $("#file"+x+"").click();
        $("#file"+x+"").on('change', function () {
            const file = $("#file"+x+"")[0].files[0]
            $("#excelName"+x+"").text(file.name);
        })
    })
}
 
$(function() {
    // 初始化icon上传
    var iconUp = new $WebUpload("icon0");
    iconUp.setUploadBarId("progressBar");
    iconUp.init();
 
    $('#chooseFile0').on('click', function () {
        $('#file0').click();
        $('#file0').on('change', function () {
            const file = $('#file0')[0].files[0]
            $('#excelName0').text(file.name);
        })
    })
    var iconSize = $("#iconSize").val();
    for(var i = 1 ; i < iconSize+1 ; i++){
        // 初始化icon上传
        var iconUp = new $WebUpload("icon"+i);
        iconUp.setUploadBarId("progressBar");
        iconUp.init();
 
        $("#chooseFile"+i).on('click', function () {
            $(this).prev().click();
            $(this).prev().on('change', function (e) {
                const file = $(this)[0].files[0]
                $(this).parent().parent().next().find("span").text(file.name);
            })
        })
    }
});