var selectedObj, StreetIds = '', BuildIds = '', CompanyIds = '', Names = '';
$('input[name="streetAll"]').click(function () {
//alert(this.checked);
if ($(this).is(':checked')) {
$('input[name="street"]').each(function () {
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked", true);
});
} else {
$('input[name="street"]').each(function () {
$(this).removeAttr("checked", false);
});
//$(this).removeAttr("checked");
}
});
$('input[name="buildAll"]').click(function () {
//alert(this.checked);
if ($(this).is(':checked')) {
$('input[name="build"]').each(function () {
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked", true);
});
} else {
$('input[name="build"]').each(function () {
$(this).removeAttr("checked", false);
});
//$(this).removeAttr("checked");
}
});
$('input[name="companyAll"]').click(function () {
//alert(this.checked);
if ($(this).is(':checked')) {
$('input[name="company"]').each(function () {
//此处如果用attr,会出现第三次失效的情况
$(this).prop("checked", true);
});
} else {
$('input[name="company"]').each(function () {
$(this).removeAttr("checked", false);
});
//$(this).removeAttr("checked");
}
});
$("#type_id").change(function () {
getCompanys();
checkIds();
});
function getBuilds() {
var ids = new Array();
$("input:checkbox[name='street']:checked").each(function (i) {
var val = $(this).val() + ',';
ids += val;
});
if (ids.length > 0) {
$.ajax({
url: pagePath + "/government/activity/getBuildsByStreetIds",
type: "post",
data: {
'streetIds': ids
},
dataType: "json",
success: function (result) {
if (result.success) {
bindBuild(result.obj);
} else {
errorMessage(result.message);
}
},
error: function () {
errorMessage('系统错误!');
}
});
} else {
$(".buildList").empty();
}
}
function bindStreet(streetList) {
$(".streetListPre").empty();
$(".streetListPre").append('
');
$(".streetList").empty();
var str = '';
for (var i = 0; i < streetList.length; i++) {
str += '';
str += ' ';
str += '' + streetList[i].name + ' ';
str += ' ';
}
$(".streetList").append(str);
}
function bindBuild(buildList) {
$(".buildList").empty();
var str = '';
for (var i = 0; i < buildList.length; i++) {
str += '';
str += ' ';
str += '' + buildList[i].name + ' ';
str += ' ';
}
$(".buildList").append(str);
}
function getCompanys() {
var ids = new Array();
$("input:checkbox[name='build']:checked").each(function (i) {
var val = $(this).val() + ',';
ids += val;
});
if (ids.length > 0) {
$.ajax({
url: pagePath + "/government/activity/getCompanysByBuildIds",
type: "post",
data: {
'buildIds': ids,
'type_id': $('#type_id').val()
},
dataType: "json",
success: function (result) {
if (result.success) {
bindCompany(result.obj);
} else {
errorMessage(result.message);
}
},
error: function () {
errorMessage('系统错误!');
}
});
} else {
$(".companyList").empty();
}
}
function bindCompany(companyList) {
$(".companyList").empty();
var str = '';
for (var i = 0; i < companyList.length; i++) {
str += ''
str += ''
str += '
'
str += ''
str += '' + companyList[i].company_name + ' '
str += ' '
str += ' '
str += '
'
}
$(".companyList").append(str);
}
function checkIds() {
var ids = new Array();
StreetIds = '', BuildIds = '', CompanyIds = '', Names = '';
$("input:checkbox[name='street']:checked").each(function (i) {
var val = $(this).val();
StreetIds += val + ',';
Names += ""+$(this).attr("streetName") + " ";
ids.push({id: val, type: 4});
});
$("input:checkbox[name='build']:checked").each(function (i) {
var val = $(this).val();
BuildIds += val + ',';
Names += ""+$(this).attr("buildName") + " ";
ids.push({id: val, type: 1});
});
$("input:checkbox[name='company']:checked").each(function (i) {
var val = $(this).val();
CompanyIds += val + ',';
Names += ""+$(this).attr("companyName") + " ";
ids.push({id: val, type: 3});
});
selectedObj = ids;
}
$("body").keydown(function (event) {
if (event.keyCode == "13") {//keyCode=13是回车键
$('#searchBtn').trigger("click");
}
});
$('#searchBtn').click(function () {
var name = $("input[ name='search']").val();
$.ajax({
url: pagePath + "/government/activity/findStreetBuildCompanyByName",
type: "post",
data: {
'name': name
},
dataType: "json",
success: function (result) {
if (result.success) {
var list = result.obj;
var streetList = new Array();
var buildList = new Array();
var companyList = new Array();
for (var i = 0; i < list.length; i++) {
if (list[i].type == '4') {
streetList.push(list[i]);
} else if (list[i].type == '1') {
buildList.push(list[i]);
} else if (list[i].type == '3') {
companyList.push({id: list[i].id, company_name: list[i].name});
}
}
bindStreet(streetList);
bindBuild(buildList);
bindCompany(companyList);
} else {
errorMessage(result.message);
}
},
error: function () {
errorMessage('系统错误!');
}
});
});
function saveItems() {
parent.$("#pushStreetIds").val(StreetIds);
parent.$("#pushBuildIds").val(BuildIds);
parent.$("#pushCompanyIds").val(CompanyIds);
parent.$("#pushNames").html(Names);
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
}