无关风月
2025-03-20 2ad97245d64b65132507cab36ad89d968edb7705
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
/**
 * 用户详情对话框(可用于添加和修改对话框)
 */
var VipChannelInfo = {
    userInfoData: {},
    layerIndex: -1,
    exposureCrowd: $('#exposureCrowd').val(),
    mapPosition: [],
    position: null
};
 
var editor = null;
 
/**
 * 关闭此对话框
 */
VipChannelInfo.close = function () {
    parent.layer.close(window.parent.VipChannel.layerIndex);
};
 
 
/**
 * 提交添加
 */
VipChannelInfo.addSubmit = function () {
    let name = $('#name').val();
    let distance = $('#distance').val();
    let gasStation = $('#gasStation').val();
    let file = $('#file')[0].files;
    let type = $('input[name="type"]:checked').val();
    let startTime = $('#startTime').val();
    let invalidDistance = $('#invalidDistance').val();
    if(null == name || '' == name){
        Feng.error("入会渠道不能为空");
        return
    }
    if(type == "1" && (null == distance || '' == distance)){
        Feng.error("距离不能为空");
        return
    }
    if(type == "1" && distance <= 0){
        Feng.error("距离必须大于0KM");
        return
    }
    if(type == "1" && file.length == 0 && (null == gasStation || '' == gasStation)){
        Feng.error("加油站不能为空");
        return
    }
    if(null == startTime || '' == startTime){
        Feng.error("生效周期不能为空");
        return
    }
    if(type == "2" && (null == invalidDistance || '' == invalidDistance)){
        Feng.error("无效统计范围限定不能为空");
        return
    }
    if(type == "2" && invalidDistance <= 0){
        Feng.error("无效统计范围限定必须大于0M");
        return
    }
    if(type == "2" && (VipChannelInfo.mapPosition.length == 0 || $('tbody tr td').length == 0)){
        Feng.error("请添加地理位置信息");
        return
    }
    let times = startTime.split(" - ");
 
    var formData = new FormData()  //创建一个forData
    formData.append('file', $('#file')[0].files[0]) //把file添加进去  name命名为img
    formData.append("name", name);
    formData.append("startTime", times[0]);
    formData.append("endTime", times[1]);
    formData.append("invalidDistance", invalidDistance);
    formData.append("distance", distance);
    formData.append("gasStation", (null == gasStation) ? '' : gasStation.toString());
    formData.append("type", type);
    formData.append("position", JSON.stringify(VipChannelInfo.mapPosition));
    layer.load(); //上传loading
    $.ajax({
        url: Feng.ctxPath + "/vipChannel/saveVipChannel",
        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("添加成功");
                window.parent.VipChannel.table.refresh();
                VipChannelInfo.close();
            }else{
                Feng.error(res.msg);
            }
        }
    })
};
 
/**
 * 提交修改
 */
VipChannelInfo.editSubmit = function () {
    let name = $('#name').val();
    let distance = $('#distance').val();
    let gasStation = $('#gasStation').val();
    let file = $('#file')[0].files;
    let type = $('input[name="type"]:checked').val();
    let startTime = $('#startTime').val();
    let invalidDistance = $('#invalidDistance').val();
    if(null == name || '' == name){
        Feng.error("入会渠道不能为空");
        return
    }
    if(type == "1" && (null == distance || '' == distance)){
        Feng.error("距离不能为空");
        return
    }
    if(type == "1" && distance <= 0){
        Feng.error("距离必须大于0KM");
        return
    }
    if(type == "1" && file.length == 0 && (null == gasStation || '' == gasStation)){
        Feng.error("加油站不能为空");
        return
    }
    if(null == startTime || '' == startTime){
        Feng.error("生效周期不能为空");
        return
    }
    if(type == "2" && (null == invalidDistance || '' == invalidDistance)){
        Feng.error("无效统计范围限定不能为空");
        return
    }
    if(type == "2" && invalidDistance <= 0){
        Feng.error("无效统计范围限定必须大于0M");
        return
    }
    if(type == "2" && (VipChannelInfo.mapPosition.length == 0 || $('tbody tr td').length == 0)){
        Feng.error("请添加地理位置信息");
        return
    }
    let times = startTime.split(" - ");
 
    var formData = new FormData()  //创建一个forData
    formData.append('file', $('#file')[0].files[0]) //把file添加进去  name命名为img
    formData.append("id", $('#id').val());
    formData.append("name", name);
    formData.append("startTime", times[0]);
    formData.append("endTime", times[1]);
    formData.append("invalidDistance", invalidDistance);
    formData.append("distance", distance);
    formData.append("gasStation", (null == gasStation) ? '' : gasStation.toString());
    formData.append("type", type);
    formData.append("position", JSON.stringify(VipChannelInfo.mapPosition));
    layer.load(); //上传loading
    $.ajax({
        url: Feng.ctxPath + "/vipChannel/saveVipChannel",
        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("编辑成功");
                window.parent.VipChannel.table.refresh();
                VipChannelInfo.close();
            }else{
                Feng.error(res.msg);
            }
        }
    })
};
 
 
VipChannelInfo.initTable = function(){
    var str = '';
    for(var i in VipChannelInfo.mapPosition){
        var name = VipChannelInfo.mapPosition[i].name;
        var address = VipChannelInfo.mapPosition[i].address;
        str += '<tr><td><input value="' + name + '" onblur="VipChannelInfo.updatePositionName(' + i + ', this)" style="height: 100%;width: 100%;border: none;text-align: center;"></td><td>' + address + '</td><td><a href="#" onclick="VipChannelInfo.delMapPosition(' + i + ')">删除</a></td></tr>'
    }
    $('table tbody').html(str);
}
 
 
VipChannelInfo.updatePositionName = function(index, e){
    for(var i in VipChannelInfo.mapPosition){
        if(i == index){
            VipChannelInfo.mapPosition[i].name = $(e).val();
        }
    }
    VipChannelInfo.initTable();
}
 
 
VipChannelInfo.addMapPosition = function(){
    if(VipChannelInfo.position == null){
        Feng.info("请选择有效的位置");
        return
    }
    VipChannelInfo.initTable();
    $('#tipinput').val('');
    VipChannelInfo.position = null;
}
 
VipChannelInfo.delMapPosition = function(index){
    var st = [];
    for(var i in VipChannelInfo.mapPosition){
        if(i != index){
            st.push(VipChannelInfo.mapPosition[i]);
        }
    }
    VipChannelInfo.mapPosition = st;
    VipChannelInfo.initTable();
}
 
 
$(function () {
    if($('#id').val() != ''){
        var position = $('#position').val();
        VipChannelInfo.mapPosition = JSON.parse(position);
        var str = '';
        for(var i in VipChannelInfo.mapPosition){
            var name = VipChannelInfo.mapPosition[i].name;
            var address = VipChannelInfo.mapPosition[i].address;
            str += '<tr><td><input value="' + name + '" onblur="VipChannelInfo.updatePositionName(' + i + ', this)" style="height: 100%;width: 100%;border: none;text-align: center;"></td><td>' + address + '</td><td><a href="#" onclick="VipChannelInfo.delMapPosition(' + i + ')">删除</a></td></tr>'
        }
        $('table tbody').html(str);
    }
 
    $('#chooseFile').on('click', function () {
        $('#file').val('');
        $('#file').click();
        $('#file').on('change', function () {
            const file = $('#file')[0].files[0]
            $('#excelName').text(file.name);
        })
    })
 
    $('input[name="type"]').each(function (i, e) {
        $(e).change(function () {
            if($(this).val() == 1){
                $('.gasStation').show();
                $('.other').hide();
            }else{
                $('.gasStation').hide();
                $('.other').show();
            }
        })
    })
});