function returnValue(id, name) {

    $('#orgid').val(id);
    $('#orgname').val(name);
}

function testEmail(str) {
    var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (reg.test(str)) {
        return true;
    } else {
        return false;
    }
}


function tijiao(call) {
    var $accountNameIpt = $('#accountName').val();
    var $usernameIpt = $('#userName').val();
    var $emailIpt = $('#email').val();
    if ($accountNameIpt == '') {
        topWin.layer.msg("用户账号不能为空");
        return;
    }
    if ($usernameIpt == '') {
        topWin.layer.msg("姓名不能为空");
        return;
    }
    var aa = $emailIpt;
    if (aa == '') {
    } else {
        if (!testEmail(aa)) {
            topWin.layer.msg("请输入正确的Email");
            return;
        }
    }
    var url = g.ctx + "pc/sys/user/save";
    var userForm = {
        orgId: $("#orgId").val(),
        deptCode: $("#deptCodeId").val(),
        accountName: $("#accountName").val(),
        username: $("#userName").val(),
        sex: $("#sex option:selected").val(),
        email: $("#email").val(),
        cardId: $("#cardId").val(),
        birthday: $("#birthday").val(),
        educationalHistory: $("#educationalHistory").val(),
        professional: $("#professional").val(),
        position: $("#position").val(),
        phone: $("#phone").val(),
        startFromDate: $("#startFromDate").val(),
        description: $("#description").val()
    };
    if ($("#deptCode").length >= 1) {
        userForm.deptName = $("#deptCode").textbox('getValue')
    }
    if ($("#supplierName").length >= 1) {
        userForm.supplierId = $("#supplierId").val()
    }
    $.ajax({
        url: url,
        method: "POST",
        data: userForm,
        success: function (data) {
            topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                topWin.layer.close(idx);
                call();
            });
        },
        error: function (data) {
            topWin.layer.alert(data.responseJSON.message, {icon: 2});
        }
    });
}

function doSearch() {
    var userOrgyDialog = openDialog('userOrgyDialog', g.ctx + 'pc/sys/org/orgTree', {
        title: "组织部门",
        width: '400px',
        height: '700px',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            userOrgyDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.save,
                handler: function () {
                    topWin.frames['userOrgyDialog'].confirm(function (cbox) {
                        setOrgValue(cbox.id, cbox.name, cbox.code);
                        userOrgyDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    userOrgyDialog.dialog('close');
                }
            }
        ]
    });
}

function searchSupplier() {
    var supplierDialog = openDialog('supplierDialog', g.ctx + 'pc/supplier/supplierSelect?single=1', {
        title: "选择供应商",
        width: '800px',
        height: '500px',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            supplierDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.confirm,
                handler: function () {
                    topWin.frames['supplierDialog'].chooseRow(function (cbox) {
                        $("#supplierId").val(cbox.id);
                        $('#supplierName').textbox('setValue', cbox.supplierName)
                        supplierDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    supplierDialog.dialog('close');
                }
            }
        ]
    });
}

function setOrgValue(id, value, value1) {

    $("#orgId").val(id);
    /*      $('#deptCode').val(value);*/
    $("#deptCodeId").val(value1);
    $('#deptCode').textbox('setValue', value)
}

function setCompanyValue(value, value1) {

    $('#institutionId').val(value);
    $('#institution').textbox('setValue', value1)
}
