<!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="table_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.$;
        var utils = layui.utils;
        var admin = layui.admin;
        var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
        var cols_total = '';
        cols_total += '<tr>\n' +
            '                        <td id="no" class="cell">单号</td>\n' +
            '                        <td id="create_time" class="cell">创建时间</td>\n' +
            '\n' +
            '                    </tr>\n' +
            '\n' +
            '                    <tr>\n' +
            '                        <td id="create_user_text" class="cell">创建人</td>\n' +
            '                        <td id="status_text" class="cell">审核状态</td>\n' +
            '                    </tr>\n' +
            '                    <tr>\n' +
            '                        <td id="check_user_text" class="cell">审核人</td>\n' +
            '                        <td id="check_time" class="cell">审核时间</td>\n' +
            '                    </tr>\n' +
            '                    <tr>';
        if (utils.isHasPermissions('goods.view_goods_cost')) {
            cols_total += '<td id="total_count" class="cell">数量合计</td>\n' +
                '                        <td id="total_amount" class="cell">金额合计</td>\n' +
                '                    </tr>\n' +
                '                    <tr>\n';
        }
        cols_total += '<td id="warehouse_text" class="cell">仓别</td>\n' +
            '<td id="notes" class="cell">备注</td>\n' +
            '                    </tr>';
        $('#table_total').html(cols_total);
        $('.cell').each(function (index, element) {
            element.innerHTML += '：' + (data[element.id]||'')
        });
        admin.req({
            url: '/goods/godownentry/detail/?id='+data.id
            ,done: function(data){
                var items = data.data.items_data;
                var cols = '';
                cols += '<tr>\n' +
                    '                        <td>序号</td>\n' +
                    '                        <td>成品名称</td>\n' +
                    '                        <td>成品代码</td>\n' +
                    '                        <td align="right">数量</td>';
                if (utils.isHasPermissions('goods.view_goods_cost')) {
                    cols += '<td align="right">单价</td>\n' +
                        '                        <td align="right">金额</td>\n'+
                        '                        <td align="right">发票金额</td>\n';
                }
                cols +='                        <td >备注</td>\n' +
                    '                    </tr>';
                $('#tr_item_total').before(cols);
                for(var n in items){
                    var cols_data = '';
                    var m = parseInt(n) + 1;
                    cols_data += "<tr>\n" +
                        "                        <td>"+m+"</td>\n" +
                        "                        <td>"+items[n].goods_name+"</td>\n" +
                        "                        <td>"+items[n].goods_model+"</td>\n" +
                        "                        <td align=\"right\">"+items[n].count+"</td>\n";
                    if (utils.isHasPermissions('goods.view_goods_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].notes+"</td>\n" +
                        "                    </tr>";
                    $('#tr_item_total').before(cols_data);
                }
            }
        });
    });
</script>
</body>
</html>

