<!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">
                            <tr id="tr_item_total">
                            </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.$
            ,utils = layui.utils
            ,admin = layui.admin;
        var cols = [];
        cols.push('<tr>\n' +
            '                        <td id="no" class="cell">单号</td>\n' +
            '                        <td id="product_type_text" class="cell">产品类型</td>\n' +
            '                    </tr>');
        if (utils.isHasPermissions('material.view_consumable_cost')) {
            cols.push('<tr>\n' +
                '                        <td id="total_count" class="cell">合计数量</td>\n' +
                '                        <td id="total_cost" class="cell">合计成本</td>\n' +
                '                    </tr>\n' +
                '                    <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="receiver_text" class="cell">领用人</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="goods_text" class="cell">成品</td>\n' +
                '                        <td id="warehouse_text" class="cell">仓别</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n' +
                '                        <td id="notes" class="cell" colspan="2">备注</td>\n' +
                '                    </tr>');
        }else{
        cols.push('<tr>\n' +
            '                        <td id="total_count" class="cell">合计数量</td>\n' +
            '                        <td id="goods_text" class="cell">成品</td>\n' +
            '                    </tr>\n' +
            '                    <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="receiver_text" class="cell">领用人</td>\n' +
            '                    </tr>\n' +
            '                    <tr>\n' +
            '                        <td id="warehouse_text" class="cell">仓别</td>\n' +
            '                        <td id="notes" class="cell">备注</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: '/material/deliver/detail/?id='+data.id
            ,done: function(data){
                var items = data.data.items_data;
                var cols_body = '';
                cols_body += '<tr>\n' +
                    '                        <td>序号</td>\n' +
                    '                        <td>名称</td>\n' +
                    '                        <td>代码</td>\n' +
                    '                        <td>单位</td>\n' +
                    '                        <td>入库单号</td>\n' +
                    '                        <td align="right">数量</td>';
                if (utils.isHasPermissions('material.view_consumable_cost')) {
                    cols_body += '<td align="right">成本合计</td>';
                }
                cols_body += '<td align="right">库存数量</td>\n' +
                        '<td>备注</td>\n' +
                    '                    </tr>';
                $('#tr_item_total').before(cols_body);
                for(var n in items){
                    var cols_data = '';
                    var m = parseInt(n) + 1;
                    cols_data +="<tr>\n" +
                        "                        <td>"+m+"</td>\n" +
                        "                        <td>"+items[n].name+"</td>\n" +
                        "                        <td>"+items[n].model+"</td>\n" +
                        "                        <td>"+items[n].unit+"</td>\n" +
                        "                        <td>"+items[n].no+"</td>\n" +
                        "                        <td align=\"right\">"+items[n].count+"</td>\n";
                    if(utils.isHasPermissions('material.view_consumable_cost')){
                        cols_data += "                        <td align=\"right\">"+items[n].total_cost+"</td>\n";
                    }
                    cols_data +="                        <td align=\"right\">"+items[n].warehouse_stock_count+"</td>\n" +
                            "                        <td>"+items[n].notes+"</td>\n" +
                        "                    </tr>";
                    $('#tr_item_total').before(cols_data);
                }
            }
        });
    });
</script>
</body>
</html>

