<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<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">
    <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>
        html {
            background-color: #fff;
        }
    </style>
</head>
<body>
<div class="layui-card md-0">
    <div class="layui-card-body" id="LAY_app">
        <div class="layui-form" lay-filter="layuiadmin-form-admin" >

            <div class="layui-form-item layui-col-xs12 ">

                <div class="layui-col-xs6 layui-form-item">
                    <label class="layui-form-label">发货单位凭证：</label>
                    <div class="layui-input-block">
                        <div>
                            <div class="bimgSpan mt-10">
                              <%--  <img src="${commonStaticImgPath}${img.deliverImg}" data-img="${commonStaticImgPath}${img.deliverImg}" height="900" width="1300"/>--%>
                                <%--<a target="_blank" style="color:#D9B589;cursor:pointer;" href="https://sunhomemanager.sungrowpower.com/online-preview/onlinePreview?url=${commonStaticImgPath}${img.deliverImg}">查看发货凭证</a>--%>
                                  <a href="${commonStaticImgPath}${img.deliverImg}" class="layui-table-link" target="_blank">查看发货凭证</a>
                            </div>
                        </div>
                    </div>
                </div>
                <c:if test="${order.orderType ne '1'}">
                    <div class="layui-col-xs6 layui-form-item">
                        <label class="layui-form-label">接货单位凭证：</label>
                        <div class="layui-input-block">
                            <div>
                                <div class="imgSpan mt-10">
                                    <%--<img src="${commonStaticImgPath}${img.receivingImg}" data-img="${commonStaticImgPath}${img.receivingImg}" height="900" width="1300"/>--%>
                                        <a href="${commonStaticImgPath}${img.receivingImg}" target="_parent" class="layui-table-link" >查看接货凭证</a>
                                   <%-- <a target="_blank" style="color:#D9B589;cursor:pointer;" href="https://sunhomemanager.sungrowpower.com/online-preview/onlinePreview?url=${commonStaticImgPath}${img.receivingImg}">查看接货凭证</a>--%>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>

                <div class="layui-col-xs12 mt-5">
                    <label class="layui-form-label">审核备注：</label>
                    <div class="layui-input-block">
                        <textarea id="reason" name="reason" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item " >
                <div class="layui-col-xs12 mb-10 pr-30">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

                            <ul class="layui-tab-title">
                                <li class="layui-this">物料清单</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <table class="layui-table">
                                        <thead>
                                        <th>序号</th>
                                        <th>物料代码</th>
                                        <th>物料类型</th>
                                        <th>物料组</th>
                                        <th>单位</th>
                                        <th>物料描述</th>
                                        <c:choose>
                                            <c:when test="${order.orderType eq '1'}">
                                                <th>当前库存</th>
                                                <th>盘点数量</th>
                                                <th>盘盈/盘亏</th>
                                            </c:when>
                                            <c:when test="${order.orderType eq '2'}">
                                                <th>调拨数量</th>
                                                <th>调出方库存</th>
                                            </c:when>
                                            <c:otherwise>
                                                <th>下单数量</th>
                                                <th>实发数量</th>
                                                <th>入库数量</th>
                                            </c:otherwise>
                                        </c:choose>

                                        </thead>
                                        <tbody id="materialTbody">
                                        <c:forEach items="${list}" var="detail" varStatus="vs">
                                            <tr data-id="${detail.columns.id}"
                                                data-materialId="${detail.columns.material_id}"
                                                data-applyAmount="${detail.columns.apply_amount}">
                                                <td>${vs.count}</td>


                                                <c:choose>
                                                    <c:when test="${order.orderType eq '1'}">
                                                        <td>${detail.columns.material_code}</td>
                                                        <td>${detail.columns.material_type}</td>
                                                        <td>${detail.columns.material_group}</td>
                                                        <td>${detail.columns.material_unit}</td>
                                                        <td>${detail.columns.material_remarks}</td>
                                                        <td><fmt:formatNumber value="${detail.columns.stock}" pattern="#" /></td>
                                                        <td><fmt:formatNumber value="${detail.columns.amount}" pattern="#" /></td>
                                                        <c:set value="${detail.columns.amount - detail.columns.stock}" var="diff"></c:set>
                                                            <td>
                                                                <c:if test="${diff > 0}">+</c:if>
                                                                <fmt:formatNumber value="${diff}" pattern="#"/>
                                                            </td>
                                                    </c:when>
                                                    <c:when test="${order.orderType eq '2'}">
                                                        <td>${detail.columns.material_code}</td>
                                                        <td>${detail.columns.material_type}</td>
                                                        <td>${detail.columns.material_group}</td>
                                                        <td>${detail.columns.material_unit}</td>
                                                        <td>${detail.columns.material_remarks}</td>
                                                        <td>${detail.columns.amount}</td>
                                                        <td>${detail.columns.stock}</td>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <td>${detail.columns.code}</td>
                                                        <td>${detail.columns.materialTypeName}</td>
                                                        <td>${detail.columns.materialGroupName}</td>
                                                        <td>${detail.columns.unit_name}</td>
                                                        <td>${detail.columns.remarks}</td>
                                                        <td>${detail.columns.apply_amount}</td>
                                                        <td>${detail.columns.out_amount}</td>
                                                        <td>${detail.columns.in_amount}</td>
                                                    </c:otherwise>
                                                </c:choose>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item operate-footer" style="text-align: center;">
                <button type="button" class="layui-btn" onclick="passOrder()">同意</button>
                <button type="button" class="layui-btn" onclick="rejectOrder()">驳回</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="cancels()" >取消</button>
            </div>
        </div>
    </div>
</div>

<%--<div id="lookImg" class="hide pos-r">
    <div style="position:relative;width:100%;height:500px;">
        <div class="w-500 h-450 lookImg">
            <img src="" width="80%" id="image" >
        </div>
    </div>
</div>--%>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/ueditor/1.4.3/third-party/jquery-1.10.2.min.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/modules/qrcode.min.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script>
    //图片查看效果
    var viewer = new Viewer(document.getElementById('LAY_app'));
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    var imgsCount;
    var fitId = '${apply.columns.fittingId}';
    var layer;
    layui.use(['form', 'jquery', 'layer'], function () {
        $ = layui.$;

        form = layui.form;

        layer = layui.layer;

        //$("#codeDiv").empty().qrcode({width : 120, height : 120,text:fitId});

       /* $(".imgSpan img").click(function(){
            var img = $(this).attr("data-img");
            $("#lookImg img").attr('src',img);
            /!*layer.open({
                type:1,
                title:'查看图片',
                area:['500px','530px'],
                content:$("#lookImg")
            })*!/
            parent.showImg(img);
        })*/
    });


    var passFlag = false;
    function passOrder() {
        if (passFlag) {
            return;
        }
        var reason = $("textarea[name='reason']").val();
        passFlag = true;
        $.post('${ctx}/checkPendingOrder/auditOrder', {orderId: '${order.id}', reason: reason}, function(result){
            if (result.code === '200') {
                layer.msg("操作成功！",{time:1000},function(){

                    parent.layer.close(index);
                    parent.$('.layui-laypage-btn').click();
                });
            } else {
                layer.msg('操作失败！'+result.errMsg, {icon: 5, anim: 6});
                passFlag = false;
            }
        });
    }

    var rejectFlag = false;
    function rejectOrder() {
        if (rejectFlag) {
            return;
        }
        var reason = $("textarea[name='reason']").val();
        if (isBlank(reason)) {
            layer.msg('请输入审核备注！', {icon: 5, anim: 6});
            return;
        }
        rejectFlag = true;
        $.post('${ctx}/checkPendingOrder/rejectOrder', {orderId: '${order.id}', reason: reason}, function(result){
            if (result.code === '200') {
                layer.msg("操作成功！",{time:1000},function(){
                    parent.layer.close(index);
                    parent.$('.layui-laypage-btn').click();
                });
            } else {
                layer.msg('操作失败！'+result.errMsg, {icon: 5, anim: 6});
                rejectFlag = false;
            }
        });
    }

    function previewUrl(_url){
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded =  base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function cancels(){
        parent.layer.closeAll();
    }


</script>
</body>
</html>
