underscore.js,js工具库

官方文档:http://underscorejs.org/

var totalCheckPriceVal = _.reduce(tableData[0],function(memo,num){

var memoint=memo-0;

var numint=num-0;

return memoint+numint; },0

)

_.reduce()

计算一个数组里所有值相加

var selectProdutData = _.indexBy(prodcutList,function(obj){

return obj.originalProductCode+obj.stationCode+obj.orderNumber;

});

._indexBy()

返回一个key-value形式的js对象可用于添加商品业务逻辑的实现;

_.map(productsData,function(product){

var objNegative={};

if((product.confirmedNumber-0)<=0){

isNegative=true;

objNegative.originalProductCode=product.originalProductCode;

objNegative.stationCode=product.stationCode;

objNegative.orderNumber=product.orderNumber;

arrayNegative.push(objNegative);

}

})

._map()

一个遍历函数;

遍历的时候遇到异步执行的函数会同步执行;

使用underscore制作一个打印分页html

<!doctype html>
<head>
<title></title>
<script src="./jquery.js"></script>
<script src="./underscore-min.js"></script>
<style type="text/css">
		*{padding: 0;margin:0;}
		table{border-collapse:collapse;border: 1px solid  #000000;border-spacing:0;width: 100%;text-align: left;margin-top: 10px;}
		table td,table th{padding: 0 3px;height: 19px;line-height: 15.5px;border: 1px solid #000;}
		body{padding: 5px;font-size: 12px;} 
		ul{list-style-type: none;font-size: 0;position: relative;}
		ul li{display: inline-block;width: 50%;font-size: 12px;margin: 10px 0;}
		ul li.op{position: absolute;right: 100px;top: 15px;width: 80px;}
		td.title{text-align: left;width: 100px;}
		tr.blank{height: 17px;border: 1px solid #fff;}
		#print{padding-right: 15px;position: relative;}
		.pageer{position: absolute;right: 0px;display:none;top:0;color: #000000;font-size: 14px;}
		@media print {
		  .paging {page-break-after:always;}
		  .page{display:inline-block;right: -5px;}
		}
		#list{margin: 15px 0;}
		#list th{text-align: center;}
		
		.mouth{
		    -ms-transform: rotate(-90deg);
		    -webkit-transform: rotate(-90deg);
		    -moz-transform: rotate(-90deg);
		    -o-transform: rotate(-90deg);
	   }
	   
	   .ie8mouth{
		   filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); 
	   }
	</style>
    <script id="teml" type="text/template">
	<div style="width:100%" align="center"><font size="6">服务商送货任务单</font></div>
	<div id="print" class='paging'>
		<table>
			<tbody><tr>
				<td rowspan="6" style="text-align:center;border-bottom: 0px;">
					<p class="mouth">商</p><p class="mouth">务</p><p class="mouth">服</p><p class="mouth">:</p><p class="mouth">联</p><p class="mouth">色</p><p class="mouth">白</p>
				</td>
				<td class="title" colspan="2">原厂订单编号</td>
				<td colspan="2"><%= productdescripe[0].orderCode %></td>
				<td class="title" colspan="2">厂商品牌</td>
				<td colspan="2"><%= productdescripe[0].brand %></td>
			</tr>
			<tr>
				<td class="title" colspan="2">配送任务单号</td>
				<td colspan="2"><%= productdescripe[0].taskCode %></td>
				<td class="title" colspan="2">订单创建日期</td>
				<td colspan="2"><%= productdescripe[0].createTime %></td>
			</tr>
			
			<tr>
				<td class="title" colspan="2">站点名称</td>
				<td colspan="2"><%= productdescripe[0].stationName %></td>
				<td class="title" colspan="2">ASC代码</td>
				<td colspan="2"><%= productdescripe[0].ascCode %></td>
			</tr>
			<tr>
				<td class="title" colspan="2">站点联系人</td>
				<td colspan="2"><%= productdescripe[0].stationPerson %></td>
				<td class="title" colspan="2">站点电话</td>
				<td colspan="2"><%= productdescripe[0].stationPhone %></td>
			</tr>
			
			<tr>
				<td class="title" colspan="2">站点送货地址</td>
				<td colspan="2"><%= productdescripe[0].stationAddress %></td>
				
				<td class="title" colspan="2">原厂订单日期</td>
				<td colspan="2"><%= productdescripe[0].orderTime %></td>
			</tr>
			
			<tr>
				<td class="title" colspan="2">服务商名称</td>
				<td colspan="2"><%= productdescripe[0].serviceName %></td>
				<td class="title" colspan="2">服务商编号</td>
				<td colspan="2"><%= productdescripe[0].serviceNumber %></td>
				
			</tr>
			
			<tr>
				<td rowspan="31" style="text-align:center;border-bottom: 0px;border-top: 0px;" id="datalist"> <!-- 上海通用雪佛兰 -->
					
					<p class="mouth">
					兰

					</p>
					
					<p class="mouth">
					佛

					</p>
					
					<p class="mouth">
					雪

					</p>
					
					<p class="mouth">
					用

					</p>
					
					<p class="mouth">
					通

					</p>
					
					<p class="mouth">
					海

					</p>
					
					<p class="mouth">
					上

					</p>
					
					<p class="mouth">:</p><p class="mouth">联</p><p class="mouth">色</p><p class="mouth">蓝</p>
					
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					
					<p class="mouth">O</p><p class="mouth">Z</p><p class="mouth">K</p><p class="mouth">A</p>
					<p class="mouth">:</p><p class="mouth">联</p><p class="mouth">色</p><p class="mouth">红</p>
					
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					<p class="mouth"> </p>
					
					<p class="mouth">理</p><p class="mouth">代</p><p class="mouth">总</p>
					<p class="mouth">:</p><p class="mouth">联</p><p class="mouth">色</p><p class="mouth">绿</p>
				</td>
				<td class="title" colspan="2">服务商联系人</td>
				<td colspan="2"><%= productdescripe[0].servicePerson %> </td>
				<td class="title" colspan="2"><%= productdescripe[0].servicePhone %></td>
				<td colspan="2">13301607008</td>
			</tr>
			
			<tr>
				<td style="text-align: right">序号</td>
				<td>配件号</td>
				<td colspan="2">配件名称</td>
				<td colspan="2">订购数量(罐)</td>
				<td colspan="2">实收数量(罐)</td>
			</tr>
			
<!--startprint-->
        <% for(var i = 0; i < 29; i++) { %>  
        <% var item = list[i]; if(item){%>  
                <tr><td>1</td>
					<td><%= item.code %>        </td>
					<td colspan="2"><%= item.name %></td>
					<td colspan="2"><%= item.ordercount %></td>
					
						<td colspan="2"><%= item.receiptcount %></td>				
				</tr>
                <%} else{%>
                <tr><td></td>
					<td></td>
					<td colspan="2"></td>
					<td colspan="2"></td>
					
						<td colspan="2"></td>				
				</tr>
                <%}%>
                 <% } %>  
			<tr>
				<td rowspan="5" style="text-align:center;border-top: 0px;">
					<p class="mouth">点</p><p class="mouth">站</p><p class="mouth">C</p><p class="mouth">S</p><p class="mouth">A</p>
					<p class="mouth">:</p><p class="mouth">联</p><p class="mouth">色</p><p class="mouth">黄</p><p class="mouth"> </p>
				</td>
				<td></td>
				<td></td>
				<td colspan="2"></td>
				<td colspan="2"></td>
				<td></td>
			</tr>
			
			<tr><td>合计</td>
				<td></td>
				<td colspan="2"></td>
				<td colspan="2" class="ordercount"></td>
				<td colspan="2" class="receiptcount"></td></tr>
			
			<tr>
				<td colspan="2"></td>
				<td colspan="2"></td>
				<td colspan="2"></td>
				<td colspan="2"></td>
			</tr>
			<tr>
				<td colspan="2">送货人</td>
				<td colspan="2">收件人</td>
				<td colspan="2" style="text-align:center">盖章</td>
				<td colspan="2"></td>
			</tr>
			<tr>
				<td colspan="2">送货时间</td>
				<td colspan="2">收货时间</td>
				<td colspan="2"></td>
				<td colspan="2">
				</td>
			</tr>
		</tbody></table>
	</div>
    </script>
</head>
<body>
    
</body>
<script type="text/javascript">
var data={  
		productdescripe:[{
		orderCode:"P2200391160401000",
		taskCode:"AKS16041515441113922",
		stationName:"上海九炫汽车销售服务有限公司",
		stationPerson:"test",
		stationAddress:"上海奉贤区南亭公路1269号",
		serviceName:"上海光环工贸有限公司",
		servicePerson:"姜宏伟 ",
		brand:"上海通用雪佛兰",
		createTime:"2016-4-15 15:44:11",
		ascCode:"2200391", 
		stationPhone:"22222",
		orderTime:"2016-04-15",
		serviceNumber:"107131",
		servicePhone:"13301607008"
		}],
        list: [
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"7",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"4",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"5",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"6",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
            {code: "YQ-9850918",name:"新劲7号底色漆 MM Q271 1升",ordercount:"8",receiptcount:"7"},
        ]
    }; 
var arr=data.list;
var ordercountlist=_.pluck(arr, 'ordercount');
var ordercountsum = _.reduce(ordercountlist, function(memo, num){ return parseInt(memo) + parseInt(num); }, 0);
var length=arr.length;
var render = _.template($('#teml').html());
var html = render(data);
$("body").html(html);
var page=parseInt(length/29)+1;
for(j=1;j<page;j++){
    arr.splice(0,29*j);
    var render = _.template($('#teml').html());
    var html = render(data);
    $("body").append(html);
}
$("table").last().parent().removeClass("paging");
$("td[class=ordercount]").last().html(ordercountsum)
</script>
</html>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏FSociety

SQL中GROUP BY用法示例

GROUP BY我们可以先从字面上来理解,GROUP表示分组,BY后面写字段名,就表示根据哪个字段进行分组,如果有用Excel比较多的话,GROUP BY比较类...

5.1K20
来自专栏腾讯社交用户体验设计

ISUX Xcube智能一键生成H5

50820
来自专栏Ken的杂谈

【系统设置】CentOS 修改机器名

17230
来自专栏怀英的自我修炼

考研英语-1-导学

英二图表作文要重视。总体而言,英语一会比英语二难点。不过就写作而言,英语二会比英语一有难度,毕竟图表作文并不好写。

11310
来自专栏钱塘大数据

理工男图解零维到十维空间,烧脑已过度,受不了啦!

让我们从一个点开始,和我们几何意义上的点一样,它没有大小、没有维度。它只是被想象出来的、作为标志一个位置的点。它什么也没有,空间、时间通通不存在,这就是零维度。

26930
来自专栏腾讯高校合作

【倒计时7天】2018教育部-腾讯公司产学合作协同育人项目申请即将截止!

15220
来自专栏前端桃园

知识体系解决迷茫的你

最近在星球里群里都有小伙伴说道自己对未来的路比较迷茫,一旦闲下来就不知道自己改干啥,今天我这篇文章就是让你觉得一天给你 25 个小时你都不够用,觉得睡觉都是浪费...

19440
来自专栏钱塘大数据

中国互联网协会发布:《2018中国互联网发展报告》

在2018中国互联网大会闭幕论坛上,中国互联网协会正式发布《中国互联网发展报告2018》(以下简称《报告》)。《中国互联网发展报告》是由中国互联网协会与中国互联...

13250
来自专栏微信公众号:小白课代表

不只是软件,在线也可以免费下载百度文库了。

不管是学生,还是职场员工,下载各种文档几乎是不可避免的,各种XXX.docx,XXX.pptx更是家常便饭,人们最常用的就是百度文库,豆丁文库,道客巴巴这些下载...

43230
来自专栏haifeiWu与他朋友们的专栏

复杂业务下向Mysql导入30万条数据代码优化的踩坑记录

从毕业到现在第一次接触到超过30万条数据导入MySQL的场景(有点low),就是在顺丰公司接入我司EMM产品时需要将AD中的员工数据导入MySQL中,因此楼主负...

26540

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励