<script type="text/javascript">

<!---计算折扣后的总价格--->
function outtotalprice(i) {
document.getElementsByName("items[#index#].TotaPricel")[i].value = document.getElementsByName("items[#index#].qty")[i].value * document.getElementsByName("items[#index#].Price")[i].value; }
<!----在动态显示 原价、折扣、折扣后的总价---->
function OutTotalPrice() {
var len = document.getElementsByName("items[#index#].TotaPricel").length;
var ordertotalprice = ;
for (var j = ; j < len; j++) {
ordertotalprice += parseFloat(document.getElementsByName("items[#index#].TotaPricel")[j].value);
}
document.getElementById("Out.TotalPrice").value = ordertotalprice.toFixed();
var strdiscount = parseFloat(parseInt(document.getElementById("Out.discount").value) / ).toFixed();
var strdiscountPrice = parseFloat(ordertotalprice * strdiscount).toFixed();
document.getElementById("Out.discountPrice").value = strdiscountPrice;
document.getElementById("spanoldprice").innerHTML = ordertotalprice.toFixed();
document.getElementById("spandistinct").innerHTML = document.getElementById("Out.discount").value;
document.getElementById("spandisprice").innerHTML = strdiscountPrice;
}
</script>

声明两个对象:

  <%: Html.HiddenFor(model => model.TotalPrice, new { id = "Out.TotalPrice" })%>
<%: Html.HiddenFor(model => model.discountPrice, new { id = "Out.discountPrice" })%>
   <div class="sortDrag" style="width: 20%; border: 1px solid #e66; margin: 5px; float: inherit;min-height: 220px;">
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
原价(¥)&nbsp;&nbsp;&nbsp;<span id="spanoldprice" style="color: Red; font-size: x-large"><%=ViewData["totalPrice"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
折扣(%)&nbsp;&nbsp;&nbsp;<span id="spandistinct" style="color: Red; font-size: x-large"><%=ViewData["discount"]%></span></div>
<div style="border: 1px solid #B8D0D6; padding: 10px; margin: 10px">
总价(¥)&nbsp;&nbsp;&nbsp;<span id="spandisprice" style="color: Red; font-size: x-large"><%=ViewData["discountPrice"]%></span></div>
</div>

后台代码

 private string BindTableOutSend(IList<VOutProceManager> objList)
{
sbProcessingtype = null;
getProcessingtype();
string strCalMethod = "";
StringBuilder sb = new StringBuilder();
int i = ;
string currentdate = DateTime.Now.ToString("yyyy-MM-dd");
foreach (VOutProceManager obj in objList)
{
if (ViewBag.outauditstate <= )
{
sb.Append("<tr class=\"unitBox\">");
sb.Append("<input type=\"hidden\" name=\"items[#index#].Id\" submitName=\"items[" + i + "].Id\" value=\"" + obj.Id + "\" /> ");
sb.Append("<input type=\"hidden\" name=\"items[#index#].bomID\" submitName=\"items[" + i + "].bomID\" value=\"" + obj.bomID + "\" /> ");
sb.Append("<input type=\"hidden\" name=\"items[#index#].Isbom\" submitName=\"items[" + i + "].Isbom\" value=\"" + obj.Isbom + "\" /> ");
sb.Append("<td ><input class=\"textInput \" size='15' readonly=\"readonly\" value=\"" + obj.mouldNo + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" value=\"" + obj.partName + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='3' readonly=\"readonly\" value=\"" + obj.drawingNo + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" name=\"items[#index#].qty\" submitName=\"items[" + i + "].qty\" value=\"" + obj.qty + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='15' readonly=\"readonly\" name=\"items[#index#].typeName\" submitName=\"items[" + i + "].typeName\" value=\"" + obj.typeName + "\" > </td> ");
sb.Append("<td>");
sb.Append("<SELECT name=\"items[#index#].PriceType\" submitName=\"items[" + i + "].PriceType\">");
strCalMethod = obj.PriceType;
if (strCalMethod == "体积")
{
sb.Append("<OPTION selected value='体积'>体积</OPTION><OPTION value=面积>面积</OPTION>");
}
else
{
sb.Append("<OPTION value='体积'>体积</OPTION><OPTION selected value=面积>面积</OPTION>");
}
sb.Append("</SELECT>");
sb.Append("</td>");
sb.Append("<td ><input class=\"textInput required number\" size='9' name=\"items[#index#].Quantity\" submitName=\"items[" + i + "].Quantity\" value=\"" + obj.Quantity + "\" > </td>");
sb.Append("<td ><input class=\"textInput\" type=\"lookup\" size='3' name=\"items[#index#].Unit.Name\" lookupgroup=\"items[#index#].Unit\" suggesturl=\"projectGL/Mould/GetName?typeid=7\" suggestfields=\"Name\" postfield=\"keywords\" submitName=\"items[" + i + "].Unit.Unit\" value=\"" + obj.Unit + "\" > </td>");
sb.Append("<td ><input class=\"textInput required number\" size='9' name=\"items[#index#].Price\" onkeyup=\"outtotalprice(" + i + ");OutTotalPrice()\" submitName=\"items[" + i + "].Price\" value=\"" + obj.Price + "\" > </td>");
sb.Append("<td ><input class=\"textInput \" size='9' readonly=\"readonly\" name=\"items[#index#].TotaPricel\" submitName=\"items[" + i + "].TotaPricel\" value=\"" + obj.TotaPricel + "\" > </td>");
sb.Append("</tr>");
i++;
}
}
return sb.ToString();
}

首次加载:初始化的后台显示(未输入价格前)

   ViewData["totalPrice"] = ;
ViewData["discount"] = "100%";
ViewData["discountPrice"] = ;

在提交的方法里

判断是否输入单价:把每种类型的总价累加起来,得到最后的总价:

decimal totalprice = 0.0m;
decimal countprice = 0.0m;
bool iszero = true;
while (!string.IsNullOrEmpty(Request.Form["items[" + i + "].Id"]))
{ totalprice = decimal.Parse(Request.Form["items[" + i + "].TotaPricel"]);
countprice += totalprice;
ViewData["totalPrice"] = countprice;
if (totalprice <= )
{
iszero = false;
break;
}
i++;
}
if (!iszero)
{
return SaveSuccessStr("", "单价不能小于等于0!", "", "", "");
}

在提交的方法里计算折扣后的总价格:

  if (Tmodels.discount == )
Tmodels.discountPrice = countprice;
else
Tmodels.discountPrice = Convert.ToDecimal(countprice * (Tmodels.discount / 100.0m));

js 动态计算折扣后总价格的更多相关文章

  1. JS动态生成表格后 合并单元格

    JS动态生成表格后 合并单元格 最近做项目碰到表格中的单元格合并的问题,需求是这样的,首先发ajax请求 请求回来后的数据 动态生成表格数据,但是生成后如果编号或者(根据其他的内容)有相同时,要合并单 ...

  2. 还能输入多少字?(JS动态计算)

    <div class="m-form ovh"> <div class="hd"> <span class="fr&qu ...

  3. 理解rem实现响应式布局原理及js动态计算rem

    前言 移动端布局中,童鞋们会使用到rem作为css单位进行不同手机屏幕大小上的适配.那么来讲讲rem在其中起的作用和如何动态设置rem的值. 1.什么是rem rem是相对于根元素(html标签)的字 ...

  4. js动态获取地址栏后的参数

    原文链接:https://blog.csdn.net/qq_37936542/article/details/78866651 需求:js动态的获取地址栏后面的参数 js代码: alert(GetQu ...

  5. js动态计算移动端rem适配问题

    第一:css3的media query来实现适配,例如下面这样: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 ...

  6. JS动态计算移动端rem的解决方案

    首先介绍下rem 说起rem就的说px,em: PX为单位 在Web页面初期制作中,我们都是使用“px”来设置我们的文本,因为他比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的 ...

  7. js动态计算移动端rem

    在做移动端web app的时候,众所周知,移动设备分辨率五花八门,虽然我们可以通过CSS3的media query来实现适配,例如下面这样: html { font-size : 20px; } @m ...

  8. JS动态插入HTML后不能执行后续JQUERY操作

    通过js追加的html 发现 不能点击 执行函数   普通绑定事件:$('.btn1').click(function(){}绑定 事件委托   解决方法: $("body").d ...

  9. 关于cefsharp 获取js动态加载后的信息

    IFrame frame = null; var identifiers = Browser.GetBrowser().GetFrameIdentifiers(); foreach (var i in ...

随机推荐

  1. js判断选择时间不能小于当前时间的代码

    判断选择时间不能小于当前时间的方法有很多,在本文为大家详细介绍下使用js是如何实现的,感兴趣的朋友可以尝试操作下 复制代码代码如下: var controldate;  function checkD ...

  2. 就谈个py 的装饰器 decorator

    很早很早就知道有这么个 装饰器的东西,叫的非常神秘. 包括c#  和 java 中都有这个东西, c#中叫做attribut 特性,java中叫做Annotation 注解,在偷偷学习c#教程的时候, ...

  3. 一、记一次失败的 CAS 搭建 之 环境配置

    ==================================================================================================== ...

  4. 【BZOJ2152】聪聪可可

    Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...

  5. 1588: [HNOI2002]营业额统计 - BZOJ

    Description营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天 ...

  6. SetTimer在无窗口和有窗口线程的使用 . .

    今天犯了一个粗心的错误,在无窗口线程中,SetTimer中设置计时器ID,而WM_TIMER消息响应函数中得到的计时器ID却不是之前设置的计时器ID. 对应计时器ID的输出的是一个随机数字. 原来在m ...

  7. SQL Server CONVERT() 函数

    http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用 ...

  8. HDU4756+Prim

    题意简单:去掉最小生成树的某一条边并补上一条,求MaxVal 思路:贪心(借鉴Yamidie的思路...) 分别求出最小生成树和次最小生成树,再在这两棵树上求最小生成树 #include<std ...

  9. Why does yum return error: [Errno 256] No more mirrors to try ?

    https://access.redhat.com/solutions/203603 ISSUE yum update fails with the error : [Errno 256] No mo ...

  10. Android 显示大图片

    主要的代码如下: BitmapFactory.Options options = new BitmapFactory.Options(); //图片解析配置 options.inJustDecodeB ...