选择多项内容 备份

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>操作小结模板表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <link rel="stylesheet" href="plug-in/select2/css/select2.min.css">
<script type="text/javascript" src="plug-in/select2/js/select2.full.min.js"></script>
  <script type="text/javascript">
  //编写自定义JS代码
   $(document).ready(function(){
        var pcname = new Array();
        $.ajax({
            url : 'ldcHandbookOrderController.do?cusselect',
            type : 'GET',
            dataType : 'JSON',
            delay : 250,
            cache : true,
            success : function(data) {
                for (var i = 0; i < data.length; i++) {
                    var pcnameObj = {};
                    pcnameObj.id = data[i].id;
                    pcnameObj.text = data[i].cus_company;
                    pcname.push(pcnameObj);
                }
                $("#kehu").select2({
                    data : pcname,
                    placeholder : '请选择客户',// 默认文字提示
                    language : "zh-CN",// 汉化
                    allowClear : true
                // 允许清空
                });
            }
        });
        if ($.browser.msie) {
              $('input:checkbox').click(function () { 
               this.blur();   
               this.focus(); 
              });   
             };
            
 });
// 上移 
   function moveUp(obj) { 
     var current = $(obj).parent().parent(); //获取当前<tr>
     var prev = current.prev();  //获取当前<tr>前一个元素
     if (current.index() > 0) { 
       current.insertBefore(prev); //插入到当前<tr>前一个元素前
       numCheck();
     } 
   } 
   // 下移 
   function moveDown(obj) { 
     var current = $(obj).parent().parent(); //获取当前<tr>
     var next = current.next(); //获取当前<tr>后面一个元素
     if (next) { 
       current.insertAfter(next);  //插入到当前<tr>后面一个元素后面
       numCheck();
     } 
     
   }
   function numCheck(){

               var num = $("#bbsTab tr").length;     //获取tr的长度

               for (var i = 0; i <= num; i++) {         //进行循环

               $("#bbsTab tr .td_center").eq(i).html(i+1);

           };

       }

  </script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="ldCuscolumnRulerController.do?doAdd" >
                    <input id="id" name="id" type="hidden" value="${ldCuscolumnRulerPage.id }"/>
        <table style=" 600px;" cellpadding="0" cellspacing="1" class="formtable">
                <tr>
                    <td align="right">
                        <label class="Validform_label">
                            客户:
                        </label>
                    </td>
                    <td class="value">
                              <input id="kehu" name="kehu" type="text" style=" 180px" class="inputxt"  ignore="ignore" />
                            <input id="look" name="look" type="button" onclick="lookmb()" value="查看" />
                            <span class="Validform_checktip"></span>
                            <label class="Validform_label" style="display: none;">客户</label>
                        </td>
                </tr>
                <tr>
                    <td align="right">
                        <label class="Validform_label">
                            显示列:
                        </label>
                    </td>
                    <td class="value">
                <table>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='create_date' title="接单日期" >接单日期
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)"  value='order_code' title="业务编号" >业务编号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_from_cucode' title="客户" >客户
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='cr_etd_gettime' title="提货日期" >提货日期
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_protocolno' title="合同号" >合同号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_ship_deliveday' title="到港日期" >到港日期
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_goods' title="货物" >货物
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='route_state6' title="放行日" >放行日
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_number' title="件数" >件数
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_gross_weight' title="毛重" >毛重
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_book_billno' title="提单号" >提单号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='route_state3' title="报关日" >报关日
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_zznote' title="操作备注" >操作备注
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_hddate' title="换单日期" >换单日期
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='route_state1' title="商检日期" >商检日期
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='cr_etd_outtime' title="送货日期" >送货日期
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_aboutno' title="客户编号" >客户编号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_billno' title="提货单号" >提货单号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='entry_id' title="报关单号" >报关单号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_dzqqdate' title="单证齐全日" >单证齐全日
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='cr_boxno' title="箱号" >箱号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_box' title="箱量" >箱量
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='free_date' title="免箱日期" >免箱日期
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_salesman' title="业务员" >业务员
                        </td>
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_invoiceno' title="发票号" >发票号
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='maoyi_type' title="报关类型" >报关类型
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_bz' title="木包" >木包
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_check_time' title="中转港预计到港日" >中转港预计到港日
                        </td> 
                    </tr>
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='voyage' title="航程" >航程
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='shyq' title="送货要求" >送货要求
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='shnum' title="已送货箱量" >已送货箱量
                        </td> 
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_checkouttime' title="中转港预计出港日" >中转港预计出港日
                        </td>
                    </tr>     
                    <tr>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='is_sh' title="可否送货" >可否送货
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_bgcomment' title="备注" >备注
                        </td>
                        <td class="value">
                            <input type='checkbox' name='showlie' onchange="state(this)" value='order_Loading_Port' title="起运港" >起运港
                        </td>
                    </tr> 
                </table>
                  <span class="Validform_checktip"></span>
                    <label class="Validform_label" style="display: none;">显示列</label>
                </td>
        </tr>
                
                
            </table>
        </t:formvalid>
        <table style=" 600px;margin-top: 5%;margin-left: 10%;margin-right: 10%;"  border="1" >
        <tbody id='bbsTab'></tbody>    
            </table>
            <button style='margin-left:38%;margin-top: 2%' onclick='saveuserdate()'>保存模板信息</button>
 </body>
  <script src = "webpage/com/jeecg/ldcuscolumnruler/ldCuscolumnRuler.js"></script>        
    <script type="text/javascript">
    function state(me){
        //alert($(me).is(':checked'))
        var name=$(me).prop('title')
        var rowTem = "";
        //rowTem = "<tr><td>序号</td><td>显示列</td><td>展示</td><td>操作</td></tr>";
        if($(me).is(':checked')==true){
                rowTem+= "<tr name='trvalue'><td class='td_center' style=' 40px'>1</td><td class='td_id' style='display: none'>"+me.value+"</td>";
                rowTem+="<td class='value' style=' 110px'>"+name+"</td>";
                rowTem+="<td style=' 110px'><input type='text'  name='itemname' value='"+name+"' > </td>";
                
                rowTem+="<td class='value' style=' 80px'>";
                rowTem+="<button  style='margin-left:10%' onclick='moveUp(this)'>上移</button>";
                rowTem+=" <button style='margin-left:5%'  onclick='moveDown(this)'>下移</button>";
                rowTem+="</td></tr>";
                 $("#bbsTab").append(rowTem);
                 numCheck();     
        }else{
            $('#bbsTab').find('tr').each(function (){
            //    alert($(this).find('td').eq(2).text())
                if($(this).find('td').eq(2).text()==name){
                    $(this).remove();
                }
            })
            numCheck();    
        }
  
    }
    function saveuserdate() {
        var kehu=$('#kehu').val();
        var a=0;
        $('#bbsTab').find('tr').each(function (){
             a++;
            })
        if(kehu==null||kehu==''){
            tip('请选择客户')
        }else if(a<3){
            tip('请至少选择3列')
        }else{
            var featureCodes = [];
            $('#bbsTab').find('tr[name="trvalue"]').each(function (){
                var arr = {};
                arr.sortidx=$(this).find('td').eq(0).text();
                arr.itemkey=$(this).find('td').eq(1).text();
                arr.itemnameold=$(this).find('td').eq(2).text();
                arr.itemname=$(this).find('td input[name="itemname"]').val();
                console.log(arr)
                featureCodes.push(arr);
               })
             $.ajax({
                    url : "ldCuscolumnRulerController.do?doAddcusmodel",
                    type : 'post',
                    data : {cusid:kehu,models:JSON.stringify(featureCodes)},
                    cache : false,
                    success : function(data) {
                        var d = $.parseJSON(data);
                        if (d.success) {
                            var msg = d.msg;
                            tip(msg);
                        }
                    }
                });  
        }
    }
    
    function lookmb(){
         var kehu=$('#kehu').val();
         $.ajax({
                url : "ldCuscolumnRulerController.do?gomb",
                type : 'post',
                data : {cusid:kehu},
                cache : false,
                success : function(data) {
                    var d = $.parseJSON(data);
                    if (d.success) { 
                        var obj = d.obj;
                        if(obj==null){
                            tip('该客户暂无模板')
                        }else{ 
                            var cc = jQuery.parseJSON(obj.content); 
                            var rowTem = "";
                            $("#bbsTab").html("");
                            $("input[name='showlie']").each(function(){
                                $(this).attr("checked",false);
                            });
                             for(var i=0;i<Object.keys(cc).length;i++){

                                 $("input[name='showlie'][value='"+cc[i].itemkey+"']").attr("checked","checked");  
                                 
                                 rowTem = "<tr name='trvalue'><td class='td_center' style=' 40px'>1</td><td class='td_id' style='display: none'>"+cc[i].itemkey+"</td>";
                                rowTem+="<td class='value' style=' 110px'>"+cc[i].itemnameold+"</td>"
                                rowTem+="<td style=' 110px'><input type='text'  name='itemname' value='"+cc[i].itemname+"' > </td>";
                                
                                rowTem+="<td class='value' style=' 80px'>";
                                rowTem+="<button style='margin-left:10%' onclick='moveUp(this)'>上移</button>";
                                rowTem+=" <button style='margin-left:5%' onclick='moveDown(this)'>下移</button>";
                                rowTem+="</td></tr>";
                                 $("#bbsTab").append(rowTem);
                                 numCheck();     
                             }
                        }
                    }else{
                        var msg = d.msg;
                        tip(msg);
                    }
                }
            });
    }
    </script>
原文地址:https://www.cnblogs.com/xueblvip/p/14378031.html