<!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>
<link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
<link href="/static/css/snailfish.css" rel="stylesheet">
<style>
    .content{
        display:none;
        width:200px;
        height:200px;
        border-radius:10px;
        padding:20px;
        position:relative;
        top:15px;
        left:460px;
        background-color:FFFFFF;
        border:1px solid;
    }
    .layadmin-name{background-color: #009688;
        color: #fff;
        width: 90px;
        text-align: center;
        height: 22px;}

</style>
</head>
<body layadmin-themealias="default">

<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header layui-elem-quote">当前位置：打印机设置</span></div>
		<div class="layui-card-body" style="padding:15px;">
			<form action="" method="post" class="layui-form" lay-filter="component-layui-form-item">
                <?php if($data['open_feier_print'] != 0){ ?>
                <div class="layui-form-item">
                    <label class="layui-form-label">旧版打印机设置</label>
                    <div class="layui-input-block"  style="width: 50%;">
						<div id="share">
                        <input type="checkbox"  lay-skin="primary" id="feierprint"  name="data[open_feier_print]" class="form-control valid" <?php if( !empty($data) && $data['open_feier_print'] != 0 ){ ?>checked<?php } ?> value="<?php echo $data['open_feier_print'];?>" title="继续使用旧版本设置" ></input>
                        </div>
						<span style="color:red;">（此处勾选，又设置了新的小票打印机，可能导致打印多份）</span>
						<span class='help-block'>继续使用原有的打印机设置，旧版打印机与“默认订单打印机”一起打印小票，也可以关闭旧版打印机设置使用新版本“默认打印机”</span>
						
						<div id="share_div" <?php if( !empty($data) && $data['open_feier_print'] != 0 ){ ?> style="display:none;"<?php }else{ ?> style="display:block;"<?php } ?>>
                        <?php if($data['open_feier_print'] == 1){ ?>
                            <div class="input-group" style="margin: 10px 0;">飞鹅打印机</div>
                            <div class="input-group fixsingle-input-group">
                                <div class="input-group-addon"><b>sn:</b></div>
                                <input type="text" name="data[feier_print_sn]" class="form-control" value="{$data['feier_print_sn']}" />
                                <div class="input-group-addon"><b>key:</b></div>
                                <input type="text" name="data[feier_print_key]" class="form-control" value="{$data['feier_print_key']}" />
                                <div class="input-group-addon"><b>打印联数：</b></div>
                                <input type="text" name="data[feier_print_lian]" class="form-control" value="<?php echo !isset($data['feier_print_lian'])  ? 1 : $data['feier_print_lian']; ?>" />

                            </div>
                            <span class='help-block'>支持飞鹅打印机 (sn,key在机子底部)，打印联数最小为1</span>
                        <?php }else if($data['open_feier_print'] == 2){ ?>
                            <div class="input-group" style="margin: 10px 0;">易联云打印机</div>
                            <div class="input-group fixsingle-input-group">
                                <div class="input-group-addon"><b>应用id:</b></div>
                                <input type="text" name="data[yilian_client_id]" class="form-control" value="{$data['yilian_client_id']}" />
                                <div class="input-group-addon"><b>应用密钥:</b></div>
                                <input type="text" name="data[yilian_client_key]" class="form-control" value="{$data['yilian_client_key']}" />
                            </div>
                            <div class="input-group fixsingle-input-group">
                                <div class="input-group-addon"><b>打印机终端号:</b></div>
                                <input type="text" name="data[yilian_machine_code]" class="form-control" value="{$data['yilian_machine_code']}" />
                                <div class="input-group-addon"><b>终端密钥:</b></div>
                                <input type="text" name="data[yilian_msign]" class="form-control" value="{$data['yilian_msign']}" />
                                <div class="input-group-addon"><b>打印联数：</b></div>
                                <input type="text" name="data[yilian_print_lian]" class="form-control" value="<?php echo !isset($data['yilian_print_lian']) ? 1 : $data['yilian_print_lian']; ?>" />
                            </div>
                            <span class='help-block'>支持易联云K4、K5、K6打印机 (打印机终端号,终端密钥在机子底部,开发者中心应用类型选择： 自有型应用)，没有开发者账号<a href="https://dev.yilianyun.net/" target="_blank">请点击申请</a></span>
                        <?php } ?>
						</div>
                    </div>
                </div>
                <?php } ?>
                <div class="layui-form-item">
                    <label class="layui-form-label">默认订单打印机</label>
                    <div class="layui-input-block"  style="width: 50%;">
                        <div class="input-group " style="margin: 0;">
                            <input type="text" disabled value="" class="form-control valid" name="" placeholder="" id="printer_id">
                            <span class="input-group-btn">
                                <span data-input="#printer_id" id="chose_printer"  class="btn btn-default">选择打印机</span>
                            </span>
                            <span class='help-block' style="display: table-row;">选择打印机进行订单打印，支持多台打印机一起打印</span>
                        </div>
                        <?php if(!empty($printer_list)){ ?>
                        <?php foreach( $printer_list as $item ){ ?>
                        <div class="input-group mult_choose_printerid" data-printerid="{$item['id']}" style="border-radius: 0;float: left;margin: 10px;margin-left:0px;width: 20%;">
                            <div class="layadmin-text-center choose_user">
                                <div class="layadmin-name" style="">{$item['printer_name']}</div>
                                <button type="button" class="layui-btn layui-btn-sm" onclick="cancle_bind(this)">
                                    <i class="layui-icon"></i>
                                </button>
                            </div>
                        </div>
                        <?php }} ?>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">订单打印方式</label>
                    <div class="layui-input-block ">
                        <input type="checkbox" lay-skin="primary" name="data[is_print_cancleorder]" class="form-control valid" <?php if( !empty($data) && $data['is_print_cancleorder'] ==1 ){ ?>checked<?php } ?> value="1" title="取消订单打印" />
                        <input type="checkbox" lay-skin="primary" name="data[is_print_admin_cancleorder]" class="form-control valid" <?php if( !empty($data) && $data['is_print_admin_cancleorder'] ==1 ){ ?>checked<?php } ?> value="1" title="后台整单立即退款打印" />
                        <input type="checkbox" lay-skin="primary" name="data[is_print_dansupply_order]" class="form-control valid" <?php if( !empty($data) && $data['is_print_dansupply_order'] ==1 ){ ?>checked<?php } ?> value="1" title="独立供应商订单打印" />
                        <input type="checkbox" lay-skin="primary" name="data[is_print_member_note]" class="form-control valid" <?php if( !empty($data) && $data['is_print_member_note'] ==1 ){ ?>checked<?php } ?> value="1" title="小票打印内容包含“会员详情-备注信息”" />
                        <input type="checkbox" lay-skin="primary" name="data[is_print_order_note]" class="form-control valid" <?php if( !empty($data) && $data['is_print_order_note'] ==1 ){ ?>checked<?php } ?> value="1" title="小票打印内容包含“订单提交页自定义备注信息”" />

                        <br/>
                        <div class="layui-form-mid layui-word-aux">
                            默认付款后自动打印
                        </div>
                    </div>
                </div>
				<div class="layui-form-item">
					<label class="layui-form-label"> </label>
					<div class="layui-input-block">
						<input type="submit" value="提交" lay-submit lay-filter="formDemo" class="btn btn-primary"  />
					</div>
				</div>
			</form>
		</div>
</div>
</div>

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

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

})

function cancle_bind(obj,sdiv)
{
    $('#'+sdiv).val('');
    $(obj).parent().parent().remove();
}
//由于模块都一次性加载，因此不用执行 layui.use() 来加载对应模块，直接使用即可：
var layer = layui.layer;
var $;

var cur_open_div;

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

    $('#chose_printer').click(function(){
        cur_open_div = $(this).attr('data-input');
        $.post("{:U('printer/query_printer', array('template' => 'mult', 'unselect_printerid' => $id))}", {}, function(shtml){
            layer.open({
                type: 1,
                area: '930px',
                content: shtml //注意，如果str是object，那么需要字符拼接。
            });
        });
    })
	
	$('#share').click(function(){
		var isChecked = $('#feierprint').prop('checked');
		if (isChecked == 0) {
           $('#share_div').show();
      } else {
           $('#share_div').hide();
      }
	})



    //监听提交
    form.on('submit(formDemo)', function(data){
    var loadingIndex = layer.load();
    var printer_ar = [];
    var printer_str = '';
    $('.mult_choose_printerid').each(function(){
        printer_ar.push( $(this).attr('data-printerid') );
    })
    printer_str = printer_ar.join(',');

    data.field.is_printer_list = printer_str;
        console.log(data.field);
     $.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});
                layer.close(loadingIndex);
            }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>  
</body>