<tbody>
                            <tr id="demoR" style="display: none">
                                <td>
                                    <input type='checkbox' name='ckb_r' data-id="-1"/>
                                </td>
                                <td>
                                 <input  name="expenseRList[-1].settleObjId" type="text" style="width:220px" data_name='settleObj' rp_flag='R'
                                 />
<!--                                     <select name="expenseRList[-1].settleObjId" style="width:150px"> -->
<%--                                         <option value="${requestScope.companyModel.companyId}" >${requestScope.companyModel.companyCname}</option> --%>
<!--                                     </select> -->
                                </td>
                                <td>
                                    <e:Select name="expenseRList[-1].chargeId"
                                        queryName="${applicationScope.bacQuery.CHARGEITEM}"
                                        textField="chargeCname" valueField="chargeId" selectValue="" attribute="style='width:150px' datatype='*'"/><span class="Validform_checktip"></span>
                                </td>
<!--                                 <td> -->
<!--                                     <input type="text" style="width:81%" value="" name="expenseRList[-1].chargeRate"> -->
<!--                                 </td> -->
                                <td>
                                    <e:Select name="expenseRList[-1].chargeUnit"
                                        queryName="${applicationScope.bacQuery.CHARGEUNIT}"
                                        textField="unitCname" valueField="unitId" selectValue=""  attribute="style='width:100px' datatype='*'"/><span class="Validform_checktip"></span>
                                </td>
                                <td>
                                    <input id="countR-1" changeR-id="-1" type="text" style="width:81%" value="" name="expenseRList[-1].count" datatype="n"><span class="Validform_checktip"></span>
                                </td>
                                <td>
                                    <e:Select id="expenseRCurrency-1" name="expenseRList[-1].currency"  
                                        queryName="${applicationScope.bacQuery.CURRENCY}"
                                        textField="curMeaning" valueField="curCode" selectValue="${requestScope.valueOfCurrency }"  attribute="style='width:100px' datatype='*' onchange='caculateAmount()'"/><span class="Validform_checktip"></span>                        
                                </td>
                                
                            
                                <td>
                                    <input id="unitPriceR-1" changeR-id="-1" type="text" style="width:91%" value="" name="expenseRList[-1].unitPrice" datatype="/^[+]?\d+(\.\d+)?$/" errormsg="请填写数字"><span class="Validform_checktip"></span>
                                </td>                                    
                                   
                                
                                                    
                                <td>
                                    <input id="amountR-1" type="text" style="width:81%" value="0" name="expenseRList[-1].amount" readonly
                                    data='1' dataname='amountR' datacur='USD'>
                                </td>
                                
                                <input type="hidden" name="expenseRList[-1].rpFlag" value="R" />
                                <input id="r-1" type="hidden" name="expenseRList[-1].modelState" value="" />
                                <input id="rId-1" type="hidden" name="expenseRList[-1].expenseId" value="" />
                                
                            </tr>
                            <c:forEach var="item" items="${requestScope.expenseModel.expenseRListShow}" varStatus="status">
                                <tr>
                                    <td>
                                        <input type='checkbox' name='ckb_r' data-id="${status.index}"/>
                                    </td>
                                    <td>
                                     <input  name="expenseRList[${status.index}].settleObjId" type="text" style="width:220px" data_name='settleObj' settleObj_id="${item.settleObjId}" settleObj_name="${item.settleObjName}"/>
<%--                                         <select name="expenseRList[${status.index}].settleObjId" style="width:150px"> --%>
<%--                                             <option value="${requestScope.companyModel.companyId}" >${requestScope.companyModel.companyCname}</option> --%>
<!--                                         </select> -->
                                    </td>
                                    <td>
                                        <e:Select name="expenseRList[${status.index}].chargeId"
                                            queryName="${applicationScope.bacQuery.CHARGEITEM}"
                                            textField="chargeCname" valueField="chargeId" selectValue="${item.chargeId}" attribute="style='width:150px' datatype='*'"/><span class="Validform_checktip"></span>
                                    </td>
<!--                                     <td>                                         -->
<%--                                         <input type="text" style="width:81%" value="${item.chargeRate}" name="expenseRList[${status.index}].chargeRate" onkeyup="value=value.replace(/[^\-?\d.]/g,'')" onafterpaste="this.value=this.value.replace(/[^\-?\d.]/g,'')"> --%>
<!--                                     </td> -->
                                    <td>
                                        <e:Select name="expenseRList[${status.index}].chargeUnit"
                                            queryName="${applicationScope.bacQuery.CHARGEUNIT}"
                                            textField="unitCname" valueField="unitId" selectValue="${item.chargeUnit}"  attribute="style='width:100px' datatype='*'"/><span class="Validform_checktip"></span>
                                    </td>
                                    <td>
                                        <input id="countR${status.index}" changeR-id="${status.index}" type="text" style="width:81%" value="<f:formatNumber value="${item.count}" pattern="###,###" />" name="expenseRList[${status.index}].count" datatype="n" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "><span class="Validform_checktip" ></span>
                                    </td>
                                    <td>
                                        <e:Select id="expenseRCurrency${status.index}" name="expenseRList[${status.index}].currency"  
                                            queryName="${applicationScope.bacQuery.CURRENCY}"
                                            textField="curMeaning" valueField="curCode"  selectValue="${item.currency}"  attribute="style='width:100px' datatype='*' onchange='caculateAmount()'"  /><span class="Validform_checktip"></span>                        
                                    </td> 
                                    
                                    
                                    <td>
                                        <input id="unitPriceR${status.index}" changeR-id="${status.index}" type="text" style="width:91%" value="${item.unitPrice}" name="expenseRList[${status.index}].unitPrice" datatype="/^[+]?\d+(\.\d+)?$/" errormsg="请填写数字" onkeyup="value=value.replace(/[^\-?\d.]/g,'')" onafterpaste="this.value=this.value.replace(/[^\-?\d.]/g,'')" ><span class="Validform_checktip" ></span>
                                    </td>        
                                     
                                     
                                    <td>
                                        <input id="amountR${status.index}" type="text" style="width:81%" value="${item.amount}" name="expenseRList[${status.index}].amount" readonly
                                        data='${item.amount}' dataname='amountR' datacur='${item.currency}'>                                        
                                    </td>
                                                                        
                                                                        
                                    <input type=hidden name="expenseRList[${status.index}].rpFlag" value="R" />
                                    <input id="r${status.index}" type=hidden name="expenseRList[${status.index}].modelState" value="" />
                                    <input id="rId${status.index}" type="hidden" name="expenseRList[${status.index}].expenseId" value="${item.expenseId}" />
                                </tr>
                            </c:forEach>
                        </tbody>
$('#RUSD').attr("disabled",true);
        $('#RCNY').attr("disabled",true);
        $('#PUSD').attr("disabled",true);
        $('#PCNY').attr("disabled",true);
        $('#ProfitUSD').attr("disabled",true);
        $('#ProfitCNY').attr("disabled",true);
        $('#totalCNY').attr("disabled",true);
        $(function(){
            caculateAmount();
        })
        
        
        $("input[dataname='amountR']").change(function(){
            caculateAmount();
        });
        
        $("input[dataname='amountP']").change(function(){
            caculateAmount();
        });
function caculateAmount(){
                var RBoxs=$("input[dataname='amountR']");
                var PBoxs=$("input[dataname='amountP']");             
                var r_usdAmount=0;
                var r_cnyAmount=0;
                var p_usdAmount=0;
                var p_cnyAmount=0;
                var profit_usdAmount=0;
                var profit_cnyAmount=0;
                var total_cnyAmount=0;    
                var R = 0;
                var P = 0;
                var indexR = 0;
                var indexP = 0;
                var rate = 0;
                
                var rateURL="${pageContext.request.contextPath}/rest/bacCurrencyRateService/getNewRate.json"; 
                $.post(rateURL,function(result){
                    rate = result.data;
                    RBoxs.each(function(){    
                        if((indexR++)==0){
                            //跳过demoR
                        }else{
                        var amount=$(this).val();
                        var cur=$("#expenseRCurrency"+(R++)).val();                    
                        var floatAmount=parseFloat(amount);
                        if(!floatAmount)floatAmount=0;
                        if(cur=='USD'){
                            r_usdAmount+=floatAmount;
                        }else if(cur=='CNY'){
                            r_cnyAmount+=floatAmount;
                        }
                    }
                    });    
                    
                     PBoxs.each(function(){    
                        if((indexP++)==0){
                             //跳过demoP
                         }else{
                            var amount=$(this).val();
                            var cur=$("#expensePCurrency"+(P++)).val();    
                            var floatAmount=parseFloat(amount);
                            if(!floatAmount)floatAmount=0;
                            if(cur=='USD'){
                                p_usdAmount+=floatAmount;
                            }else if(cur=='CNY'){
                                p_cnyAmount+=floatAmount;
                            }
                        };
                    });
                     
                    profit_usdAmount=r_usdAmount-p_usdAmount;
                    profit_cnyAmount=r_cnyAmount-p_cnyAmount;
                    total_cnyAmount=profit_usdAmount*rate+profit_cnyAmount;
                    $('#RUSD').val(fmoney(r_usdAmount,2));
                    $('#RCNY').val(fmoney(r_cnyAmount,2));
                    $('#PUSD').val(fmoney(p_usdAmount,2));
                    $('#PCNY').val(fmoney(p_cnyAmount,2));
                    $('#ProfitUSD').val(fmoney(profit_usdAmount,2));
                    $('#ProfitCNY').val(fmoney(profit_cnyAmount,2));
                    $('#totalCNY').val(fmoney(total_cnyAmount,2));
                },"json"); 
                
                
            }
            
             function fmoney(s, n) //s:传入的float数字 ,n:希望返回小数点几位
             {
                 if(s==null)return '';
                 n = n > 0 && n <= 20 ? n : 2;
                 s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                 var l = s.split(".")[0].split("").reverse(),
                 r = s.split(".")[1];
                 t = "";
                 for(i = 0; i < l.length; i ++ )
                 {
                 t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                 }
                 return t.split("").reverse().join("") + "." + r;
             }