<!DOCTYPE html>
<html>
<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>
<body>

<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">
                        <table class="layui-table" id="print_total">
                        </table>
                        <table class="layui-table" id="print_body">
                        </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.$
            ,utils = layui.utils
            ,admin = layui.admin;
        var cols = [];
        cols.push('<tr>\n' +
            '                        <td id="no" class="cell">单号</td>\n' +
            '                        <td id="supplier_text" class="cell">供应商</td>\n' +
            '                    </tr>');
        if (utils.isHasPermissions('material.view_material_cost')) {
            cols.push('<tr>\n' +
                '                        <td id="total_count" class="cell">合计数量</td>\n' +
                '                        <td id="total_amount" class="cell">合计金额</td>\n' +
                '                    </tr>' +
                '<tr>\n' +
                '                        <td id="create_user_text" class="cell">创建人</td>\n' +
                '                        <td id="create_time" class="cell">创建时间</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="status_text" class="cell">审核状态</td>\n' +
                '                        <td id="check_user_text" class="cell">审核人</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="check_time" class="cell">审核时间</td>\n' +
                '                        <td id="warehouse_text" class="cell">仓别</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="purchase_order_no" class="cell">合同号</td>\n' +
                '                        <td id="notes" class="cell">备注</td>\n' +
                '                    </tr>');
        }else {
            cols.push('<tr>\n' +
                '                        <td id="total_count" class="cell">合计数量</td>\n' +
                '                        <td id="create_user_text" class="cell">创建人</td>\n' +
                '                    </tr>' +
                '<tr>\n' +
                '                        <td id="status_text" class="cell">审核状态</td>\n' +
                '                        <td id="create_time" class="cell">创建时间</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="check_time" class="cell">审核时间</td>\n' +
                '                        <td id="check_user_text" class="cell">审核人</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="warehouse_text" class="cell">仓别</td>\n' +
                '                        <td id="purchase_order_no" class="cell">合同号</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="notes" class="cell" colspan="2">备注</td>\n' +
                '                    </tr>');
        }
        $('#print_total').html(cols);
        var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
        $('.cell').each(function (index, element) {
            element.innerHTML += '：' + (data[element.id]||'')
        });

        admin.req({
            url: '/purchase/godownentry/detail/?id='+data.id
            ,done: function(data){
                var cols_body = '';
                cols_body += '<tr><td>序号</td>\n' +
                    '                        <td>原料名称</td>\n' +
                    '                        <td>原料代码</td>\n' +
                    '                        <td align="right">数量</td>';
                if (utils.isHasPermissions('material.view_material_cost')) {
                    cols_body += ' <td align="right">单价</td>\n' +
                        '                        <td align="right">金额</td>'+
                        '                        <td align="right">发票金额</td>';
                }
                cols_body += ' <td>单位</td>\n' +
                        ' <td>备注</td>\n' +
                    '                    </tr>' +
                    '<tr id="tr_item_total">\n' +
                    '                    </tr>';
                $('#print_body').html(cols_body);
                var items = data.data.items_data;
                for(var n in items){
                    var cols_data = '';
                    cols_data += "<tr>\n" +
                        "                        <td>"+(parseInt(n)+1)+"</td>\n" +
                        "                        <td>"+items[n].product_base_name+"</td>\n" +
                        "                        <td>"+items[n].product_base_model+"</td>\n" +
                        "                        <td align=\"right\">"+items[n].count+"</td>\n";
                    if(utils.isHasPermissions('material.view_material_cost')){
                        cols_data += "                        <td align=\"right\">"+items[n].price+"</td>\n" +
                            "                        <td align=\"right\">"+items[n].amount+"</td>\n"+
                            "                        <td align=\"right\">"+items[n].invoice_amount+"</td>\n"
                    }
                    cols_data +="                        <td>"+items[n].unit+"</td>\n" +
                            "                        <td>"+items[n].notes+"</td>\n" +
                        "                    </tr>";
                    $('#tr_item_total').before(cols_data);
                }
            }
        });
    });
</script>
</body>
</html>

