/**
|
* 用户详情对话框(可用于添加和修改对话框)
|
*/
|
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();
|
}
|
})
|
})
|
});
|