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

<!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/jquery/jquery-1.8.3.min.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>
    <link href="../scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/My97DatePicker/lang/zh-cn.js" type="text/javascript"></script>
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var selectcategoryid = "";
        var categorylist;
        var indexlist;
        var selectindex = -1;
        function ReLoadCategoryList() {
            categorylist.reload();
        }
        function LoadCategoryList() {
            categorylist = $("#divCategoryList").ligerGrid({
                checkbox: false,
                height: '97%',
                width: 330,
                columns: [
                { display: '分类名称', width: '200', name: '_f_categoryname', id: '_f_categoryid', align: 'left' },
                { display: '分值', width: '60', name: '_f_expand1' }
                ],
                tree: { columnId: '_f_categoryid', idField: '_f_categoryid',
                    parentIDField: '_f_parentid'
                },
                toolbar: {
                    items: [
                    { text: '增加', click: itemclick1, icon: 'add' },
                    { line: true },
                    { text: '修改', click: itemclick1, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: itemclick1, icon: 'delete' }
                    ]
                },
                url: 'ajax/indexcategory.ashx?action=getlist', pageSize: 100, pageSizeOptions: [10, 20, 50, 100], rownumbers: true, isChecked: f_isChecked,
                onCheckRow: function (checked, rowdata, rowindex) {
                    //                   for (var rowid in this.records)
                    //                       this.unselect(rowid); 
                    //                   this.select(rowindex);
                },
                onAfterShowData: function (data) {
                    try {
                        if (selectindex != -1) {
                            this.select(selectindex);
                        }
                    }
                    catch (e) {
                        alert(e.Message);
                    }
                },
                onSelectRow: function (data, rowindex, rowobj) {
                    selectcategoryid = data._f_categoryid;
                    selectindex = rowindex;
                    LoadIndexList();
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                    var id = "";
                    var name = "";
                    try {
                        id = data._f_categoryid;
                        name = data._f_categoryname;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'indexcategoryedit.aspx?otype=modify&id=' + id, title: '修改分类【<font color="red">' + name + '</font>】', height: 250, width: 380, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的分类，请选择');
                    }
                }
            });
            $("#pageloading").hide();
        }
        function f_isChecked(rowdata) {
            if (selectcategoryid != "") {
                if (rowdata._f_categoryid == selectcategoryid) {
                    return true;
                }
            }
            return false;
        }
        function LoadIndexList() {
            var key = escape(document.getElementById("txtKeywords").value);
            indexlist = $("#divindexlist").ligerGrid({
                height: '97%',
                columns: [
                { display: '指标分类', width: '120', name: '_f_categoryname' },
                { display: '指标标题', align: 'left', width: '350', name: '_f_title' },
                { display: '分值', width: '70', name: '_f_score' }
                ],
                toolbar: {
                    items: [
                    { text: '增加', click: itemclick2, icon: 'add' },
                    { line: true },
                    { text: '修改', click: itemclick2, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: itemclick2, icon: 'delete' },
                    { line: true },
                    { text: '所有指标', click: itemclick2, icon: 'attibutes' }
                    ]
                },
                url: 'ajax/indexbase.ashx?action=getlist&categoryid=' + selectcategoryid + '&selecttype=&key=' + key, pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "修改指标";
                    try {
                        id = data._f_indexid;
                        vtitle = "【<font color='red'>" + data._f_title + "</font>】修改指标";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'indexedit.aspx?otype=modify&id=' + id, title: vtitle, height: 380, width: 500, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的指标，请选择');
                    }
                }
            });
            $("#pageloading").hide();
        }
        function itemclick1(item) {
            switch (item.icon) {
                case "add":
                    var row = categorylist.getSelectedRow();
                    if (row) {
                        $.ligerDialog.open({ url: 'indexcategoryedit.aspx?otype=new&categoryid=' + row._f_categoryid, title: '添加【<font color="red">' + row._f_categoryname + '</font>】子分类', height: 250, width: 400, isResize: false
                        });
                    }
                    else {
                        $.ligerDialog.open({ url: 'indexcategoryedit.aspx?otype=new&categoryid=0', title: '添加根分类', height: 250, width: 400, isResize: true
                        });
                    }
                    break;
                case "modify":
                    var id = "";
                    var name = "";
                    try {
                        var rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                        name = rowobj._f_categoryname;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'indexcategoryedit.aspx?otype=modify&id=' + id, title: '修改分类【<font color="red">' + name + '</font>】', height: 250, width: 380, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的分类，请选择');
                    }
                    break;
                case "delete":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要删除【<font color="red">' + rowobj._f_categoryname + '</font>】吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/indexcategory.ashx?action=delete&id=" + id, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        ReLoadCategoryList();
                                    }
                                    else if (data == "error") {
                                        $.ligerDialog.error('删除失败');
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败，此分类下有【<font color="red">' + data + '</font>】个关联指标，无法删除');
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的分类，请选择');
                    }
                    break;
            }
        }
        function itemclick2(item) {
            switch (item.icon) {
                case "add":
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "添加指标";
                    var rowobj;
                    try {
                        rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                        vtitle = "【<font color='red'>" + rowobj._f_categoryname + "</font>】分类下添加指标";
                    }
                    catch (e) {
                    }
                    $.ligerDialog.open({ url: 'indexedit.aspx?otype=new&categoryid=' + id + '&selecttype=', title: vtitle, height: 380, width: 500, isResize: true
                    });
                    break;
                case "modify":
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "修改指标";
                    var rowobj;
                    try {
                        rowobj = indexlist.getSelectedRow();
                        id = rowobj._f_indexid;
                        vtitle = "【<font color='red'>" + rowobj._f_title + "</font>】修改指标";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'indexedit.aspx?otype=modify&id=' + id, title: vtitle, height: 380, width: 500, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的指标，请选择');
                    }
                    break;
                case "delete":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = indexlist.getSelectedRow();
                        id = rowobj._f_indexid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要删除【<font color="red">' + rowobj._f_title + '</font>】指标吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/indexbase.ashx?action=delete&id=" + id + "&categoryid=" + rowobj._f_categoryid, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        ReLoadCategoryList();
                                        LoadIndexList();
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的指标，请选择');
                    }
                    break;
                case "attibutes":
                    selectcategoryid = "";
                    LoadIndexList();
                    break;
            }
        }
        $(function () {
            //var vheight = $("#form1").height();
            //document.getElementById("tableMessage").style.height = vheight - 80;
            LoadCategoryList();
            LoadIndexList();
        });
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                LoadIndexList();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <asp:HiddenField ID="hdF_FunctionId" runat="server" />
        <asp:HiddenField ID="hdF_ModuleId" runat="server" />
        <div class="tools_bar">
            <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="LoadIndexList();" />
            </div>
        </div>
    </div>
    <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
        <tr>
            <td valign="top" style="width: 330px; padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/icon_site.gif" />&nbsp;指标分类</div>
                    </div>
                </div>
                <div id="divCategoryList">
                </div>
            </td>
            <td valign="top" style="padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/icon_attach.png" />&nbsp;指标列表</div>
                    </div>
                </div>
                <div id="divindexlist">
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
