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

<!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 singleClick;
        var count = 0;
        var counts = 0;
        $(function () {
            InitList();
        });
        function InitList() {
            count += 1;
            counts = count;
            var sql = GetSql();
            try {
                gridlist = $("#divDataList").ligerGrid({
                    checkbox: true,
                    height: '95%',
                    columns: [
                { display: 'Id', name: '_f_customerid', hide: 'Id', width: 1 },
                { display: '客户编号', frozen: true, name: '_f_customercode', align: 'left', width: 110 },
                { display: '客户名称', frozen: true, name: '_f_customername', width: 180 },
                //{ display: '负责人', frozen: true, name: '_f_chargename', width: 80 },
                { display: '联系电话',align:'left', 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_servicedept', width: 100 },
                { display: '所属省份', name: '_f_province', width: 80 },
                { display: '所属县市', name: '_f_city', width: 80 }
                //{ display: '产品系列', name: '_f_productline', width: 110 },
                //{ display: '客户等级', name: '_f_customerclass', width: 80 },
                //{ display: '客户属性', name: '_f_customernature', width: 80 },
                //{ display: '售后人员', name: '_f_aftersalename', width: 80 }
                ],
            url: 'ajax/customer.ashx?action=getcustomerlist' + sql, pageSize: 20, pageSizeOptions: [10, 20, 50], rownumbers: true,
                    onSelectRow: function (data, rowindex, rowobj) {
                        singleClick = data._f_customerid;
                    },
                    onDblClickRow: function (data, rowindex, rowobj) {
                        Edit('edit');
                    }
                });
            }
            catch (e) {
                alert(e.Message);
            }
            gridlist.changePage('first');
            $("#pageloading").hide();
        }
        function GetSql() {
            var sql = "";
            if (document.getElementById("txtKey").value != "") {
                sql += "&key=" + escape(document.getElementById("txtKey").value);
            }
            //if (document.getElementById("txtCustomerNature").value != "") {
            //    sql += "&customernature=" + encodeURIComponent(document.getElementById("txtCustomerNature").value);
            //}
            //if (document.getElementById("txtCustomerClass").value != "") {
            //    sql += "&customerclass=" + encodeURIComponent(document.getElementById("txtCustomerClass").value);
            //}
            return sql;
        }
        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_customerid;
                                }
                                $.post("ajax/customer.ashx?action=delete&arrid=" + arr.toString(), function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        InitList();
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                        else {
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要删除的客户');
                }
            }
            catch (e) {
                $.ligerDialog.error(e.Message);
            }
        }
        function AddCustomer() {
            var vheight = $("#form1").height();
            var vwidth = $("#form1").width() * 0.9;
            if (vwidth > 900) {
                vwidth = 900;
            }
            $.ligerDialog.open({ url: 'customermodify.aspx?actionFlag=add', title: '添加客户信息', height: vheight, width: vwidth, isResize: true
            });
        }
        function DoInCustomer() {
            var vheight = $("#form1").height();
            var vwidth = $("#form1").width() * 0.9;
            if (vwidth > 900) {
                vwidth = 900;
            }
            $.ligerDialog.open({ url: 'customermodify.aspx?actionFlag=add', title: '导入客户信息', height: vheight, width: vwidth, isResize: true
            });
        }
        function Export() {
            $.ligerDialog.confirm('手动同步时间可能较长，确认同步？', function (yes) {
                if (yes) {
                    $.ligerDialog.open({
                        url: 'customerSYNC.aspx',
                        title: '同步客户信息',
                        height: 200,
                        width: 400,
                        isResize: true
                    });
                }
            });
        }
        function Edit(params) {
            if (count > 1) {
                count -= 1;
                return;
            } else {
                count = counts;
                if (singleClick == "" || singleClick == undefined) {
                    alert("请选择修改行！");
                } else {
                    var vheight = $("#form1").height();
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 900) {
                        vwidth = 900;
                    }
                    $.ligerDialog.open({ url: 'customermodify.aspx?actionFlag=' + params + '&customerId=' + singleClick, title: '修改客户信息', height: vheight, width: vwidth, isResize: true, overflow:scroll
                    });
                }
            }
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                InitList();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <div class="tools_bar">
        <a class="tools_btn" href="#" onclick="AddCustomer();">
                <span><b class="add">添加</b></span>
            </a>
            <a class="tools_btn" href="#" onclick="Edit('edit');">
                <span><b class="modify">修改</b></span>
            </a>
            <a class="tools_btn" href="#" onclick="Delete();"><span>
                    <b class="delete">删除</b></span> </a>
                    <a class="tools_btn" href="#" onclick="DoInCustomer();"><span>
                    <b class="export">导入客户</b></span> </a>
                    <%--<a class="tools_btn" href="#" onclick="Export();"><span>
                    <b class="export">同步客户</b></span> </a>--%>
            <div class="search_box">
                客户名称：<asp:TextBox ID="txtKey" runat="server" CssClass="txtInput" Width="80px"></asp:TextBox>&nbsp;&nbsp;
                <%--客户属性：<asp:DropDownList ID="txtCustomerNature" runat="server">
                </asp:DropDownList>--%>
                <%--<asp:TextBox ID="txtCustomerNature" runat="server" CssClass="txtInput" Width="50px"></asp:TextBox>--%>&nbsp;&nbsp;
                <%--客户等级：<asp:DropDownList ID="txtCustomerClass" runat="server">
                </asp:DropDownList>--%>
                <%--<asp:TextBox ID="txtCustomerClass" runat="server" CssClass="txtInput" Width="50px"></asp:TextBox>--%>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="InitList();" />
            </div>
        </div>
    </div>
    <div id="divDataList">
            </div>
    </form>
</body>
</html>
