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

<!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 = 1;
        var counts = 1;
        $(function () {
            InitList();
        });
        function List() {
            count += 1;
            counts = count;
            InitList();
         }
        function InitList() {
            var sql = GetSql();
            try {
                gridlist = $("#divDataList").ligerGrid({
                    checkbox: false,
                    height: '90%',
                    columns: [
                    { display: '操作', isSort: false, width: 50, render: function (rowdata, rowindex, value) {
                        var h = "";
                        if (!rowdata._editing) {
                            h += "<a href='javascript:ShowInfo(" + rowdata._f_customerid + ")'>详细</a> ";
                        }
                        return h;
                    }
                    },
                    { display: 'Id', name: '_f_customerid', hide: 'Id', width: '1%' },
                    { display: '客户编号', name: '_f_customercode', align: 'left', width: '11%' },
                    { display: '客户名称', name: '_f_customername', width: '15%' },
                    //{ display: '负责人', name: '_f_chargename', width: '9%' },
                    { display: '联系电话', name: '_f_telephone', width: '9%' },
                    { display: '所属省份', name: '_f_province', width: '9%' },
                    { display: '所属县市', name: '_f_city', width: '9%' }
                    //{ display: '产品系列', name: '_f_productline', width: '10%' },
                    //{ display: '客户等级', name: '_f_customerclass', width: '9%' },
                    //{ display: '客户属性', name: '_f_customernature', width: '9%' },
                    //{ display: '售后人员', name: '_f_aftersalename', width: '9%' }
                    ],
                    url: '../customermanage/ajax/customer.ashx?action=getcustomerlist' + sql, pageSize: 10, rownumbers: true,
                    onDblClickRow: function (data, rowindex, rowobj) {
                        singleClick = data._f_customerid;
                        if (count > 1) {
                            count -= 1;
                            return;
                        } else {
                            try {

                                parent.SetCustomerInfo(data._f_customerid, data._f_customername, data._f_customercode, data._f_servicedeptid, data._f_regionid, data._f_cityid,
                                    data._f_servicedept, data._f_province, data._f_city, data._f_chargename, data._f_telephone, data._f_mobile, data._f_chargetelephone);
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                        CloseThis();
                    },
                    onSelectRow: function (data, rowindex, rowobj) {
                        singleClick = data._f_customerid;
                        if (count > 1) {
                            count -= 1;
                            return;
                        } else {
                            try {

                                parent.SetCustomerInfo(data._f_customerid, data._f_customername, data._f_customercode, data._f_servicedeptid, data._f_regionid, data._f_cityid,
                                    data._f_servicedept, data._f_province, data._f_city, data._f_chargename, data._f_telephone, data._f_mobile, data._f_chargetelephone);
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                    }
                });
            }
            catch (e) {
                alert(789);
                alert(e.Message);
            }
            gridlist.changePage('first');
            $("#pageloading").hide();
        }
        function ShowInfo(cid) {
            if (count > 1) {
                count -= 1;
                return;
            } else {
                count = counts;
                if (cid == "" || cid == undefined) {
                    alert("客户不存在！");
                } else {
                    var vheight = $("#form1").height();
                    var vwidth = $("#form1").width() * 0.9;
                    $.ligerDialog.open({ url: '/customermanage/customermodify.aspx?actionFlag=edit&customerId=' + cid, title: '修改客户信息', height: vheight, width: vwidth, isResize: true, overflow: scroll
                    });
                }
            }
        }
        function formatDateTime(value) {
            if (value != null) {
                var date = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
                var result = date.getFullYear() + "-" + (date.getMonth() + 1 < 10 ? "0"
                    + (date.getMonth() + 1) : date.getMonth() + 1) + "-"
                    + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "
                    + (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"
                    + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":"
                    + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds());
                return result;
            }
            return value;
        }
        function GetSql() {
            var sql = "";
            if (document.getElementById("txtKey").value != "") {
                sql += "&key=" + escape(document.getElementById("txtKey").value);
            } else {
                if (document.getElementById("HdName").value != "") {
                    sql += "&key=" + escape(document.getElementById("HdName").value);
                    document.getElementById("txtKey").value = document.getElementById("HdName").value;
                }
            }
            return sql;
        }
        function CloseThis() {
            if (singleClick == null || singleClick == undefined || singleClick == "") {
                alert("请选择客户！");
            } else {
                var dialog = frameElement.dialog;
                dialog.close();
            }
        }
        function FastAdd() {
            $.ligerDialog.confirm('快速添加新用户？', function (yes) {
                if (yes == true) {
                    var cname = encodeURIComponent($("#txtKey").val());
                    if (cname != "") {
                        $.post("../customermanage/ajax/customer.ashx?action=fastadd&cn=" + cname, function (data, states) {
                            if (states == "success") {
                                if (data == "True") {
                                    $.ligerDialog.success('添加成功');
                                } else if (data == "False") {
                                    $.ligerDialog.error('添加失败');
                                }
                            }
                        })
                    }
                    else { $.ligerDialog.warn('客户名不能为空'); }
                }
            });
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                List();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <div class="tools_bar">
                <asp:HiddenField ID="HdName" runat="server" />
            <a class="tools_btn" href="#" onclick="CloseThis();"><span><b class="modify">选择</b></span></a>
            <div class="search_box">
                关键字：<asp:TextBox ID="txtKey" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="List();" />&nbsp;&nbsp;
                <input id="btnAddCustomer" type="button" title="快速添加新用户" value="添加" class="btnSearch" onclick="FastAdd();" />
            </div>
        </div>
    </div>
    <div id="divDataList">
            </div>
    </form>
</body>
</html>
