<!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 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 items = data.data.items_data;
                var cols = '';
                if (data.data.inventory_type == 1){
                    cols += '<tr>\n' +
                    '                        <td width="30">序号</td>\n' +
                    '                        <td width="100px">名称</td>\n' +
                    '                        <td width="100px">代码</td>\n' +
                    '                        <td width="100px">仓别</td>\n' +
                    '                        <td width="100px">入库单</td>\n' +
                    '                        <td align="right" width="60px">数量</td>';
                } else {
                     cols += '<tr>\n' +
                    '                        <td width="30">序号</td>\n' +
                    '                        <td width="100px">名称</td>\n' +
                    '                        <td width="100px">代码</td>\n' +
                    '                        <td width="100px">仓别</td>\n' +
                    '                        <td align="right" width="60px">数量</td>';
                }

                if (status) {
                    cols += '<td align="right" width="60px">单价</td>\n' +
                        '                        <td align="right" width="60px">金额</td>\n';

                }
                cols += '<td width="200px">备注</td>\n' +
                        '                    </tr>';
                $('#tr_item_total').before(cols);
                for(var n in items){
                    if(items[n].notes == null){
                        items[n].notes = '';
                    }
                    var m = parseInt(n) + 1;
                    var cols_data = '';
                    if (data.data.inventory_type == 1) {
                        cols_data += "<tr>\n" +
                        "                        <td>"+m+"</td>\n" +
                        "                        <td>"+items[n].product_name+"</td>\n" +
                        "                        <td>"+items[n].product_model+"</td>\n" +
                        "                        <td>"+items[n].warehouse_text+"</td>\n" +
                        "                        <td>"+items[n].entry_no+"</td>\n" +
                        "                        <td align=\"right\">"+items[n].count+"</td>\n";
                    }else{
                        cols_data += "<tr>\n" +
                        "                        <td>"+m+"</td>\n" +
                        "                        <td>"+items[n].product_name+"</td>\n" +
                        "                        <td>"+items[n].product_model+"</td>\n" +
                        "                        <td>"+items[n].warehouse_text+"</td>\n" +
                        "                        <td align=\"right\">"+items[n].count+"</td>\n";
                    }

                    if (status) {
                        cols_data += "                        <td align=\"right\">"+items[n].price+"</td>\n" +
                            "                        <td align=\"right\">"+items[n].amount+"</td>\n";
                    }
                    cols_data +="                        <td>"+items[n].notes+"</td>\n" +
                        "                    </tr>";
                    $('#tr_item_total').before(cols_data);
                }
            }
        });
    });
</script>
</body>
</html>

