<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="personlist.aspx.cs" Inherits="HySoft.BaseCallCenter.Web.customermanage.personlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>客户联系人档案管理</title>
 <link href="../scripts/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../scripts/ui/json2.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/core/base.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/ligerui.min.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/Tab/css/tab.css" rel="stylesheet" type="text/css" />
    <link href="../scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/ui/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerLayout.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerMenu.js" type="text/javascript"></script>
    <script src="../scripts/CustomersData.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        var count = 0;
        var counts = 0;
        $(function () {
            LoadList();
        });
        var singleClick;
        function LoadList() {
            count += 1;
            counts = count;
            var sql = GetSql();
            try {
                gridlist = $("#divDataList").ligerGrid({
                    checkbox: true,
                    height: '90%',
                    columns: [
                { display: 'Id', name: '_f_manid', hide: '_f_manid', width: 1 },
                { display: '客户编号', frozen: true, name: '_f_manid', align: 'left', width: 110, render: getCustomerInfo },
                { display: '客户名称', frozen: true, name: '_f_manid', width: 180, render: getCustomerInfo },
                { display: '联系人', frozen: true, name: '_f_name', width: 80 },
                { display: '手机', frozen: true, name: '_f_mobile', width: 130, render: function (rowdata, rowindex, value) {
                    if (value == "") {
                        return "&nbsp;";
                    }
                    else {
                        return "<img src=\"../images/phone3.png\" style=\"cursor:hand; width:24px;\" title=\"拨打" + value + "\" onclick=\"CallOut('" + encodeURI(value) + "');\" />" + value;
                    }
                }
                },
                { display: '联系电话', frozen: true, name: '_f_telephone', width: 130, render: function (rowdata, rowindex, value) {
                    if (value == "") {
                        return "&nbsp;";
                    }
                    else {
                        return "<img src=\"../images/phone3.png\" style=\"cursor:hand; width:24px;\" title=\"拨打" + value + "\" onclick=\"CallOut('" + encodeURI(value) + "');\" />" + value;
                    }
                }
                },
                { display: '账户', name: '_f_useraccount', width: 100 },
                { display: '密码', name: '_f_password', width: 100 },
                { display: '性别', name: '_f_sex', width: 50 },
                { display: '职务', name: '_f_duty', width: 100 },
                { display: '邮箱', name: '_f_email', width: 100 },
                { display: 'QQ', name: '_f_qq', width: 90 },
                { display: '传真', name: '_f_fax', width: 100 },
                { display: '备注', name: '_f_remark', width: 180 }
                ],
                    url: 'ajax/person.ashx?action=getallpersonlist&keywords=' + encodeURIComponent(document.getElementById("txtKeywords").value), pageSize: 10, rownumbers: true,
                    onSelectRow: function (data, rowindex, rowobj) {
                        singleClick = data._f_manid;
                    },
                    onDblClickRow: function (data, rowindex, rowobj) {
                        Edit('modify');
                    }
                });
            }
            catch (e) {
                alert(e.Message);
            }
            gridlist.changePage('first');
            $("#pageloading").hide();
        }
        function GetSql() {
            var sql = "";
            return sql;
        }
        function getCustomerInfo(rowdata, index, value, columns) {
            var param;
            if (columns.display == "客户编号") { param = "code" }
            if (columns.display == "客户名称") { param = "name" }
            $.ajax({
                type: "get",
                url: "ajax/person.ashx?action=getcustomerinfo&id=" + rowdata._f_customerid + "&type=" + param,
                async: false,
                //data: "action=getcustomerinfo&id=" + value + "&type=" + param,
                success: function (data, states) {
                    if (states == "success") {
                        param = data;
                    }
                }
            });
            return param;
        }
        function Delete() {
            try {
                //获取选择的行
                var rows = gridlist.getSelectedRows();
                if (rows.length > 0) {
                    $.ligerDialog.confirm('确定要批量删除选择的记录吗？', function (yes) {
                        if (yes) {
                            try {
                                var arr = new Array();
                                var i = 0;
                                for (var i = 0; i < rows.length; i++) {
                                    arr[i] = rows[i]._f_manid;
                                }
                                $.post("ajax/person.ashx?action=delete&arrid=" + arr.toString(), function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        LoadList();
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                        else {
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要删除的联系人');
                }
            }
            catch (e) {
                $.ligerDialog.error(e.Message);
            }
        }
        function AddPerson() {
            var vheight = $("#form1").height();
            var vwidth = $("#form1").width() * 0.9;
            if (vwidth > 800) {
                vwidth = 800;
            }
            $.ligerDialog.open({ url: 'personedit.aspx?actionFlag=add', title: '添加客户联系人信息',
                height: vheight, width: vwidth, isResize: true
            });
        }
        function Edit(params) {
            if (count > 1) {
                count -= 1;
                return;
            } else {
                count = counts;
                if (singleClick == "" || singleClick == undefined) {
                    $.ligerDialog.error("请选择修改行！");
                } else {
                    var vheight = $("#form1").height();
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 800) {
                        vwidth = 800;
                    }
                    $.ligerDialog.open({ url: 'personedit.aspx?actionFlag=' + params + '&personId=' + singleClick,
                        title: '修改客户联系人信息', height: vheight, width: vwidth, isResize: true
                    });
                }
            } 
        }
        function Export() {
            if (singleClick == "" || singleClick == undefined) {
                $.ligerDialog.error("请选择导出行！");
            }
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                LoadList();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <div class="tools_bar">
        <a class="tools_btn" href="#" onclick="AddPerson();">
                <span><b class="add">添加</b></span>
            </a>
            <a class="tools_btn" href="#" onclick="Edit('modify');">
                <span><b class="modify">修改</b></span>
            </a>
            <a class="tools_btn" href="#" onclick="Delete();"><span>
                    <b class="delete">删除</b></span> </a>
            <div class="search_box">
                关键字：<asp:TextBox ID="txtKeywords" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadList();" />
            </div>
        </div>
    </div>
    <div id="divDataList">
            </div>
    </form>
</body>
</html>
