<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>批量下单</title>
    <meta name="decorator" content="base"/>
    <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">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>html {
        background-color: #fff;
        padding-bottom: 50px;
    }

    td, th {
        text-align: center !important;
    }</style>
</head>

<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <table class="layui-table">
                            <thead>
                            <th width="10%">序号</th>
                            <th width="30%">物料类型</th>
                            <th width="40%">物料规格</th>
                            <th width="20%">下单数量</th>
                            </thead>
                            <tbody id="materialTbody">
                            <c:forEach items="${details}" var="applyDetail" varStatus="vs">
                                <tr>
                                    <td>${vs.count}</td>
                                    <td><c:choose>
                                        <c:when test="${applyDetail.columns.type == '1'}">逆变器</c:when>
                                        <c:when test="${applyDetail.columns.type == '2'}">并网箱</c:when>
                                        <c:when test="${applyDetail.columns.type == '3'}">组件</c:when>
                                        <c:when test="${applyDetail.columns.type == '4'}">支架</c:when>
                                    </c:choose></td>
                                    <td>${applyDetail.columns.model}</td>
                                    <td>${applyDetail.columns.num}</td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-form-item layui-col-xs6">
                        <label class="layui-form-label"><span class="red">*</span>入库仓库：</label>
                        <div class="layui-input-block">
                            <select name="inWarehouse" lay-search lay-verify="required" id="inWarehouse"
                                    lay-filter="inWarehouse">
                                <c:forEach items="${warehouseList}" var="warehouse">
                                    <option value="${warehouse.columns.id}">${warehouse.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label w-130">订单备注：</label>
                        <div class="layui-input-block ">
                            <textarea class="layui-textarea" id="orderRemark"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <button type="button" class="layui-btn" onclick="confirmOrder();">确认</button>
        <button type="button" class="layui-btn layui-btn-primary" onclick="closeDiv();">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var $;
    var imgs = '';
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'layedit', 'laydate', 'jquery', 'layer', 'element', 'upload'], function () {
        $ = layui.jquery;
        form = layui.form;
        var element = layui.element;
        $form = $('form');
    })

    var splitFlag = false;
    function confirmOrder() {
        if (splitFlag) {
            return;
        }
        let warehouseId = $("#inWarehouse").val();
        if (isBlank(warehouseId)) {
            layer.msg('请选择入库仓库');
            return;
        }
        let remark = $("#orderRemark").val();
        splitFlag = true;
        $.ajax({
            type: 'post',
            url: '${ctx}/customerEntry/batchOrder',
            data: {
                ids: '${ids}',
                warehouseId: warehouseId,
                remark: remark
            },
            success: function(data){
                if (data.code === '200') {
                    layer.msg('操作成功', {time: 2000});
                    parent.searchOrder();
                    closeDiv();
                } else {
                    layer.msg(data.errMsg, {time: 2000});
                }
                splitFlag = false;
            }
        })
    }

    function closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

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


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