<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. foxtable使用笔记

    1.设置关联表窗口的列的顺序:Tables("award.people").SetColVisibleWidth("name|100|sex|100|job|100|ag ...

  2. SDP协议分析

    一.SDP协议介绍 SDP 完全是一种会话描述格式 ― 它不属于传输协议 ― 它只使用不同的适当的传输协议,包括会话通知协议(SAP).会话初始协议(SIP).实时流协议(RTSP).MIME 扩展协 ...

  3. 提取图像(tif)中水体的矢量数据(shp)研究

    方法一:1、利用envi打开tif数据,原投影信息为beijing54.envi中没有这个投影。这里选择投影信息(WGS-84)选取水体roi——进行监督分类。这里可以对分类后进行处理(消除文字等干扰 ...

  4. 【MyBatis】 通过包含的jdbcType类型

    BIT         FLOAT      CHAR           TIMESTAMP       OTHER       UNDEFINED TINYINT     REAL       V ...

  5. 【BZOJ 1010】 [HNOI2008]玩具装箱toy

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...

  6. 【BZOJ 2878】 [Noi2012]迷失游乐园

    Description 放假了,小Z觉得呆在家里特别无聊,于是决定一个人去游乐园玩.进入游乐园后,小Z看了看游乐园的地图,发现可以将游乐园抽象成有n个景点.m条道路的无向连通图,且该图中至多有一个环( ...

  7. Nhibernate 多对多级联删除

    在网上找到的方法:查看这里 //-------------------------------------Article.hbm.xml-------------------------------- ...

  8. 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript

    常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...

  9. Apache2.2+php5.4在windows上配置实例

    这几天一直在win8.1上配置apache+php环境,网上看了很多文章,自己又犯了很多错误才配置成功,对新手来说真是有点小难. 自己打算把配置的详细过程写下来,好帮助其他新手快速配置. 在这里参考了 ...

  10. Angular与React的一些看法

    Angular - React之争 Angular和React无疑是目前最受追捧的两个前端框架,谷歌也发现Angular1.x不足的地方,开始开发2.0版本,脸书发现React的组件化和虚拟DOM非常 ...