<%@ Page Title="" Language="C#" MasterPageFile="~/helpdesk/Pc.master"   ClientIDMode="Static"   AutoEventWireup="true" CodeBehind="PC_List.aspx.cs" Inherits="helpdesk.helpdesk.PC_List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
      <link href="../javascript/datatables/datatables.css" rel="stylesheet" />
      <script src="../javascript/datatables/datatables.min.js"></script>

      <script>
          //提示信息
            lang = {
              "sProcessing": "处理中...",
              "sLengthMenu": "每页 _MENU_ 项",
              "sZeroRecords": "没有匹配结果",
              "sInfo": "<b>&nbsp;&nbsp; 每页 20 条 当前显示第 _PAGE_页 共 _PAGES_ 页，共 _TOTAL_ 条</b> (双击编辑,鼠标右键可以进行多种操作)",
              "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
              "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
              "sInfoPostFix": "",
              "sSearch": "搜索:",
              "sUrl": "",
              "sEmptyTable": "表中数据为空",
              "sLoadingRecords": "载入中...",
              "sInfoThousands": ",",
              "oPaginate": {
                  "sFirst": "首页",
                  "sPrevious": "上页",
                  "sNext": "下页",
                  "sLast": "末页",
                  "sJump": "跳转"
              },
              "oAria": {
                  "sSortAscending": ": 以升序排列此列",
                  "sSortDescending": ": 以降序排列此列"
              }
          };


          function rf() {
              window.location = "../pc_list.aspx";
          }
     </script>


        <style>
      .xxx  {
            background-color: #DFF0D8;  
            font-weight:bold 
            }

    table#tbl_pc { 
             border-collapse:collapse !important;
         }

        </style>
 
   <input type="hidden" id="hf_trid" name="hf_trid" />

  

    <div class="panel panel-default">
  <div class="panel-heading">资产搜索</div>
  <div class="panel-body">

    <div class="form-inline">

     所属组织 <asp:DropDownList runat="server" ID="ddl_belongto"  Width="183px" AppendDataBoundItems="true" ClientIDMode="Static"   CssClass="form-control"  >
          <asp:ListItem Text="==所有==" Value=""></asp:ListItem>
         </asp:DropDownList>
       

   使用部门 <asp:DropDownList runat="server" ID="ddl_dept"  Width="183px" AppendDataBoundItems="true" ClientIDMode="Static"   CssClass="form-control"  >
        <asp:ListItem Text="==所有==" Value=""></asp:ListItem>
    </asp:DropDownList>


   使用状态 <asp:DropDownList runat="server" ID="ddl_status" Width="183px" ClientIDMode="Static"   AppendDataBoundItems="true"  CssClass="form-control"  >
         <asp:ListItem Text="==所有==" Value=""></asp:ListItem>  
         </asp:DropDownList>

         
                
   使用年限 <asp:DropDownList runat="server" ID="ddl_workyear" Width="183px" ClientIDMode="Static"   AppendDataBoundItems="true"  CssClass="form-control"  >
         <asp:ListItem Text="==所有==" Value=""></asp:ListItem> 
        <asp:ListItem Text="1~3年"  Value="1~3"></asp:ListItem>
        <asp:ListItem Text="4-5年"    Value="4~5"></asp:ListItem>
        <asp:ListItem Text="6-7年"   Value="6~7"></asp:ListItem>
        <asp:ListItem Text="8年以上（含）"   Value="8~200"></asp:ListItem> 
     </asp:DropDownList>



        
     机器用途 <asp:TextBox runat="server" ID="txt_usetype" CssClass="form-control" Width="183"></asp:TextBox>


        





        <div style="margin:5px;"></div>

        操作系统 <asp:TextBox runat="server" ID="txt_os" CssClass="form-control"></asp:TextBox>

       存放位置 <asp:TextBox runat="server" ID="txt_storeplace" CssClass="form-control"></asp:TextBox>


     &nbsp;&nbsp;  关键字 <asp:TextBox placeholder="机器名/使用者/员工号/资产编号/服务序列号/IT资产编号/型号" runat="server" 
             ClientIDMode="Static" ID="txt_key" CssClass="form-control" Width="428"></asp:TextBox>

        
         

         <a href="javascript:void(0)"; onclick="ept('PC/PC_Export.aspx?types=pc')" class="btn    btn-sm  btn-primary   btn-flat"> 导出</a>



          <a href="javascript:void(0)"; onclick="ept('PC/PC_Import.aspx?types=pc')" class="btn  btn-sm   bg-teal  btn-flat"> 导入</a>

         
         <a href="PC_addeditpc.aspx" class="btn btn-danger   btn-sm  btn-flat">新增</a>
    
    </div>

      </div>
        </div>

    


    <table   class="table  "  id="tbl_pc"  >
        <thead  >
            <tr>
                  <th width="40px">ID</th>
                   <th width="80px">员工号</th>

                   <th width="80px">机器名</th>

                 <th  width="100px">使用部门</th>
              
                 <th width="80px">使用者</th>

                  <th width="80px">服务编号</th> 

               
                 <th width="95px">使用状态</th>

                  <th width="100px">型号</th>
            
               
                  <th width="100px">机器用途</th>
             
                 <th width="120px">所属组织</th> 

                 <th width="100px">操作系统</th> 
                 <th width="100px">存放位置</th> 
                 <th width="95px">IT资产编号</th> 
            </tr>
        </thead>
    </table>


        
      
     <ul class="dropdown-menu" id="contextMenu">
        
      <li>
            <a href="###"  onclick="_edit(); return false;"  >查看&编辑</a>    
        </li>

           <li>
            <a href="###"  onclick="_viewlog(); return false;"  >变更日志</a>    
        </li>

          


        <li>
            <a href="#"  onclick="_del(); return false;"  >批量删除</a>    
        </li>
       

        <li>
            <a  href="#" onclick="change('enduser'); return false;">批量更新使用者</a>    
        </li>

        <li role="separator" class="divider"></li>
          <li>
            <a  href="#" onclick="change('dept'); return false;">批量更改使用部门...</a>    
        </li>
   
         
       <li>
            <a  href="#" onclick="change('usestatus'); return false;">更改使用状态...</a>    
        </li>

      <li>
            <a  href="#" onclick="change('usetype'); return false;">更改机器用途...</a>    
        </li>

           <li>
            <a  href="#" onclick="change('belongto'); return false;">更改所属组织...</a>    
        </li>

           <li>
            <a  href="#" onclick="change('os'); return false;">更改操作系统...</a>    
        </li>
      
            <li>
            <a  href="#" onclick="_barcode(); return false;">生成二维码...</a>    
        </li>
</ul>



      
      


    <script>
         
    
      function InitTable() {
          
          var table = $('#tbl_pc').DataTable();
           
         
         if ($.fn.dataTable.isDataTable('#tbl_pc')) {
             table.destroy();
         }
           
         

         $("#ddl_belongto").change(function () {
             table.ajax.reload();
         });

         $("#ddl_dept").change(function () {
             table.ajax.reload();
         });

         $("#ddl_status").change(function () {
             table.ajax.reload();
         });

         $("#ddl_workyear").change(function () {
             table.ajax.reload();
         });


         $("#txt_usetype").keyup(function () {
             table.ajax.reload();
         });


         $("#txt_os").keyup(function () {
             table.ajax.reload();
         });


         $("#txt_storeplace").keyup(function () {
             table.ajax.reload();
         });


         $("#txt_key").keyup(function () { 
             table.ajax.reload(); 
         });

       
        



         //初始化表格
         table = $("#tbl_pc").dataTable({

             language: lang,  //提示信息
             autoWidth: false,  //禁用自动调整列宽 
             processing: true,  //隐藏加载提示,自行处理
             serverSide: true,  //启用服务器端分页
             searching: false,  //禁用原生搜索
             orderMulti: false,  //启用多列排序
             ordering: true,//禁止排序
             order: [],  //取消默认排序查询,否则复选框一列会出现小箭头
             pageLength: 25,
             lengthMenu: [[20, 50, -1], [20, 50, "All"]],

             dom: 'ifrtp',//lfrtip frtip
             pagingType: "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers 

             columnDefs: [{}],

              
               
             ajax: function (data, callback, settings) { 
                 var colname = "";
                 var dir = "";
                 if (data.order != "") {
                     colname = data.columns[data.order[0].column]["data"];
                     dir = data.order[0].dir;
                 }
                  
                  
                 $.ajax({
                     type: "GET",
                     url: "ajax_pc/Pc_List_Data.aspx",
                     cache: false,  //禁用缓存
                     async: false,
                     data: {
                         belongto: encodeURIComponent($("#ddl_belongto").val()),
                         dept: encodeURIComponent($("#ddl_dept").val()),
                         status: encodeURIComponent($("#ddl_status").val()),
                         workyear: encodeURIComponent($("#ddl_workyear").val()),
                         usetype: encodeURIComponent($("#txt_usetype").val()),
                         os: encodeURIComponent($("#txt_os").val()),
                         storeplace: encodeURIComponent($("#txt_storeplace").val()),
                         key: encodeURIComponent($("#txt_key").val()),

                         pageIndex: data.start, 
                         pageSize: data.length,
                         dir: dir,
                         colname: colname
                       },
                     
                     dataType: "json", 
                     success: function (result) { 
                         callback(result); 
                     }
                 });
             },
               

             //列表表头字段
             columns: [
                    { "data": "id" },
                    { "data": "staffcode" },
                    { "data": "pcname" },
                    { "data": "dept" },
            
                    { "data": "enduser" },
                    { "data": "serial" },
                    { "data": "usestatus" },
                    { "data": "spec" },
                    { "data": "usetype" },
                    { "data": "belongto" },

             { "data": "os" },
        { "data": "storeplace" },
        { "data": "itasset" }
                 
             ],



             "columnDefs": [{
                 "targets": 2,               
                 "render": function (data, type, row, meta) {
                     return '<a target=_blank href="pc_addeditpc.aspx?id=' + row.id + '">' + data + '</a>';
                 }
             }]



         }).api();



         $('#tbl_pc').on('draw.dt', function () {

             formatData();

         });
    
        
         

      }

         
         

     InitTable();

     formatData();

    
          


     function formatData() {
         
         $('#tbl_pc tbody tr').each(
          function () { 

              var _v = $(this).find("td:eq(5)").html();
 

              switch (_v) {
                  case "报废":
                      $(this).css("color", "#ff0000");
                      break;

                  case "维修":
                      $(this).css("color", "orange");
                      break;


                  case "在库":
                      $(this).css("color", "#09a800");
                      break;

              }


          }

          );

     }

   
    </script>





      




    

 <script>

   

     $(document).ready(function () { 

         $('#tbl_pc tbody').on('click', 'tr', function () { 
             $(this).toggleClass('xxx'); 
         });



         $('#tbl_pc tbody').on('dblclick', 'tr', function () {
             _id = $(this).find("td:eq(0)").html();
             window.open("pc_addeditpc.aspx?id=" + _id); 
         });


      

         $("#tbl_pc tbody").on("contextmenu", 'tr', function (event) {

             var pageX = event.pageX;//鼠标单击的x坐标
             var pageY = event.pageY;//鼠标单击的y坐标 

             //获取菜单
             var contextMenu = $("#contextMenu");

             var cssObj = {
                 top: pageY + "px",//设置菜单离页面上边距离，top等效于y坐标
                 left: pageX + "px"//设置菜单离页面左边距离，left等效于x坐标
             };

             //判断横向位置（pageX）+自定义菜单宽度之和，如果超过页面宽度及为溢出，需要特殊处理；
             var menuWidth = contextMenu.width();
             var pageWidth = $(document).width();
             if (pageX + contextMenu.width() > pageWidth) {
                 cssObj.left = pageWidth - menuWidth - 5 + "px"; //-5是预留右边一点空隙，距离右边太紧不太美观；
             }

             //设置菜单的位置
             $("#contextMenu").css(cssObj).show();//显示使用淡入效果,比如不需要动画可以使用show()替换;

             event.preventDefault();//阻止浏览器与事件相关的默认行为；此处就是弹出右键菜单

         }); 
     });

      


     //文档对象注册鼠标按下事件；
     $(document).on("mousedown", function (event) {
         //button等于0代表左键，button等于1代表中键
         if (event.button == 0 || event.button == 1) {

             if (event.target.nodeName.toLowerCase() == "a") {

             }
             else {

                 if (event.target.nodeName.toLowerCase() == "div") {
                     $('#tbl_pc tbody tr').removeClass("xxx");
                 }
                 else {
                     $("#contextMenu").hide();
                 }
             }
         }
     });


      

      
      

   </script>






    <script>



        function MakeSureSelect() {
            var checked = 0;
            var result = "";
            var _c = 0; 
            var rows = $("tr.xxx");//table.rows('.selected').data();
             
            for (var i = 0; i < rows.length; i++) {
                checked++;
                var __id = $(rows[i]).find("td:eq(0)").html().trim(); 
                result = __id + "," + result;
            } 
            result = result + "-1";
            if (checked > 0) {
                $("#hf_trid").val(result);
                return true;
            }
            else {
                $("#hf_trid").val("");
                return false;
            }
        }


          


        function _edit() { 
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
                
            window.open("pc_addeditpc.aspx?id=" + _theid.split(',')[0]);
        }





        function _viewlog(e) {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }

            var idCount = _theid.split(','); 
            Pop('../ajax/pc_logs.aspx?id=' + _theid, 700, 600, '变更日志');
            return false;
        }






        function _del() {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
            $("#hf_trid").val();



            $.ajax({ cache: false, url: "ajax_pc/del_pc.aspx?ids=" + _theid });

            $("tr.xxx").remove();
        }



        function change(key) {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
            $("#hf_trid").val();

            //pclist_op.aspx?t=dept&ids=43,42&returnUrl=pc_list.aspx
            Pop("ajax_pc/pclist_op.aspx?ids=" + _theid + "&t=" + key, 500, 400, "更新状态");



        }




        function note(note) {


            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请选择一台PC，如果选择多个，系统会自动使用其中一个', 12);
                return;
            }
            $("#hf_trid").val();

            Pop("ajax_pc/pc_note.aspx?id=" + _theid.split(",")[0] + "&t=" + note, "500", 400, "更新备注");


        }




        function _barcode() {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
           

            window.open("barcode.aspx?id=" + _theid);
 
            $("tr.xxx").remove();
        }

    </script>













</asp:Content>
