扫码枪 js批量生成条码

来源:互联网 发布:windows安全对话框 编辑:程序博客网 时间:2024/06/11 20:51
<formid="form2">
<inputtype="hidden"name="type_code"id="type_code"value="">
<li>
<divstyle="width:70%;height:35px;line-height:35px;float:left;">
<spanstyle="display:inline-block;width:125px;text-align:right;color:#999;font-size:15px;">条码设置</span>
<divstyle="float:right;color:#999;font-size:15px;">
条码长度
<inputtype="number"id="code_size"value="<?php if($cnf['code_size']){echo$cnf['code_size'];}else{echo13;}?>"style="width:40px;">
<divclass="btn btn-warning actionbt code_size" style="">
立 即 设 置
</div>
</div>
<divstyle="float:right;margin-right:20px;color:#999;font-size:15px;margin-right:40px;">
箱装条码
<inputtype="number"id="code_start"value="<?php echo $cnf['code_start']?>"style="width:40px;">
位开始后
<inputtype="number"id="code_end"value="<?php echo $cnf['code_end']?>"style="width:40px;">
</div>
<br>
</div>
<divclass=""style="">
<divstyle="float:left;"class="box_code">
<divclass="button_code case_box">
<b>件 装 扫 码</b>
</div>
</div>
<divstyle="float:left;"class="case_code">
<divclass="button_code ">
<b>箱 装 扫 码</b>
</div>
</div>
</div>
</li>
<?php
$a=0;
foreach($data['goods']as$k=>$goods) {?>
<inputtype="hidden"name="order_sn"id="order_sn"value="<?php echo $data['order_sn']?>">
<inputtype="hidden"name="order_id"id="order_id"value="<?php echo $data['_id']?>">
<li>
<divclass="goodsdetail"style="margin-left:130px">
<ahref="/app/goods/edit.html<?php echo $exturl?>&id=<?php echo $goods['goodsid']?>">
<spanclass="goodspic"><imgsrc="<?php echo $goods['pic']?>"/></span>

<divclass="gs"style="width:200px;">
<spanclass="goodname"><?php echo $goods['goodsname']?></span>
<spanclass="myask">
<?php
if(!empty($goods['attr'])) {
foreach($goods['attr']as$key=>$row) {
echo$row['name'] . ':'.$row['val'] . ",";
}
}
echo"数量:".$goods['count'] . ",单价:". formatYuan($goods['price']);
?>
</span>
</div>
</a>
</div>
<!-- 盒装扫码-->
<divclass="box_code_state formtips">
<divstyle="text-align:right;">
<?php
$track= LogisticsTrackModel::where(array('order_sn'=>$data['order_sn'],'goodsid'=>intval($goods['goodsid'])))->get();
?>
<?php if ($track->count()) { ?>
<?php foreach ($trackas$val) {?>

<inputtype="text"name="code[<?php echo $goods['goodsid']?>][]"
value="<?php echo $val->code?>"class="aabb">
<?php}?>
<?php}else{?>
<?php
for($i=1;$i<=$goods['count'];$i++) {
?>
<inputtype="text"name="code[<?php echo $goods['goodsid']?>][]"
class='aabb'>
<?php}?>
<?php}?>
</div>
</div>
<!-- 箱装扫码-->
<divclass="case_code_state">
<divstyle="text-align:right;"id="add_content<?php echo $k?>">
<divclass='formtips case_bbcc' >
<inputtype='text'class='bbcc'name='start[<?php echo $goods['goodsid']?>][]'> -- <inputtype='text'class='bbcc'name='end[<?php echo $goods['goodsid']?>][]'>
<spanstyle="font-size:15px;color:#359947"class="add_button<?php echo $k?>"><b>+</b></span><br>
</div>
</div>
</div>
<script>
//添加input 删除input
$(document).ready(function() {
$(".add_button<?php echo $k?>").click(function() {
$("#add_content<?php echo $k?>").append(
"<div class='formtips case_bbcc' ><input type='text' class='bbcc' name='start[<?php echo$goods['goodsid']?>][]'> -- <input type='text' class='bbcc' name='end[<?php echo $goods['goodsid']?>][]'><span class='delete_content' style='font-size: 20px;'> -</span><br></div>");
});
$('body').on('click','.delete_content',function() {
$(this).parent(".formtips").remove();
})
});
</script>
</li>
<?php}?>
<divclass="order-view"style="margin-left:110px;">
<tableclass="table">
<thead>
<trstyle="color:#FF3939">
<td>

*在使用扫码前确定扫码枪规格,取消 回车/换行 功能
<br>
*箱装条码设置:例如 条码 a8567cdef 第2位开始后3位 指的是条码中的 856
<br>
*条形码默认为标准13位纯数字条码, 其他规格条码需要设置条码长度,否则扫码时不会自动跳转
<br>
*件装扫码:对每一个商品进行一一扫码
<br>
*箱装扫码:条码必须是不间断纯数字条码,扫码只需要扫每一箱的开始和结尾条码
<br>
*修改扫码:在件装扫码进行单个扫码修改,在箱装进行批量修改必须从新扫码
</td>
<td>
<divid="submit"class="btn btn-warning actionbt">
保 存 条 形 码
</div>

</td>
</tr>
</thead>
</table>
</div>
<scripttype="text/javascript">
$('body').on('input','.bbcc',function() {
if($(this).val().length>= <?php if($cnf['code_size']){echo$cnf['code_size'];}else{echo13;}?>) {
varnext= $(this).next('.bbcc');
next= next.length? next: $(this).parents('.case_bbcc').nextAll().find(".bbcc").first();
if(next.length==0){
next= next.length? next: $(this).parents('li').nextAll().find(".bbcc").first();
}
next.focus();
next.val("")

}
})
$('body').on('input','.aabb',function() {
if($(this).val().length>= <?php if($cnf['code_size']){echo$cnf['code_size'];}else{echo13;}?>) {
varnext= $(this).next();
//next = next.length ? next : $(this).parent().parent().parent().next().find(".aabb").first();
next= next.length? next: $(this).parents('li').nextAll('li').find(".aabb").first();
next.focus();
next.val("")
}
})
/* document.onkeydown = function () {
console.log(event.keyCode);
return false;
}*/
$(document).ready(function() {
$("#submit").click(function() {
vardata= $("#form2").serialize()
$.get('<?php echo siteURL('/app/goods/addcodes.html').$exturl.'&ajax=json';?>',data,function(data) {
if(data.message== "ok") {
varr= confirm("保存成功")
if(r== true) {
window.location.reload();
}
}else if(data.message== "on") {
alert('条形码不能为空')
}else if(data.message== "count"){
alert('数量太大')
}else if(data.message== "oncode"){
alert('请先设置箱装条码参数')
}
},'json');
return false;
});

$(".code_size").click(function() {
varcode_size= $("#code_size").val();
varcode_start= $("#code_start").val();
varcode_end= $("#code_end").val();
if(code_start>20|| code_end>20){
alert("箱装条码设置不能大于20位")
return false;
}
if(code_size<4|| code_size>20){
alert("条码长度为5-20位")
return false;
}
$.get('<?php echo siteURL('/app/goods/ordercode.html').$exturl.'&ajax=json';?>',{code_size:code_size,code_start:code_start,code_end:code_end},function(data) {
if(data.message== "ok") {
varr= confirm("设置成功")
if(r== true) {
window.location.reload();
}
}
},'json');
return false;
});
});
/*盒装和箱装切换*/
$(document).ready(function() {
$(".case_code").click(function() {
$('.case_code_state').show();
$('.box_code_state').hide();
$('#type_code').val('case_code');
});
$(".box_code").click(function() {
$('.case_code_state').hide();
$('.box_code_state').show();
$('#type_code').val('box_code');
});
$('.box_code').click();
});
</script>
</div>




/*
* 设置条形码长度
* */
public function on_ordercode(){
$tab=$this->mongodb()->userconf;
$code_size=intval($_GET['code_size']);
$code_start=intval($_GET['code_start']);
$code_end=intval($_GET['code_end']);
$status=$tab->update(array('cnftype'=>'shopset','AppID'=>$this->appid),array('$set'=>array('code_size'=>$code_size,'code_start'=>$code_start,'code_end'=>$code_end)));
if($status){
die(json_encode(array('errors'=>1,'message'=>'ok','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
}

/*
* 添加条形码
* */
public function on_addcodes()
{
$userconf=$this->userconf;
$type_code=trim($_GET['type_code']);
$order_sn=trim($_GET['order_sn']);
$find= LogisticsTrackModel::where(array('order_sn'=>$order_sn,'AppID'=>$this->appid))->delete();
if($type_code=='case_code'){
if( !intval($userconf['code_start']) || !intval($userconf['code_end'])){
var_dump(intval($userconf['code_start']));
var_dump(intval($userconf['code_end']));
die(json_encode(array('errors'=>1,'message'=>'oncode','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
$start=$_GET['start'];
$end=$_GET['end'];
foreach($startas$gid=>$val) {
if(is_array($val)) {
foreach($valas$key=>$res) {
if(!$res|| !$end[$gid][$key]){
die(json_encode(array('errors'=>1,'message'=>'on','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
$s=substr($res,$userconf['code_start']-1,$userconf['code_end']);//78
$e=substr($end[$gid][$key],$userconf['code_start']-1,$userconf['code_end']);//80
$count=$s-$e;
if($count>100){
die(json_encode(array('errors'=>1,'message'=>'count','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
$data[$gid][$key] = [
'start'=>$res,
'end'=>$end[$gid][$key],
'order_sn'=>$order_sn,
'goodsid'=>$gid,
];
}
}
/* else{
$data[$gid] = [
'start'=>$val,
'end'=>$end[$gid],
];
}*/
}
foreach($dataas$k=>$v) {
foreach($vas$ks=>$vs) {
$this->addCode($vs);
}
}
die(json_encode(array('errors'=>1,'message'=>'ok','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
}elseif($type_code=='box_code'){
foreach($_GET['code']as$gid=>$val) {
// $unique_arr = array_unique ($val);
$data['goodsid'] = $gid;
if(is_array($val)) {
foreach($valas$key=>$item) {
if(!$item) {
die(json_encode(array('errors'=>1,'message'=>'on','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
$__data=array(
'AppID'=>$this->appid,
'order_sn'=>$order_sn,
'code'=>$item,
'goodsid'=>$data['goodsid'],
);
$track=newLogisticsTrackModel($__data);
$start=$track->save();
}
}
}
die(json_encode(array('errors'=>1,'message'=>'ok','data'=>$this->_view['list'],'pager'=>$this->_view['pager'])));
exit;
}
}

/*添加条形码*/
public function addCode($data){
$userconf=$this->userconf;
$s=substr($data['start'],$userconf['code_start']-1,$userconf['code_end']);// 123456 234
$e=substr($data['end'],$userconf['code_start']-1,$userconf['code_end']);
for($x=intval($s);$x<=intval($e);$x++) {
$__data=array(
'AppID'=>$this->appid,
'order_sn'=>$data['order_sn'],
'code'=>substr_replace($data['start'],$x,$userconf['code_start']-1,$userconf['code_end']),
'goodsid'=>$data['goodsid'],
);
$track=newLogisticsTrackModel($__data);
$start=$track->save();
}
}
0 0
原创粉丝点击