/**
* 初始化租房申请详情对话框
*/
var HouseRentingInfoDlg = {
houseRentingInfoData : {},
validateFields: {
talentId: {validators: {notEmpty: {message: '申报对象不能为空'}}},
email: {validators: {notEmpty: {message: '电子邮箱不能为空'}}},
houseType: {validators: {notEmpty: {message: '拟申请租住人才社区不能为空'}}},
cardType: {validators: {notEmpty: {message: '证件类型不能为空'}}},
idCard: {validators: {notEmpty: {message: '证件号码不能为空'}}},
marryStatus: {validators: {notEmpty: {message: '婚姻状态不能为空'}}},
}
};
/**
* 清除数据
*/
HouseRentingInfoDlg.clearData = function() {
this.houseRentingInfoData = {};
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
HouseRentingInfoDlg.set = function(key, val) {
this.houseRentingInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
return this;
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
HouseRentingInfoDlg.get = function(key) {
return $("#" + key).val();
}
/**
* 关闭此对话框
*/
HouseRentingInfoDlg.close = function() {
parent.layer.close(window.parent.HouseRenting.layerIndex);
}
/**
* 收集数据
*/
HouseRentingInfoDlg.collectData = function() {
this
.set('id')
.set('type')
.set('talentId')
.set('phone')
.set('email')
.set('marryStatus')
.set('spouseName')
.set('spouseSex')
.set('spouseCardType')
.set('spouseIdCard')
.set('spouseTalentArrange')
.set('spouseNativePlace')
.set('spouseEntryTime')
.set('spousePost')
.set('spouseEnterpriseName')
.set('spouseEnterpriseAddress')
.set('spouseAddress')
.set('spousePhone')
.set('spouseEmail')
.set('houseType')
.set('checkState');
this.houseRentingInfoData['pensionDetail'] = Feng.getCheckBoxValues("pensionDetail");
this.houseRentingInfoData['unemploymentDetail'] = Feng.getCheckBoxValues("unemploymentDetail");
this.houseRentingInfoData['medicaDetail'] = Feng.getCheckBoxValues("medicaDetail");
this.houseRentingInfoData['taxDetail'] = Feng.getCheckBoxValues("taxDetail");
}
/**
* 验证数据
*/
HouseRentingInfoDlg.validate = function () {
$('#houseRentingInfoForm').data("bootstrapValidator").resetForm();
$('#houseRentingInfoForm').bootstrapValidator('validate');
return $("#houseRentingInfoForm").data('bootstrapValidator').isValid();
}
HouseRentingInfoDlg.nameChange = function(){
var talentId = $("#talentId").val();
if(Feng.isNotEmptyStr(talentId)){
var ajax = new $ax(Feng.ctxPath + "/api/talentInfo/detail/"+talentId, function(data){
var talentInfo = data;
$("#name").val(talentInfo.name);
$("#sex").val(talentInfo.sex);
$("#cardType").val(talentInfo.cardType);
$("#idCard").val(talentInfo.idCard);
$("#nativePlace").val(talentInfo.provinceName+talentInfo.cityName+talentInfo.countyName);
$("#talentArrange").val(talentInfo.talentArrange).trigger("change");
$("#entryTime").val(talentInfo.entryTime);
$("#post").val(talentInfo.post);
$("#enterpriseAddress").val(talentInfo.enterpriseAddress);
$("#phone").val(talentInfo.phone);
$("#email").val(talentInfo.email);
},function(data){
Feng.error("查询失败!" + data.responseJSON.message + "!");
});
ajax.start();
}
}
/**
* 添加未成年子女
*/
HouseRentingInfoDlg.addChild = function(){
var options = $("#cardType").html();
$("#childData").append(
'
\n' +
'
\n' +
'
'+
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'
'+
'
');
}
/**
* 删除子女信息
*/
HouseRentingInfoDlg.reduceChild = function(context){
var id = $(context).parent().find("input[name='id']").val();
if(Feng.isEmptyStr(id)){
$(context).parent().remove();
if($("#childData").children().length == 0){
HouseRentingInfoDlg.addChild();
}
}else{
if(!validateIsEdit())return;
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/api/houseRenting/deleteChildren", function(data){
if(data.code == 200){
$(context).parent().remove();
Feng.success(data.msg);
if($("#childData").children().length == 0){
HouseRentingInfoDlg.addChild();
}
}else{
Feng.info(data.msg);
}
},function(data){
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set("id",id);
ajax.start();
}
Feng.confirm("删除后无法恢复,确认删除吗?", operation);
}
}
/**
* 提交添加
*/
HouseRentingInfoDlg.addSubmit = function() {
var id = $("#id").val();
if(Feng.isNotEmptyStr(id)){
HouseRentingInfoDlg.editSubmit(1);
return;
}
this.clearData();
this.collectData();
if(!HouseRentingInfoDlg.validate()){
return ;
}
//提交信息
var child = new Array();
var error = "";
$("#childData .col-sm-12").each(function (index) {
var id = $(this).find("input[name='id']").val();
var pId = $(this).find("input[name='pId']").val();
var childName = $(this).find("input[name='childName']").val();
var childCardType = $(this).find("select[name='childCardType']").val();
var childIdCard = $(this).find("input[name='childIdCard']").val();
if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(childName) || Feng.isNotEmptyStr(childCardType) || Feng.isNotEmptyStr(childIdCard)){
if(Feng.isEmptyStr(childName)){
error = error + "第"+ (index + 1) + "行未成年子女姓名为空;\n";
}
if(Feng.isEmptyStr(childCardType)){
error = error + "第"+ (index + 1) + "行未成年子女证件类型为空;\n";
}
if(Feng.isEmptyStr(childIdCard)){
error = error + "第"+ (index + 1) + "行未成年子女证件号码为空;\n";
}
child.push({"id":id,"pId":pId,"name":childName,"cardType":childCardType,"idCard":childIdCard});
}
});
if (Feng.isNotEmptyStr(error)){
Feng.info(error);
return;
}
this.houseRentingInfoData['childList'] = child;
var ajax = new $ax(Feng.ctxPath + "/api/houseRenting/add", function(data){
if(data.code == 200){
var obj = data.obj;
var childList = obj.childList;
Feng.success(data.msg);
$("#id").val(obj.id);
$("#type").val(obj.type);
$("#fileLi").removeAttr("style");
$("#checkState").val(obj.checkState);
HouseRentingInfoDlg.initChildData(childList);
}else{
Feng.info(data.msg);
}
},function(data){
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.setcontentType("application/json;charset=utf-8");
ajax.setData(JSON.stringify(this.houseRentingInfoData));
ajax.start();
}
/**
* 提交修改
*/
HouseRentingInfoDlg.editSubmit = function(type) {
this.clearData();
this.collectData();
if(!validateIsEdit())return;
if(!HouseRentingInfoDlg.validate()){
return ;
}
//提交信息
var child = new Array();
var error = "";
$("#childData .col-sm-12").each(function (index) {
var id = $(this).find("input[name='id']").val();
var pId = $(this).find("input[name='pId']").val();
var childName = $(this).find("input[name='childName']").val();
var childCardType = $(this).find("select[name='childCardType']").val();
var childIdCard = $(this).find("input[name='childIdCard']").val();
if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(childName) || Feng.isNotEmptyStr(childCardType) || Feng.isNotEmptyStr(childIdCard)){
if(Feng.isEmptyStr(childName)){
error = error + "第"+ (index + 1) + "行未成年子女姓名为空;\n";
}
if(Feng.isEmptyStr(childCardType)){
error = error + "第"+ (index + 1) + "行未成年子女证件类型为空;\n";
}
if(Feng.isEmptyStr(childIdCard)){
error = error + "第"+ (index + 1) + "行未成年子女证件号码为空;\n";
}
child.push({"id":id,"pId":pId,"name":childName,"cardType":childCardType,"idCard":childIdCard});
}
});
if (Feng.isNotEmptyStr(error)){
Feng.info(error);
return;
}
this.houseRentingInfoData['childList'] = child;
var ajax = new $ax(Feng.ctxPath + "/api/houseRenting/update", function(data){
if(data.code == 200){
if(type == 1){
var childList = data.obj.childList;
Feng.success(data.msg);
HouseRentingInfoDlg.initChildData(childList);
}else{
HouseRentingInfoDlg.submitToCheck();
}
}else{
Feng.info(data.msg);
}
},function(data){
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.setcontentType("application/json;charset=utf-8");
ajax.setData(JSON.stringify(this.houseRentingInfoData));
ajax.start();
}
/**
* 提交审核
*/
HouseRentingInfoDlg.submitToCheck = function(){
if(!validateIsEdit())return;
var operation = function() {
var ajax = new $ax(Feng.ctxPath + "/api/houseRenting/submitToCheck", function (data) {
if(data.code==200){
Feng.success(data.msg);
window.parent.HouseRenting.table.refresh();
HouseRentingInfoDlg.close();
}else{
Feng.error(data.msg);
}
}, function (data) {
Feng.error("提交审核失败!" + data.responseJSON.message + "!");
});
ajax.set("id", $("#id").val());
ajax.start();
}
Feng.confirm("请确认基础信息已核对无误,相应附件已上传,一旦提交,无法修改", operation);
}
/**
* 校验是否显示按钮
* @param type 类型 1-上传按钮,2-修改删除按钮
* @param row
* @returns {string}
*/
function validUploadButton(type,row,fileId){
var files = $("#files").val();
var checkState = $("#checkState").val();
if(Feng.isEmptyStr(checkState)||checkState==1 || (checkState == 10 )){
return type == 1?
""
:
"" +
"";
}else{
return type == 1?"":"" ;
}
}
function validateIsEdit(){
var id = $("#id").val();
var checkState = $("#checkState").val();
if(Feng.isEmptyStr(id)){
Feng.info("请先填写基础信息并上传附件");
return false;
}
if(checkState != 1 && checkState != 10){
if(checkState==-1){
Feng.error("您的申报审核不通过,无法修改");
return false;
}else if(checkState>=30){
Feng.error("您的申报已审核通过,无法修改");
return false;
}else{
Feng.error("您的申报正在审核中,请耐心等待");
return false;
}
}
return true;
}
/**
* 初始化子女信息
* @param list
*/
HouseRentingInfoDlg.initChildData = function(list){
var options = $("#cardType").html();
var html = "";
for(var key in list) {
html = html +
'\n' +
'
\n' +
'
' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'
'+
'
';
}
if(Feng.isEmptyStr(html)){
html = html +
'\n' +
'
\n' +
'
' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'\n' +
'
\n' +
'
\n' +
'
';
}
$("#childData").empty().append(html);
$("#childData select").each(function () {
$(this).val($(this).attr("value"))
})
if(list == null){
HouseRentingInfoDlg.addChild();
}
}
HouseRentingInfoDlg.checkSbAndTax = function(){
var pensionDetail = $("#pensionDetail").attr("value");
var unemploymentDetail = $("#unemploymentDetail").attr("value");
var medicaDetail = $("#medicaDetail").attr("value");
var taxDetail = $("#taxDetail").attr("value");
$("#pensionDetail input").each(function () {
if(pensionDetail.indexOf($(this).val())!= -1){
$(this).attr("checked", true);
}
})
$("#unemploymentDetail input").each(function () {
if(unemploymentDetail.indexOf($(this).val())!= -1){
$(this).attr("checked", true);
}
})
$("#medicaDetail input").each(function () {
if(medicaDetail.indexOf($(this).val())!= -1){
$(this).attr("checked", true);
}
})
$("#taxDetail input").each(function () {
if(taxDetail.indexOf($(this).val())!= -1){
$(this).attr("checked", true);
}
})
}
$(function() {
Feng.initValidatorTip("houseRentingInfoForm", HouseRentingInfoDlg.validateFields);
//批量加载字典表数据
var arr = [
{"name":"cardType","code":"un_cardType"},
{"name":"talentArrange","code":"un_talentLevel"},
{"name":"houseType","code":"un_renting_houseType"},
{"name":"marryStatus","code":"un_marryStatus"},
{"name":"spouseCardType","code":"un_cardType"},
{"name":"spouseTalentArrange","code":"un_talentLevel"}];
Feng.findChildDictBatch(JSON.stringify(arr));
$("select[name='childCardType']").empty().append($("#cardType").html());
//加载时间控件
$(".date").each(function(){laydate.render({
elem: this,type: 'date',trigger: 'click'
});
});
var id = $("#id").val();
if(Feng.isNotEmptyStr(id)){
$("select").each(function () {$(this).val($(this).attr("value")).trigger("change");});
$("#fileLi").removeAttr("style");
HouseRentingInfoDlg.checkSbAndTax();
Feng.getCheckLog("logTable",{"type":CONFIG.project_renting,"mainId":id,"typeFileId":"","active":1})
}else{
$("#fileLi").attr("style","pointer-events: none");
}
});