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

<!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>
    <script src="../scripts/CustomersData.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 selectplan = "";
        var planlist;
        var tellist;
        var pagername = "";
        var planname = "";
        function LoadPlanList() {
            var key = escape(document.getElementById("txtKeywords").value);
            planlist = $("#divPlanList").ligerGrid({
                height: '97%',
                width: 399,
                columns: [
                { display: '状态', frozen: true, width: '70', name: '_state', render: function (rowdata, rowindex, value) {
                    if (value == "1")
                        return "<img src='../images/icon_correct.png' style='width:16px' />&nbsp;&nbsp;<font color='green'>已启动</font>";
                    else
                        return "<img src='../images/icon_disable.png' style='width:16px' />&nbsp;&nbsp;<font color='red'>未启动</font>";
                }
                },
                { display: '计划名称', frozen: true, align: 'left', width: '130', name: '_taskname' },
                { display: '号码数量', align: 'center', width: '60', name: '_y_hmcount' },
                { display: '已呼数', align: 'center', width: '60', name: '_y_hccount' },
                { display: '未呼数', align: 'center', width: '60', name: '_y_hccount' },
                { display: '呼叫率', align: 'center', width: '60', name: '_y_hccount' },
                { display: '接通数', align: 'center', width: '60', name: '_y_yjcount' },
                { display: '未接通数', align: 'center', width: '60', name: '_y_yjcount' },
                { display: '接通率', align: 'center', width: '60', name: '_y_yjcount' }
                ],
                toolbar: {
                    items: [
                    { text: '增加', click: itemclick1, icon: 'add' },
                    { line: true },
                    { text: '修改', click: itemclick1, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: itemclick1, icon: 'delete' },
                    { line: true },
                    { text: '启动', click: itemclick1, icon: 'ok' },
                    { line: true },
                    { text: '停止', click: itemclick1, icon: 'lock' }
                    ]
                },
                url: 'ajax/callplan.ashx?action=getlist&key=' + key, pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                    selectplan = data._taskid;
                    pagername = data._f_title;
                    planname = data._taskname;
                    LoadTelList();
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                    var id = "";
                    var name = "";
                    var vtitle = "修改计划";
                    try {
                        id = data._taskid;
                        vtitle = "【<font color='red'>" + data._taskname + "</font>】修改计划";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'callplanedit.aspx?otype=modify&id=' + id, title: vtitle, height: 380, width: 600, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的计划，请选择');
                    }
                },
                onSuccess: function (data, obj) {
                    try {
                        planname = "";
                        pagername = "";
                        selectplan = "0";
                        LoadTelList();
                    }
                    catch (e) {
                    }
                }
            });
            $("#pageloading").hide();
        }
        function LoadTelList() {
            var key = escape(document.getElementById("txtKeywords").value);
            var fpstate = document.getElementById("dropFP").value;
            var hcstate = document.getElementById("dropHC").value;
            tellist = $("#divTelList").ligerGrid({
                height: '97%',
                checkbox: true,
                columns: [
                { display: '号码', frozen: true, width: '130', name: '_f_phone', render: function (rowdata, rowindex, value) {
                    return "<img src='../images/phone3.png' style='width:16px' />&nbsp;&nbsp;<font color='green'>" + value + "</font>";
                }
                },
                { display: '名称', frozen: true, align: 'left', width: '130', name: '_f_customer' },
                { display: '导入时间', align: 'center', width: '130', name: '_f_createtime', type: 'date', format: 'yyyy-MM-dd hh:mm:ss' },
                { display: '分配坐席', align: 'center', width: '70', name: '_f_username' },
                { display: '呼叫状态', align: 'center', width: '70', name: '_f_hcstate', render: function (rowdata, rowindex, value) {
                    if (value == 0) {
                        return "未呼叫";
                    }
                    else {
                        return "已呼叫";
                    }
                }
                },
                { display: '接通状态', align: 'center', width: '70', name: '_f_yjstate', render: function (rowdata, rowindex, value) {
                    if (value == 0) {
                        return "未接通";
                    }
                    else {
                        return "已接通";
                    }
                }
                }
                ],
                toolbar: {
                    items: [
                    { text: '计划页面设置', click: itemclick1, icon: 'settings' },
                    { line: true },
                    { text: '导入号码', click: itemclick1, icon: 'inputdata1' },
                    { line: true },
                    { text: '清空号码', click: itemclick1, icon: 'candle' },
                    { line: true },
                    { text: '<span id="spanPagerInfo" style="color:red">相关问卷:无</span>', click: itemclick1, icon: 'help' }
                    ]
                },
                url: 'ajax/callplantelnum.ashx?action=getlist&taskid=' + selectplan + '&key=' + key + '&fpstate=' + fpstate + '&hcstate=' + hcstate, pageSize: 50, pageSizeOptions: [10, 20, 50, 100], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                },
                onSuccess: function (data, obj) {
                    try {
                        if (pagername != "") {
                            document.getElementById("spanPagerInfo").innerHTML = "相关问卷： " + pagername;
                        }
                        else {
                            document.getElementById("spanPagerInfo").innerHTML = "相关问卷: 无";
                        }
                        if (planname != "") {
                            document.getElementById("spanPlanInfo").innerHTML = "计划【" + planname + "】的";
                        }
                        else {
                            document.getElementById("spanPlanInfo").innerHTML = "";
                        }
                    }
                    catch (e) {
                    }
                }
            });
            $("#pageloading").hide();
        }
        function itemclick1(item) {
            switch (item.icon) {
                case "add":
                    $.ligerDialog.open({ url: 'callplanedit.aspx?otype=new', title: '添加计划', height: 390, width: 500, isResize: true
                    });
                    break;
                case "modify":
                    var id = "";
                    var name = "";
                    var vtitle = "修改计划";
                    try {
                        var rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                        vtitle = "【<font color='red'>" + rowobj._taskname + "</font>】修改计划";
                    }
                    catch (e) {
                        alert(e.toString());
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'callplanedit.aspx?otype=modify&id=' + id, title: vtitle, height: 380, width: 600, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的计划，请选择');
                    }
                    break;
                case "delete":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要删除【<font color="red">' + rowobj._taskname + '</font>】吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/callplan.ashx?action=delete&id=" + id, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        LoadPlanList();
                                        LoadTelList();
                                    }
                                    else if (data == "error") {
                                        $.ligerDialog.error('删除失败');
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败，此计划下有【<font color="red">' + data + '</font>】个未完成呼叫，无法删除');
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的计划，请选择');
                    }
                    break;
                case "candle":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要清空【<font color="red">' + rowobj._taskname + '</font>】的中的所有未分配号码吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/callplan.ashx?action=clearphone&id=" + id, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('清空成功');
                                        LoadTelList();
                                    }
                                    else if (data == "error") {
                                        $.ligerDialog.error('清空失败');
                                    }
                                    else {
                                        $.ligerDialog.success('清空号码，此计划下有【<font color="red">' + data + '</font>】个未分配号码已清空');
                                        LoadTelList();
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要清空的计划，请选择');
                    }
                    break;
                case "ok":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;

                    }
                    catch (e) {
                    }
                    if (id != "") {
                        if (rowobj._state == "1") {
                            $.ligerDialog.error('本计划已启动，无需再启动！');
                        }
                        else {
                            $.ligerDialog.confirm('确定要启动【<font color="red">' + rowobj._taskname + '</font>】吗？', function (yes) {
                                if (yes) {
                                    $.post("ajax/callplan.ashx?action=start&id=" + id, function (data) {
                                        if (data == "success") {
                                            $.ligerDialog.success('启动成功');
                                            LoadPlanList();
                                            LoadTelList();
                                        }
                                        else {
                                            $.ligerDialog.error('启动失败');
                                        }
                                    });
                                }
                            });
                        }
                    }
                    else {
                        $.ligerDialog.error('没有选择要启动的计划，请选择');
                    }
                    break;
                case "lock":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        if (rowobj._state == "0") {
                            $.ligerDialog.error('本计划已停止，无需再停止！');
                        }
                        else {
                            $.ligerDialog.confirm('确定要停止【<font color="red">' + rowobj._taskname + '</font>】吗？', function (yes) {
                                if (yes) {
                                    $.post("ajax/callplan.ashx?action=stop&id=" + id, function (data) {
                                        if (data == "success") {
                                            $.ligerDialog.success('停止成功');
                                            LoadPlanList();
                                            LoadTelList();
                                        }
                                        else {
                                            $.ligerDialog.error('停止失败');
                                        }
                                    });
                                }
                            });
                        }
                    }
                    else {
                        $.ligerDialog.error('没有选择要停止的计划，请选择');
                    }
                    break;
                case "settings":
                    var id = "";
                    var rowobj;
                    var vtitle = "页面设置";
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                        vtitle = "【<font color='red'>" + rowobj._taskname + "</font>】页面设置";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        var vheight = 470;
                        var vwidth = $("#form1").width() * 0.9;
                        if (vwidth > 700) {
                            vwidth = 700;
                        }
//                        $.ligerDialog.open({ url: 'pagerview.aspx?pagerid=' + pagerid, title: '预览问卷', height: vheight, width: vwidth, isResize: true
//                        });
                        $.ligerDialog.open({ url: 'callplanpageitems.aspx?otype=webset&taskid=' + id, title: vtitle, height: vheight, width: vwidth, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要页面设置的计划，请选择');
                    }
                    break;
                case "help":
                    var id = "";
                    var rowobj;
                    var vtitle = "问卷预览";
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                        vtitle = "【<font color='red'>" + rowobj._taskname + "</font>】问卷预览";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        var vheight = $("#form1").height() - 30;
                        var vwidth = $("#form1").width() * 0.9;
                        if (vwidth > 700) {
                            vwidth = 700;
                        }
                        $.ligerDialog.open({ url: '../askmanage/pagerview.aspx?pagerid=' + rowobj._y_tkmodelid, title: vtitle, height: vheight, width: vwidth, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要问卷预览的计划，请选择');
                    }
                    break;
                case "inputdata1":
                    var id = "";
                    var rowobj;
                    var vtitle = "导入号码";
                    try {
                        rowobj = planlist.getSelectedRow();
                        id = rowobj._taskid;
                        vtitle = "【<font color='red'>" + rowobj._taskname + "</font>】导入号码";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        var vheight = $("#form1").height() - 30;
                        var vwidth = $("#form1").width() * 0.9;
                        if (vwidth > 700) {
                            vwidth = 700;
                        }
                        //                        $.ligerDialog.open({ url: 'pagerview.aspx?pagerid=' + pagerid, title: '预览问卷', height: vheight, width: vwidth, isResize: true
                        //                        });
                        $.ligerDialog.open({ url: 'callplanintophone.aspx?otype=intophone&taskid=' + id, title: vtitle, height: vheight, width: vwidth, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要导入号码的计划，请选择');
                    }
                    break;
            }
        }
        $(function () {
            selectplan = "0";
            LoadPlanList();
            LoadTelList();
        });
        function Init()
        {
            LoadPlanList();
            selectplan = "0";
            LoadTelList();
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                Init();
            }
        };
    </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="Init();" />
            </div>
        </div>
    </div>
    <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
        <tr>
            <td valign="top" style="width: 399px; 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="divPlanList">
                </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/phone.png" style=" height:20px;" />&nbsp;<span id="spanPlanInfo"></span>外呼号码</div>
                            <div style="float:right; padding-right:10px;">分配状态：<asp:DropDownList ID="dropFP" runat="server" onchange="LoadTelList();" CssClass="selectBox" Width="80px">
                                <asp:ListItem Value="">--全部--</asp:ListItem>
                                <asp:ListItem Value="0">未分配</asp:ListItem>
                                <asp:ListItem Value="1">已分配</asp:ListItem>
                            </asp:DropDownList>&nbsp;&nbsp;呼叫状态：<asp:DropDownList ID="dropHC" runat="server" onchange="LoadTelList();" CssClass="selectBox" Width="80px">
                                <asp:ListItem Value="">--全部--</asp:ListItem>
                                <asp:ListItem Value="0">未呼出</asp:ListItem>
                                <asp:ListItem Value="1">已呼出</asp:ListItem>
                            </asp:DropDownList></div>
                    </div>
                </div>
                <div id="divTelList">
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
