<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <?php $shoname_name = D('Home/Front')->get_config_by_name('shoname'); ?>
  <title><?php echo $shoname; ?></title>
  <link rel="shortcut icon" href="" />
        
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">

  <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->

  <link href="./resource/css/bootstrap.min.css?v=201903260001" rel="stylesheet">
  <link href="./resource/css/common.css?v=201903260001" rel="stylesheet">
  <script type="text/javascript">
      window.sysinfo = {
        <?php if (!empty($_W['uniacid']) ){ ?>'uniacid': '{$_W['uniacid']}',<?php } ?>
        <?php if( !empty($_W['acid'])  ){ ?>'acid': '{$_W['acid']}',<?php } ?>
        <?php if (!empty($_W['openid']) ) { ?>'openid': '{$_W['openid']}',<?php } ?>
        <?php if( !empty($_W['uid']) ) {  ?>'uid': '{$_W['uid']}',<?php } ?>
        'isfounder': <?php if (!empty($_W['isfounder']) ) { ?>1<?php  }else{  ?>0<?php } ?>,
        'siteroot': '{$_W['siteroot']}',
        'siteurl': '{$_W['siteurl']}',
        'attachurl': '{$_W['attachurl']}',
        'attachurl_local': '{$_W['attachurl_local']}',
        'attachurl_remote': '{$_W['attachurl_remote']}',
        'module': {'url' : '<?php if( defined('MODULE_URL') ) { ?>{MODULE_URL}<?php } ?>', 'name' : '<?php if (defined('IN_MODULE') ) { ?>{IN_MODULE}<?php } ?>'},
        'cookie': {'pre': ''},
        'account': {:json_encode($_W['account'])},
      };
  </script>
        
  <script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="./resource/js/lib/bootstrap.min.js"></script>
  <script type="text/javascript" src="./resource/js/app/util.js?v=201903260001"></script>
  <script type="text/javascript" src="./resource/js/app/common.min.js?v=201903260001"></script>
  <script type="text/javascript" src="./resource/js/require.js?v=201903260001"></script>
  <script type="text/javascript" src="./resource/js/lib/jquery.nice-select.js?v=201903260001"></script>
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  <link href="/static/css/snailfish.css" rel="stylesheet">
  <style>
	.daterangepicker select.ampmselect, .daterangepicker select.hourselect, .daterangepicker select.minuteselect {
		width: auto!important;
	}
  </style>
</head>
<body layadmin-themealias="default">

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header layui-elem-quote">当前位置：<span class="line-text">生成配送单</span></div>
        <div class="layui-card-body" style="padding:15px;">
            <div class="page-content">
			<span class="line-text">说明：此处所有的生成，只针对待发货的订单。如果要使用这个流程，请勿在后台--“订单”，把待发货的订单给变更为已发货，也不能在后台--“订单设置”里设置自动发货，这将导致这些订单永远不会统计在配送单中。其它细节参考帮助文档，搜索 “常规发货”。</span>
			<br><br>
                <form action="" method="get" class="form-horizontal form-search layui-form" role="form">
            		<input type="hidden" name="c" value="delivery" />
                    <input type="hidden" name="a" value="get_delivery_list" />
                    
                    <div class="page-toolbar">
                        <div class="layui-form-item">
        					<span class="layui-input-inline">
        						<select name='searchtime' class='form-control' style="width:100px;padding:0 5px;" id="searchtime">
        							<option value=''>不按时间</option>
        							<option value='pay' <?php if( $gpc['searchtime']=='pay'){ ?>selected<?php } ?>>付款时间</option>
									<option value='create' <?php if( $gpc['searchtime']=='create' ){ ?>selected<?php } ?>>下单时间</option>
        						</select>
        					</span>
        					<span class="layui-input-inline" style="width:280px;">
        						{:tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)),true);}
        					</span>
        					<span class="layui-input-inline">
        						<select name="line_id" class='form-control select2' style="width:200px;" data-placeholder="配送线路">
        							<option value="-1" <?php if( empty($gpc['line_id'])){ ?>selected<?php } ?> >配送线路</option>
        							<?php foreach($line_list as $line){ ?>
        							<option value="<?php echo $line['id']; ?>" <?php if( $gpc['line_id']== $line['id'] ){ ?>selected<?php } ?> ><?php echo $line['name']; ?></option>
        							<?php } ?>
        						</select>
        					</span>
                            <div class="layui-input-inline">
        					   <input type="text" class="layui-input" name='keyword' value="{$gpc['keyword']}" placeholder="输入店铺名称然后回车">
                            </div>
                            <span class="layui-input-inline">
                                <button class="btn btn-primary" type="submit"> 搜索</button>
                            </span>
                        </div>
                    </div>
                </form>
	
                <form action="" method="post" class="layui-form" role="form" >
                    <div class="row">
                        <div class="col-md-12">
                            <div class="page-table-header">
                                <input type='checkbox' type='checkbox' name="checkall" lay-skin="primary" lay-filter="checkboxall" />
                                <span class="pull-right">
									<a  class='btn layui-btn  layui-btn-sm' href="{:U('delivery/auto_get_delivery_list')}" >
										<span data-toggle="tooltip" data-placement="top" title="" data-original-title="打印配送单">
											一键生成所有清单
										</span>
                					</a>
            					</span>
								<div class="btn-group">
                                    <button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-remove' data-confirm="确认要批量生成吗，请确认商品数量是否正确?" data-href="{:U('delivery/sub_delivery_list',   array('endtime' => $endtime,'starttime' => $starttime,'searchtime' => $gpc['searchtime'] ) )}">
                                        <i class='icow icow-shanchu1'></i> 批量生成清单
            						</button>
                                </div>
                            </div>
                            <table class="table table-responsive">
                                <thead>
                                    <tr>
                						<th style="width:25px;"></th>
                						<th style="width:100px;text-align:center;">社区ID</th>
                						<th style="">社区名称</th>
                						<th style="width: 300px;">配送线路</th>
                						<th style="width: 100px;">商品总数</th>
                						<th style="width: 200px;">操作</th>
                					</tr>
                                </thead>
                                <tbody>
                                    <?php foreach( $list as  $item  ){ ?>
                                    <tr>
                    					<td style="width:25px;">
                    						<input type='checkbox' value="{$item['head_id']}" value="{$row['id']}" name="item_checkbox" lay-skin="primary"/>
                    					</td>
                    					<td style="width:100px;text-align:center;">
                    						{$item['head_id']}
                    					</td>
                    					<td>
                    						{$item['community_name']}
                    					</td>
                    					<td>
                    						{$item['line_name']}
                    					</td>
                    					<td>
                    						{$item['goods_count']}
                    					</td>
                    					<td style="overflow:visible;position:relative">
                    						<a class='layui-btn layui-btn-primary layui-btn-xs create_list' href="javascript:;" data-href="{:U('delivery/sub_delivery_list', array('head_id' => $item['head_id'],'endtime' => $endtime,'starttime' => $starttime,'searchtime' => $gpc['searchtime'] ))}" >
                    							<span data-toggle="tooltip" data-placement="top" title="" data-original-title="生成清单">
                    								生成清单
                    							</span>
                    						</a>
                    						<a class='layui-btn layui-btn-primary layui-btn-xs head_ordergoods_detail' href="javascript:;" data-href="{:U('delivery/head_ordergoods_detail', array('head_id' => $item['head_id'],'endtime' => $endtime,'starttime' => $starttime,'searchtime' => $gpc['searchtime'],'ok'=>1 ))}" >
                    							<span data-toggle="tooltip" data-placement="top" title="" data-original-title="商品详情">
                    								<i class="icow icow-bianji2"></i>商品详情
                    							</span>
                    						</a>
                    					</td>
                                    </tr>
                                    <?php } ?>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td colspan="3" style="padding-left: 0;">
                							<div class="page-table-header">
                								<input type="checkbox" type='checkbox' name="checkall" lay-skin="primary" lay-filter="checkboxall">
                								<div class="btn-group">
                									<button class="btn btn-default btn-sm btn-operation" type="button" data-toggle='batch-remove' data-confirm="确认要批量生成吗，请确认商品数量是否正确?" data-href="{php echo shopUrl('delivery/sub_delivery_list', array('endtime' => $endtime,'starttime' => $starttime,'searchtime' => $_GPC['searchtime']) )}">
                										<i class='icow icow-shanchu1'></i> 批量生成清单
                									</button>
                								</div>
                							</div>
                                        </td>
                                        <td colspan="3" style="text-align: right">
                                            {$pager}
                                        </td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<script>
var layer = layui.layer;
var $;
var can_sb = true;

layui.use(['jquery', 'layer', 'form'], function(){ 
    $ = layui.$;
    var form = layui.form;

    $('.create_list').click(function(){
		if(!can_sb)
		{
			return false;
		}
		can_sb = false; 
        var s_url = $(this).attr('data-href');
        $.ajax({
            url:s_url,
            type:'post',
            dataType:'json',
            success:function(info){
            
                if(info.status == 0)
                {
                    layer.msg(info.result.message,{icon: 1,time: 2000});
					can_sb = true;
                }else if(info.status == 1){
                    var go_url = location.href;
                    if( info.result.hasOwnProperty("url") )
                    {
                        go_url = info.result.url;
                    }
                    
                    layer.msg('生成成功',{time: 1000,
                        end:function(){
                            location.href = info.result.url;
                        }
                    }); 
                }
            }
        })
    })
  
    $('.deldom').click(function(){
        var s_url = $(this).attr('data-href');
        layer.confirm($(this).attr('data-confirm'), function(index){
            $.ajax({
                url:s_url,
                type:'post',
                dataType:'json',
                success:function(info){
                
                    if(info.status == 0)
                    {
                        layer.msg(info.result.message,{icon: 1,time: 2000});
                    }else if(info.status == 1){
                        var go_url = location.href;
                        if( info.result.hasOwnProperty("url") )
                        {
                            go_url = info.result.url;
                        }
                        
                        layer.msg('操作成功',{time: 1000,
                            end:function(){
                                location.href = info.result.url;
                            }
                        }); 
                    }
                }
            })
        }); 
    })
    
    $('.btn-operation').click(function(){
    	if(!can_sb)
		{
			return false;
		}
		can_sb = false; 
		
        var ids_arr = [];
        var obj = $(this);
        var s_toggle = $(this).attr('data-toggle');
        var s_url = $(this).attr('data-href');
        
        
        $("input[name=item_checkbox]").each(function() {
            
            if( $(this).prop('checked') )
            {
                ids_arr.push( $(this).val() );
            }
        })
        if(ids_arr.length < 1)
        {
            layer.msg('请选择要操作的内容');
            can_sb = true;
        }else{
            var can_sub = true;
            if( s_toggle == 'batch-remove' )
            {
                var nlb_can = true;
                
                layer.confirm($(obj).attr('data-confirm'), function(index){
					if(nlb_can)
					{
						nlb_can = false;
						$.ajax({
							url:s_url,
							type:'post',
							dataType:'json',
							data:{ids:ids_arr},
							success:function(info){
							
								if(info.status == 0)
								{
									layer.msg(info.result.message,{icon: 1,time: 2000});
									can_sb = true;
								}else if(info.status == 1){
									var go_url = location.href;
									if( info.result.hasOwnProperty("url") )
									{
										go_url = info.result.url;
									}
									
									layer.msg('操作成功',{time: 1000,
										end:function(){
											location.href = info.result.url;
										}
									}); 
								}
							}
						})
						
					}
                     
                }, function(index){
					console.log('cancle confirm');
					can_sb = true;
				}); 
            }else{
                $.ajax({
                    url:s_url,
                    type:'post',
                    dataType:'json',
                    data:{ids:ids_arr},
                    success:function(info){
                    
                        if(info.status == 0)
                        {
                            layer.msg(info.result.message,{icon: 1,time: 2000});
                            can_sb = true;
                        }else if(info.status == 1){
                            var go_url = location.href;
                            if( info.result.hasOwnProperty("url") )
                            {
                                go_url = info.result.url;
                            }
                            
                            layer.msg('操作成功',{time: 1000,
                                end:function(){
                                    location.href = info.result.url;
                                }
                            }); 
                        }
                    }
                })
            }
        }
    })
  
    form.on('switch(statewsitch)', function(data){
      
      var s_url = $(this).attr('data-href')
      
      var s_value = 1;
      if(data.elem.checked)
      {
        s_value = 1;
      }else{
        s_value = 0;
      }
      
      $.ajax({
            url:s_url,
            type:'post',
            dataType:'json',
            data:{value:s_value},
            success:function(info){
            
                if(info.status == 0)
                {
                    layer.msg(info.result.message,{icon: 1,time: 2000});
                }else if(info.status == 1){
                    var go_url = location.href;
                    if( info.result.hasOwnProperty("url") )
                    {
                        go_url = info.result.url;
                    }
                    
                    layer.msg('操作成功',{time: 1000,
                        end:function(){
                            location.href = info.result.url;
                        }
                    }); 
                }
            }
        })
    });

    form.on('checkbox(checkboxall)', function(data){
      if(data.elem.checked)
      {
        $("input[name=item_checkbox]").each(function() {
            $(this).prop("checked", true);
        });
        $("input[name=checkall]").each(function() {
            $(this).prop("checked", true);
        });
        
      }else{
        $("input[name=item_checkbox]").each(function() {
            $(this).prop("checked", false);
        });
        $("input[name=checkall]").each(function() {
            $(this).prop("checked", false);
        });
      }
      
      form.render('checkbox');
    });
  
    //监听提交
    form.on('submit(formDemo)', function(data){
        $.ajax({
            url: data.form.action,
            type: data.form.method,
            data: data.field,
            dataType:'json',
            success: function (info) {
              
                if(info.status == 0)
                {
                    layer.msg(info.result.message,{icon: 1,time: 2000});
                }else if(info.status == 1){
                    var go_url = location.href;
                    if( info.result.hasOwnProperty("url") )
                    {
                        go_url = info.result.url;
                    }
                    
                    layer.msg('操作成功',{time: 1000,
                        end:function(){
                            location.href = info.result.url;
                        }
                    }); 
                }
            }
        });
        return false;
    });
})

</script>
<script>
var ajax_url = "";
$(function(){
    $(".head_ordergoods_detail").click(function () {
        var s_url = $(this).attr('data-href');
        ajax_url = s_url;
        $.ajax({
                url:s_url,
                type:"get",
                success:function(shtml){
					layer.open({
					  type: 1, 
					  area: '50%',
					  content: shtml //这里content是一个普通的String
					});
				   
                }   
        })
    });

    var sub_url = "{:U('delivery/sub_delivery_list')}";
    $(document).delegate(".modal-footer .btn-primary","click",function(){
        var s_data = $('#ajaxModal form').serialize();
        $.ajax({
            url: sub_url,
            type:'post',
            dataType:'json',
            data: s_data,
            success:function(info){
                if(info.status == 0)
                {
                    layer.msg(info.result.message,{icon: 1,time: 2000});
                }else if(info.status == 1){
                    var go_url = location.href;
                    if( info.result.hasOwnProperty("url") )
                    {
                        go_url = info.result.url;
                    }
                    
                    layer.msg('操作成功',{time: 1000,
                        end:function(){
                            location.href = info.result.url;
                        }
                    }); 
                }
            }
        })
        return false;
    })
    
    
})
</script>
<div id="ajaxModal" class="modal fade" style="display: none;"></div>
</body>
</html>