<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Staff_WfSelectRun.aspx.cs" Inherits="TotCms.Web.Office.Staff.Staff_WfSelectRun" %>
<!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="../style/global.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      var aby = 1;
      function SearchStaff() {
        var orgid = 0;
        var deptid = $('#DeptId')[0].value;
        var username = $('#UserName')[0].value;
        if (username != '') username = encodeURIComponent(username);
        var childs = document.getElementById('Staffs');
        childs.length = 0;
        $.ajax({
          url: 'Staff_Gets.aspx?orgid=' + orgid + '&deptid=' + deptid + '&username=' + username,      //异步方法
          type: 'get',
          dataType: 'xml',
          timeout: 5000,                            //延迟1秒执行
          error: function () {                        //返回失败后
            alert('载入出错了，再稍后再试.');
          },
          success: function (xml) {              //返回成功
            var strbox = '';
            $(xml).find("category").each(function () {         //找到根节点
              var id = $(this).children("id").text();
              var tt = $(this).children("title").text();
              var ofs = childs.length;
              childs.options[ofs] = new Option(tt, id);
            });
          }
        });
      }

      function GetDept(pid, cid, did) {
        var retValue, i, sele;
        var childs = document.getElementById(did);
        childs.length = 0;
        //ajax
        $.ajax({
          url: '../Dept/GetDeptByOrg.aspx?classid=' + pid,      //异步方法
          type: 'get',
          dataType: 'xml',
          timeout: 5000,                            //延迟1秒执行
          error: function () {                        //返回失败后
            alert('载入出错了，再稍后再试.');
          },
          success: function (xml) {              //返回成功
            $(xml).find("category").each(function () {         //找到根节点
              var id = $(this).children("id").text();
              var tt = $(this).children("title").text();
              var ofs = childs.length;
              childs.options[ofs] = new Option(tt, id);
              if (parseInt(id) == parseInt(cid)) {
                childs.options[ofs].selected = true;
              }
            });
          }
        });
      }

      //
      function SearchDeptMan(pid) {
        var retValue, i, sele;
        var childs = document.getElementById('Staffs');
        childs.length = 0;
        //ajax
        $.ajax({
          url: '../Dept/GetDeptByOrg.aspx?classid=' + pid,      //异步方法
          type: 'get',
          dataType: 'xml',
          timeout: 5000,                            //延迟1秒执行
          error: function () {                        //返回失败后
            alert('载入出错了，再稍后再试.');
          },
          success: function (xml) {              //返回成功
            $(xml).find("category").each(function () {         //找到根节点
              var id = $(this).children("id").text();
              var tt = $(this).children("title").text()+'负责人';
              var ofs = childs.length;
              childs.options[ofs] = new Option(tt, id);              
            });
          }
        });
        childs.options[childs.length] = new Option("→本部门负责人", 0);
        childs.options[childs.length] = new Option("↑上级部门负责人", -1);
      }

      //
      function SearchRole() {
        var retValue, i, sele;
        var childs = document.getElementById('Staffs');
        childs.length = 0;
        //ajax
        $.ajax({
          url: '../Role/GetXml.aspx',      //异步方法
          type: 'get',
          dataType: 'xml',
          timeout: 5000,                            //延迟1秒执行
          error: function () {                        //返回失败后
            alert('载入出错了，再稍后再试.');
          },
          success: function (xml) {              //返回成功
            $(xml).find("category").each(function () {         //找到根节点
              var id = $(this).children("id").text();
              var tt = $(this).children("title").text();
              var ofs = childs.length;
              childs.options[ofs] = new Option(tt, id);
            });
          }
        });        
      }

      function GetVal() {
        //alert(aby);
        var opts = document.getElementById('Staffs');
        var values = '';
        var txts = '';
        for (var i = 0; i < opts.length; i++) {
          if (opts.options[i].selected) {
            values += opts.options[i].value + ',';
            txts += opts.options[i].text + ',';
          }
        }
        values = values.substring(0, values.length - 1);
        txts = txts.substring(0, txts.length - 1);
        //return value
        parent.ReturnValue(values, txts, aby);
      }
      function SelBy(i) {
        if (i == 1) {
          $('#sele1').show();
          $('#sele2').hide();
          aby = 1;
        } else if (i == 2) {
          $('#sele1').hide();
          $('#sele2').show();
          aby = 2;
          SearchDeptMan(1);
        } else if (i == 3) {
          $('#sele1').hide();
          $('#sele2').hide();
          aby = 3;
          SearchRole(1);
        }
      }
    </script>
</head>
<body>
    <form id="form1" runat="server">    
    <table cellpadding="0" cellspacing="1" border="0" width="100%" class="border">            
      <tr class="suphead">
        <td colspan="2">选择执行人员</td>
      </tr>
      <tr class="lines">
      <td width="100">
        选择：</td>
      <td style="text-align:left;">
        <input name="GetBy" id="GetBy" type="radio" value="1" onclick="SelBy(1)" checked="checked" /><label for="GetBy">按员工</label>
        <input name="GetBy" id="GetBy2" type="radio" value="2" onclick="SelBy(2)" /><label for="GetBy2">部门负责人</label>
        <input name="GetBy" id="GetBy3" type="radio" value="3" onclick="SelBy(3)" /><label for="GetBy3">按角色</label>
      </td>
      </tr>
      <tr>
        <td colspan="2">
          <div id="sele1">
          <table cellpadding="0" cellspacing="1" border="0" width="100%">             
            <tr class="lines">
            <td width="100">
            部门：</td>
            <td  style="text-align:left;">
              <asp:Literal ID="Literal2" runat="server"></asp:Literal>
              </td>
            </tr>
            <tr class="lines">
            <td>
              姓名：</td>
            <td  style="text-align:left;">
              <input id="UserName" class="input_mini" type="text" /><input 
                id="Submit2" type="button" value="查询" onclick="SearchStaff()" /></td>
            </tr>
            </table>
          </div>
          <div id="sele2" style="display:none;">
            <table cellpadding="0" cellspacing="1" border="0" width="100%"> 
            <tr class="lines">
            <td width="100">
            机构：</td>
            <td style="text-align:left;">
              <asp:Literal ID="Literal3" runat="server"></asp:Literal>
            &nbsp;</td>
            </tr>
            </table>
          </div>
        </td>
      </tr>
      
      <tr class="lines">
      <td>
        列表：</td>
      <td style="text-align:left;">
        <div id="CbListDiv">
        <asp:Literal ID="CbList" runat="server"></asp:Literal>
          <br />
          提示：按Ctrl+鼠标左键实现多选.</div>
        </td>
      </tr>
      <tr class="lines">
      <td colspan="2">
        <input id="Button1" type="button" value="选择" onclick="GetVal()" /></td>
      </tr>
      </table>
    </form>
</body>
</html>
