assemble.html 10.5 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单据打印</title>
    <style>
        body {
            font-size: 14px;
            color: #000;
        }

        ul, li, table, td, th, tr, a{
            margin: 0;
            padding: 0;
        }

        .main {
            width: 790px;
            margin: auto;
        }

        .title {
            font-size: 16px;
            text-align: center;
        }
        .company{
            font-size: 16px;
            text-align: center;
            font-weight: bold;
        }

        .type {
            padding: 5px 10px;
        }

        .type0 {
            float: left;
            width: 30%;
            text-align: left;
        }

        .type1 {
            float: left;
            width: 50%;
            text-align: left;
        }
        .type11 {
            float: right;
            width: 50%;
            text-align: right;
        }

        .type2 {
            float: left;
            width: 15%;
            text-align: right;
        }

        .clear {
            clear: both;
        }

        table {
            border: 1px solid #000;
            width: 100%;
            border-collapse: collapse
        }

        td {
            border: 1px solid #000;
            padding: 1px 5px;
        }

        .t1 {
            font-weight: bold;
            text-align: center;
        }

        .text-center {
            text-align: center;
        }

        .text-right {
            text-align: right;
        }
        .type3{
            float: left;
            width: 25%;
            text-align: left;
        }
        .infos{
            padding: 5px 10px;
        }
        .border1{
            position: relative;
        }
        .border1 span{
            position: absolute;
            bottom: 0;
            left: 80px;
            width: 100px;

            border-bottom: 1px solid #000;
        }
    </style>
    <style>
        /*纯CSS写法*/
        .checkbox-group input{display:none;opacity:0;}
        .checkbox-group input[type=checkbox]+label, .checkbox-group input[type=radio]+label {
            line-height: 1;
            position: relative;
            margin:2px;
        }
        .checkbox-group input[type=checkbox]+label:before, .checkbox-group input[type=radio]+label:before {
            line-height: 20px;
            display: inline-block;
            width: 18px;
            height: 18px;
            margin-right: 8px;
            content: '';
            color: #fff;
            border: 1px solid #dce4e6;
            background-color: #f3f6f8;
            border-radius: 3px;
        }
        .checkbox-group input[type=checkbox]:checked+label:before,.checkbox-group input[type=radio]:checked+label:before{
            content:'\2713';
            color:#fff;
            background-color: #31b968;
            border-radius: 3px;
            font-size:23px;
            text-align: center;
            border-color: #000000;
        }
        .noprint { display:none;}
        .print_btn,#close_btn{ display:none; }
        @page {
            margin-bottom: 0mm;
            margin-top: 0mm
        }
    </style>
</head>
<body>
<div>
    <input type="button" class="print_btn" onclick="preview(1)" value="打印">
    <a id="close_btn" href="javascript:window.opener=null;window.open('','_self');window.close();">关闭</a>
</div>
<!--startprint-->
<div>
    {volist name="list" id="vo"}
    <div class="main" {if condition='$i<sizeof($list)'}style="page-break-after: always"{/if}>
        <div class="company">{$company_name|default=''}</div>
        <div class="title">组装单</div>
        <div class="type">
            <div class="type1">单据日期:{$vo.purchase_time|date='Y-m-d',###}</div>
            <div class="type11">单据编号:{$vo.purchase_code|default=''}</div>
            <div class="clear"></div>
        </div>
        <div>
            <div>组合件:</div>
            <table>
                <tr class="t1">
                    <td width="50px">序号</td>
                    <td width="250px">商品</td>
                    <td width="50px">单位</td>
                    <td width="80px">数量</td>
                    <td width="80px">入库单位成本</td>
                    <td width="80px">入库成本</td>
                    <td width="80px">仓库</td>
                </tr>
                {foreach name="vo.purchase_info" item="info"}
                {if condition="$info.type==1"}
                <tr>
                    <td width="50px" class="text-center">1</td>
                    <td width="250px">{$info.goods.goods_name|default=''}</td>
                    <td width="50px">{$info.unit.name|default=''}</td>
                    <td width="80px" class="text-right">{$info.number|default=''}</td>
                    <td width="80px" class="text-right">{$info.unit_cost|default=''}</td>
                    <td width="80px" class="text-right">{$info.cost_money|default=''}</td>
                    <td width="80px" class="text-right">{$info.stores.name|default=''}</td>
                </tr>
                {/if}
                {/foreach}
            </table>
            <div>子件:</div>
            <table>
                <tr class="t1">
                    <td width="50px">序号</td>
                    <td width="250px">商品</td>
                    <td width="50px">单位</td>
                    <td width="80px">数量</td>
                    <td width="80px">出库单位成本</td>
                    <td width="80px">出库成本</td>
                    <td width="80px">仓库</td>
                    <td width="100px">备注</td>
                </tr>
                {php}$k=0;{/php}
                {foreach name="vo.purchase_info" item="info"}
                {if condition="$info.type==2"}
                {php}$k++;{/php}
                <tr>
                    <td width="50px" class="text-center">{$k}</td>
                    <td width="250px">{$info.goods.goods_name|default=''}</td>
                    <td width="50px">{$info.unit.name|default=''}</td>
                    <td width="80px" class="text-right">{$info.number|default=''}</td>
                    <td width="80px" class="text-right">{$info.unit_cost|default=''}</td>
                    <td width="80px" class="text-right">{$info.cost_money|default=''}</td>
                    <td width="80px" class="text-right">{$info.stores.name|default=''}</td>
                    <td width="100px;">{$info.remark|default=''}</td>
                </tr>
                {/if}
                {/foreach}
                {php}for($a=$k+1;$a<8;$a++){ {/php}
                <tr>
                    <td width="50px" class="text-center">{$a}</td>
                    <td width="250px"></td>
                    <td width="50px"></td>
                    <td width="80px" class="text-right"></td>
                    <td width="80px" class="text-right"></td>
                    <td width="80px" class="text-right"></td>
                    <td width="80px" class="text-right"></td>
                    <td width="100px"></td>
                </tr>
                {php}}{/php}
                <tr>
                    <td colspan="3" class="text-right">合计:</td>
                    <td width="80px" class="text-right">{$vo.print_number|default=''}</td>
                    <td width="80px" class="text-right"></td>
                    <td width="80px" class="text-right">{$vo.print_money|default=''}</td>
                    <td width="80px" class="text-right"></td>
                    <td width="100px"></td>
                </tr>
            </table>
        </div>
        <div class="infos">组装费用:{$vo.money|default=''}</div>
        <div class="infos">备注:{$vo.note|default=''}</div>
        <div class="type">
            <div class="type3">制单人:{$vo.preparation.username|default=''}</div>
            <div class="clear"></div>
        </div>
    </div>
    {/volist}
</div>
<!--endprint-->
<script>
    bdhtml=window.document.body.innerHTML;
    // 打印开始的标志
    sprnstr="<!--startprint-->";
    // 打印结束的标志
    eprnstr="<!--endprint-->";
    // 从打印开始的位置截取到末尾
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
    // 从开始截取到打印结束的位置
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
    // 替换html
    window.document.body.innerHTML=prnhtml;
    // 打印
    HKEY_Root="HKEY_CURRENT_USER";
    HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    try{
        var Wsh=new ActiveXObject("WScript.Shell");
        HKEY_Key="header";
        //设置页眉(为空) 根据你自己要设置的填入
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
        HKEY_Key="footer";
        //设置页脚(为空) 根据你自己要设置的填入
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
        HKEY_Key="margin_bottom";
        //设置下页边距(0) 根据你自己要设置的填入
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
        HKEY_Key="margin_left";
        //设置左页边距(0) 根据你自己要设置的填入
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"1");
        HKEY_Key="margin_right";
        //设置右页边距(0)
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");
        HKEY_Key="margin_top";
        //设置上页边距(8)
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"1");
    }catch(e){}
    window.print();
    window.document.body.innerHTML = bdhtml;
    var beforePrint = function() {
        //window.print监听打印确认取消
        console.log('Functionality to run before printing.');
    };
    var afterPrint = function() {
        console.log('Functionality to run after printing');
        document.getElementById('close_btn').click();
    };
    if (window.matchMedia) {
        var mediaQueryList = window.matchMedia('print');
        mediaQueryList.addListener(function(mql) {
            if (mql.matches) {
                beforePrint();
            } else {
                afterPrint();
            }
        });
    }
    window.onbeforeprint = beforePrint;
    window.onafterprint = afterPrint;
</script>
</body>
</html>