<!DOCTYPE html>
<html style="height: 100%;min-height: 100%;">
<head>
    <meta charset="utf-8">
    <title>　</title>
    <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/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<style>
    h3, td, th{color: #000000}
    .layui-table td, .layui-table th {border-color: #000000;height: 1px}
</style>
<body style="background-color: #fff;height: 100%;min-height: 100%;">

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">

                    <div id="print_div">
                        <h3 align="center" style="font-weight: bold;letter-spacing:8px;"><span id="company"></span></br>盘存单</h3>
                        <table class="layui-table" id="table_total">
                        </table>
                        <table class="layui-table" id="table_body">
                        </table>
                        <table class="table-embed" border='0' width='100%' height="50px">
                            <tr style="height: 80px;">
                                <td align="center">制单人签字：__________</td>
                                <td align="center">审核人签字：__________</td>
                                <td align="center">财务签字：__________</td>
                                <td align="center">总经理签字：__________</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'utils'], function(){
        var $ = layui.$
        var utils = layui.utils;
        var admin = layui.admin;
        var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
        var permission = '';
        if (data.product_type == 0){
            permission = 'material.view_material_cost'
        }else if (data.product_type == 1){
            permission = 'material.view_consumable_cost'
        } else if(data.product_type == 2){
            permission = 'goods.view_goods_cost'
        }
        var status = utils.isHasPermissions(permission);
        var cols_total = '';
        cols_total += '<tr>\n' +
            '                        <td id="no" class="cell">单号</td>\n' +
            '                        <td id="create_time" class="cell">提交时间</td>\n' +
            '                        <td id="check_status_text" class="cell">状态</td>\n' +
            '                    </tr>\n' +
            '                    <tr>\n' +
            '                        <td id="type_text" class="cell">类别</td>\n' +
            '                        <td id="check_user_text" class="cell">审核人</td>\n' +
            '                        <td id="check_time" class="cell">审核时间</td>\n' +
            '                    </tr>\n' +
            '                    <tr>\n' +
            '                        <td id="total_count" class="cell">合计数量</td>';
        if (status) {
            cols_total += '<td id="total_amount" class="cell">合计金额</td>\n' +
                '                        <td id="notes" class="cell">备注</td>\n' +
                '                    </tr>';
        }else{
            cols_total += '<td id="notes" class="cell" colspan="2">备注</td>\n' +
                '                    </tr>';
        }
        $('#table_total').html(cols_total);
        $('.cell').each(function (index, element) {
            element.innerHTML += '：' + (data[element.id]||'')
        });

        admin.req({
            url: '/material/inventory/detail/?id='+data.id
            ,done: function(data){
                var company = data.data.company;
                var items_data = data.data.items_data;
                var count = 0
                    ,amount = 0;
                var cols = '';
                cols += '<tr>\n' +
                    '                        <td>产品</td>\n' +
                    '                        <td>代码</td>\n' +
                    '                        <td>仓别</td>\n' +
                    '                        <td>入库单号</td>\n' +
                    '                        <td>备注</td>\n' +
                    '                        <td align="right" width="70">数量</td>\n';
                if (status) {
                    cols += '<td align="right" width="70">单价</td>\n' +
                        '                        <td align="right" width="70">合计</td>\n' +
                        '                        </tr>\n' +
                        '<tr id="tr_total">\n' +
                        '                        <td colspan="5" align="right">合计：</td>\n' +
                        '                        <td align="right" id="td_count"></td>\n' +
                        '                        <td></td>\n' +
                        '                        <td align="right" id="td_amount"></td>\n' +
                        '                    </tr>';
                }else{
                    cols += '                    </tr>' +
                        '<tr id="tr_total">\n' +
                        '                        <td colspan="5" align="right">合计：</td>\n' +
                        '                        <td align="right" id="td_count"></td>\n' +
                        '                    </tr>';
                }
                $('#table_body').html(cols);
                for(var n in items_data){
                    count += parseFloat(items_data[n].count);
                    amount += parseFloat(items_data[n].amount);
                    var cols_data = '';
                    cols_data += "<tr>\n" +
                        "                        <td>"+items_data[n].product_name+"</td>\n" +
                        "                        <td>"+items_data[n].product_model+"</td>\n" +
                        "                        <td>"+items_data[n].warehouse_text+"</td>\n" +
                        "                        <td>"+items_data[n].entry_no+"</td>\n" +
                        "                        <td>"+items_data[n].notes+"</td>\n" +
                        "                        <td align=\"right\">"+items_data[n].count+"</td>\n";
                    if (status) {
                        cols_data += "                        <td align=\"right\">"+items_data[n].price+"</td>\n" +

                            "                        <td align=\"right\">"+items_data[n].amount+"</td>\n";
                    }
                    cols_data += "                    </tr>";
                    $('#tr_total').before(cols_data);
                }
                $('#td_count').html(parseFloat(count).toFixed(2));
                $('#company').html(company);
                if (status) {
                    $('#td_amount').html(parseFloat(amount).toFixed(4));
                }
            }
        });
    });
    parent.layui.submitChild = function () {
        window.scrollTo(0,0);
        doPrint();
        parent.layui.onSubmitChild();
    };
    function doPrint() {
        var $ = layui.$;
        document.body.innerHTML = $('#print_div').html();
        window.print();
    }
</script>
</body>
</html>

