
/**
 * 初始化购房补贴详情对话框
 */
var HousepurchaseInfoDlg = {
    housepurchaseInfoData: {},
    validateFields: {
        enterpriseId: {validators: {notEmpty: {message: '所属企业不能为空'}}},
        name: {validators: {notEmpty: {message: '姓名不能为空'}}},
        declareObject: {validators: {notEmpty: {message: '申报对象不能为空'}}},
        declareType: {validators: {notEmpty: {message: '申报类型不能为空'}}},
        cardType: {validators: {notEmpty: {message: '证件类型不能为空'}}},
        idCard: {validators: {notEmpty: {message: '证件号码不能为空'}}},
        marryStatus: {validators: {notEmpty: {message: '婚姻状态不能为空'}}},
        // houseAddress: {validators: {notEmpty: {message: '房屋坐落地址不能为空'}}},
        // houseArea: {validators: {notEmpty: {message: '房源购置面积不能为空'}}},
        // recordTime: {validators: {notEmpty: {message: '商品房购房合同备案时间不能为空'}}},
        // houseMoney: {validators: {notEmpty: {message: '房屋成交金额不能为空'}}},
        // isEnjoyOther: {validators: {notEmpty: {message: '是否享受我市其他政策不能为空'}}},
        // realEstateNo: {
        //     validators: {
        //         notEmpty: {
        //             message: '不动产权证编号不能为空'
        //         },
        //         regexp: {
        //             regexp: /^闽\([0-9]{4}\)晋江市不动产权第\([0-9]+\)号$/,
        //             message: "不动产权证编号格式不正确"
        //         }
        //     }
        // },
        // recordNo: {
        //     validators: {
        //         notEmpty: {
        //             message: '备案合同编号不能为空'
        //         },
        //         regexp: {
        //             regexp: /^\d+$/,
        //             message: "备案合同编号格式不正确"
        //         }
        //     }
        // },
        phone: {
            validators: {
                notEmpty: {
                    message: '手机号码不能为空'
                },
                regexp: {
                    regexp: /0?(13|14|15|16|17|18|19)[0-9]{9}/,
                    message: "手机号码格式不正确"
                }
            }
        },
        bank: {
            validators: {
                notEmpty: {
                    message: '开户银行不能为空'
                },
                regexp: {
                    regexp: /^[\u4e00-\u9fa5]*银行$/,
                    message: "开户银行格式不正确"
                }
            }
        },
        bankAccount: {
            validators: {
                notEmpty: {
                    message: '银行账号不能为空'
                },
                regexp: {
                    regexp: /^\d+$/,
                    message: "银行账号格式不正确"
                }
            }
        },
        // number:{
        //     validators: {
        //         notEmpty: {
        //             message: '享受第几次购房补贴不能为空'
        //         },
        //         regexp: {
        //             regexp: /^[1-5]$/,
        //             message: "享受第几次购房补贴格式不正确"
        //         }
        //     }
        // }
    }
};

/**
 * 清除数据
 */
HousepurchaseInfoDlg.clearData = function () {
    this.housepurchaseInfoData = {};
}

/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
HousepurchaseInfoDlg.set = function (key, val) {
    this.housepurchaseInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
HousepurchaseInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
HousepurchaseInfoDlg.close = function () {
    parent.layer.close(window.parent.Housepurchase.layerIndex);
}


/**
 * 初始化子女信息
 * @param list
 */
HousepurchaseInfoDlg.initChildData = function (list) {
    var options = $("#cardType").html();
    var html = "";
    for (var key in list) {
        html = html +
                '<div class="col-sm-12">\n' +
                '<input type="hidden"  name="id" value="' + list[key].id + '"/>\n' +
                '<input type="hidden" name="pId" value="' + list[key].pId + '"/>' +
                '<div class="rowGroup col-sm-3">\n' +
                '<input type="text" class="form-control" name="childName" value="' + list[key].name + '" placeholder="未成年子女姓名"/>\n' +
                '</div>\n' +
                '<div class="rowGroup col-sm-3">\n' +
                '<select class="form-control" name="childCardType" value="' + list[key].cardType + '" placeholder="未成年子女证件类型">\n' +
                options +
                '</select>\n' +
                '</div>\n' +
                '<div class="rowGroup col-sm-3">\n' +
                '<input type="text" class="form-control" name="childIdCard" value="' + list[key].idCard + '" placeholder="未成年子女证件号码"/>\n' +
                '</div>\n' +
                '</div>';
    }
    $("#childData").empty().append(html);
    $("#childData select").each(function () {
        $(this).val($(this).attr("value"))
    })
    if (list == null) {
        HousepurchaseInfoDlg.addChild();
    }
}



/**
 * 申报对象级联
 */
HousepurchaseInfoDlg.declareObjChange = function () {
    var declareObj = $("#declareObject").val();
    switch (declareObj) {
        case "":
            break;
        case "1":                     //新政策中公布入选为晋江市现代产业体系人才后再购房对象
            break;
        case "2":                     //旧政策中取得购房补贴指标后完成购房，且符合新政策认定标准对象(在库)
            Feng.info("此种对象请通过线下申报，线上不支持旧政策的申报流程！");
            break;
        case "3":                     //旧政策中取得购房补贴指标后完成购房，且符合新政策认定标准对象(在库)
            Feng.info("此种对象请通过线下申报，线上不支持旧政策的申报流程！");
            break;
    }
}

/**
 * 根据申报类型
 */
HousepurchaseInfoDlg.typeChange = function () {
    var type = $("#declareType").val();
    if (type == null) {
        $("#realEstateNo,#recordNo,#houseAddress,#houseArea,#recordTime,#houseMoney,#number,#isEnjoyOther").val("").parent().css("display", "none");
    }
    if (type == 1) {
        $("#realEstateNo,#recordNo,#houseAddress,#houseArea,#recordTime,#houseMoney,#number,#isEnjoyOther").parent().css("display", "block");
    }
    if (type == 2) {
        $("#realEstateNo,#recordNo,#houseAddress,#houseArea,#recordTime,#houseMoney,#number,#isEnjoyOther").val("").parent().css("display", "none");
    }
}

/**
 * 获取认定条件
 */
HousepurchaseInfoDlg.getIdentifyCondition = function () {
    var level = $("#talentArrange").val();
    if (level == null || level == '') {
        $("#identifyCondition").empty();
        return;
    }
    Feng.addAjaxSelect({
        "id": "identifyCondition",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/common/api/findIdentifyConditionByLevel?level=" + level
    });
}


/**
 * 校验是否显示按钮
 * @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 && files.indexOf(row.id) != -1)) {
        return type == 1 ?
                "<button type='button' onclick=\"checkFile(this,'" + row.id + "','" + null + "')\" style='margin-right: 10px' class=\"btn btn-xs btn-info\">" +
                "<i class=\"fa fa-upload\"></i>上传" +
                "</button>"
                :
                "<button type=\'button\' onclick=\"checkFile(this,'" + row.id + "','" + fileId + "')\" style=\'margin-right: 10px\' class=\"btn btn-xs btn-info\">" +
                "<i class=\"fa fa-paste\"></i>修改" +
                "</button>" +
                "<button type='button' onclick=\"deleteFile('" + fileId + "','" + CONFIG.project_house + "')\" class=\"btn btn-xs btn-danger\">" +
                "<i class=\"fa fa-times\"></i>删除" +
                "</button>";
    } else {
        return type == 1 ? "" : "";
    }
}


$(function () {
    //批量加载字典表数据
    var arr = [
        {"name": "cardType", "code": "card_type"},
        {"name": "spouseCardType", "code": "card_type"},
        {"name": "childCardType", "code": "card_type"},
        {"name": "marryStatus", "code": "marry_status"},
        {"name": "talentArrange", "code": "talent_arrange"},
        {"name": "street", "code": "street"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    $(".other_talentArrange").empty().append($("#talentArrange").html());
    loadProvince();
    $("select").each(function () {
        $(this).val($(this).attr("value")).trigger("change");
    });
    var id = $("#id").val();
    Feng.getCheckLog("logTable", {"type": CONFIG.project_house, "mainId": id, "typeFileId": "", "active": 1})
});
