<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>首页</title>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
    <style>
        .imgsMa{
            margin: 0 0% 30px;
        }
        .order-title{
            display: inline;
            float: left;
            font-size: 14px;
            font-weight: bold;
        }
        .layui-col-space5{margin: -5px;}
        td {
            text-align: center;
        }
        .layui-table[lay-size=sm] th {
            text-align: center;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12">
            <div class="layui-row">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">物料申请流程</div>
                        <div class="layui-card-body item-flow pt-50 pb-20 pl-50">
                            <div><b >代理商下单</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >业务部门审批</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b>工程部审批</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >运管部审批</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >物资专员匹配库存、拆单下单</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >供应商/供应链发货</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >代理商收货入库</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b >代理商新增出库单出库</b></div>
                            <img src="${ctxPlugin}/static/img1/smartart.png" alt="" class="imgsMa">
                            <div><b>完成</b></div>
                        </div>
                    </div>
                </div>

                <div class="layui-col-md12 mt-10">
                    <div class="layui-card">
                        <div class="layui-card-header">安全库存预警<a style="float: right" href="javascript:goAlarm();" class="matterBtn">更多 >> </a></div>
                        <div style="padding: 0 10px 2px">
                            <table class="layui-table" lay-size="sm">
                                <colgroup>
                                    <col width="50%">
                                    <col width="20%">
                                    <col>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>预警内容 </th>
                                    <th>状态</th>
                                    <th>预警时间</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="alarm" items="${alarmList}">
                                    <tr data-id="${alarm.columns.id}">
                                        <td class="pointer" onclick="showDetail(this)">${alarm.columns.content}</td>
                                        <td>${alarm.columns.status eq '0' ? '未读' : '已读'}</td>
                                        <td><fmt:formatDate value="${alarm.columns.create_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>

                <div class="layui-col-md12 mt-10">
                    <div class="layui-card">
                        <div class="layui-card-header">物料订单统计</div>
                        <div class="layui-card-body">
                            <ul class="layui-row layui-col-space10 text-c">

                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待审批</h3>
                                        <p><cite class="dspCount">0</cite></p>
                                    </a>
                                </li>
                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待供应链发货</h3>
                                        <p><cite class="dgylfhCount">0</cite></p>
                                    </a>
                                </li>

                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待供应商发货</h3>
                                        <p><cite class="dgysfhCount">0</cite></p>
                                    </a>
                                </li>
                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待代理商入库</h3>
                                        <p><cite class="djxsrkCount">0</cite></p>
                                    </a>
                                </li>
                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待供应链入库</h3>
                                        <p><cite class="dgylrkCount">0</cite></p>
                                    </a>
                                </li>
                                <li class="layui-col-xs2 h-100 pt-20">
                                    <a class="layadmin-backlog-body">
                                        <h3>待审核</h3>
                                        <p><cite class="dshCount">0</cite></p>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">

    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'console','jquery','echarts'],function(){
        $= layui.jquery;
        echarts=layui.echarts;
        var category = [];
        var dottedBase = +new Date();
        findAnnouncementOne();

        orderCount();
    });

    function showDetail(that) {
        var alarmId = $(that).closest('tr').attr('data-id');
        var content = $(that).closest('tr').find('td:eq(0)').text();
        layer.open({
            title: '查看'
            ,content: content
        });
        $.post('${ctx}/alarm/markAsRead', {alarmId: alarmId}, function(){});
    }

    function goAlarm() {
        layer.open({
            type: 2,
            title: '预警消息',
            content: '${ctx}/alarm/toAlarmPage',
            area: ['80%', '80%']
        });
    }

    function orderCount(){

        $.ajax({
            type:"POST",
            url:"${ctx}/customerEntry/statisticEntry",
            success:function(data){
                console.log(data)
                $(".dspCount").html(data.columns.dsp);
                $(".dgylfhCount").html(data.columns.dgylfh);
                $(".dgysfhCount").html(data.columns.dgysfh);
                $(".djxsrkCount").html(data.columns.djxsrk);
                $(".dgylrkCount").html(data.columns.dgylrk);
                $(".dshCount").html(data.columns.dsh);
            }
        });
    }

    function findAnnouncementOne() {
        $.ajax({
            type: "POST",
            url: "${ctx}/notification/findAnnouncementOne",
            success: function (data) {
                console.log(data)
                if(!isBlank(data)){
                    layer.open({
                        type: 2,
                        title: '详情',
                        content: '${ctx}/msg/center/supplyShowDetail?id=' + data.columns.id,
                        maxmin: true,
                        area: ['800px', '495px'],
                        btn: ['已接收','关闭'],
                        yes: function (index, layero) {
                            $.ajax({
                                type: 'post',
                                data: {id: data.columns.id},
                                url: "${ctx}/msg/center/markMsgAsRead",
                                success: function (data) {
                                    layer.msg("接收成功",{icon:1})
                                }
                            });
                            layer.close(index);
                        },
                        btn2: function(index, layero){
                            layer.close(index);
                        },
                        cancel: function (index, layero) {
                            layer.close(index);
                        }
                    });
                }
            }
        });
    }
    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>

