var id = helper.request.queryString("ids");
var depId = 0; //部门id
var depName = ''; //部门name
$(document).ready(function() {
    getDepartmentTree()
})

//保存按钮
$('.customerSubmit').click(function() {
	if (depId == 0) {
        layer.confirm('请选择部门！', {
            btn: ['确定']
        });
        return;
    }
    $.post(huayi.config.callcenter_url + 'ATheChangeLog/AddAreaATheChangeLog', {
		"token": $.cookie("token"),
        token: $.cookie("token"),
		F_CustomerId: id,
		F_Bdeptid: depId,
		F_Bdeptname: depName,
    }, function(result) {
        result = $.parseJSON(result);
        if(result.state.toLowerCase() == "success") {
            $("#activess").val(result.data);
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            parent.layer.msg("保存成功！");
            parent.$("#registerList").bootstrapTable('refresh');
        }
    })
})

//所属部门
var settingDepartment = {
	data: {
		key: {
			name: "text"
		},
		simpleData: {
			enable: true,
			idKey: "id",
			rootPId: 0
		}
	},
	callback: {
		onClick: ztreeDep
	}
};
function ztreeDep(event, treeId, treeNode) {
	depId = treeNode.id;
	depName = treeNode.text;
	$('#departmentTreeValue').val(depName);
};
function getDepartmentTree() {
	$.get(huayi.config.callcenter_url + "Department/GetAllDeptList", {
		"token": $.cookie("token"),
		"pid": '',
	}, function(result) {
		result = $.parseJSON(result);
		$.fn.zTree.init($("#departmentTree"), settingDepartment, result.data); //实例化树形图
	});
}

$('#departmentTreeValue').focus(function() {
	$('.dropDownThreeListDepartment').css('display', 'block');
})
$('.dropDownThreeIconDepartment').click(function() {
	if($('.dropDownThreeListDepartment').css('display') == 'block') {
		$('.dropDownThreeListDepartment').css('display', 'none')
	} else {
		$('.dropDownThreeListDepartment').css('display', 'block')
	}
})
$('.dropDownThree').mouseleave(function() {
	$(this).css('display', 'none')
})

