<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .btn-default {
        color: #333;
        background-color: #fff;
        border-color: #ccc
    }

    .textEllipsis {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 60px;
        max-width: 60px;
    }

    .bg-orange {
        background: #BEBEBE;
    }

    .bg-blue {
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-info">
            <ul id="myTab" class="nav nav-tabs">
                <li class="active"><a href="#tabHeader" data-toggle="tab">主表</a></li>
                <li><a href="#tabDetail" data-toggle="tab">明细</a></li>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade in active" id="tabHeader">
                    <div class="col-sm-12 select-info">
                        <form id="receiptHeader-form">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        出库单号:<input type="text" name="code"/>
                                    </li>
                                    <li>
                                        原仓库:<select name="warehouse"
                                                       th:with="warehouse=${@dict.getType('originalWarehouse')}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${warehouse}" th:text="${e['dictLabel']}"
                                                th:value="${e['dictValue']}"></option>
                                    </select>
                                    </li>
                                    <!--                                    <li>-->
                                    <!--                                        仓库类型单据:<select id="warehouseTypeDocument" name="warehouseTypeDocument">-->
                                    <!--                                        <option value="">所有</option>-->
                                    <!--                                        <option value="0">立库</option>-->
                                    <!--                                        <option value="1">平库</option>-->
                                    <!--                                    </select>-->
                                    <!--                                    </li>-->
                                    <li>
                                        生产车间:<input type="text" name="workshop"/>
                                    </li>

                                    <li>
                                        出库类型:<select name="shipmentType"
                                                         th:with="shipmentType=${@ShipmentTypeService.getType()}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${shipmentType}" th:text="${e['name']}"
                                                th:value="${e['code']}"></option>
                                    </select>
                                    </li>
                                    <li>
                                        通知单号:<input type="text" name="noticeNo"/>
                                    </li>
                                    <li>
                                        调整单号:<input type="text" name="processType"/>
                                    </li>
                                    <li>
                                        调入仓库名称:<input type="text" name="transferWarehouseName"/>
                                    </li>
                                    <li>
                                        母件名称:<input type="text" name="superiorName"/>
                                    </li>
                                    <li>
                                        母件编码:<input type="text" name="superiorCode"/>
                                    </li>
                                    <li>
                                        头 状 态:<select name="firstStatus"
                                                         th:with="firstStatus=${@dict.getType('shipmentHeaderStatus')}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${firstStatus}" th:text="${e['dictLabel']}"
                                                th:value="${e['dictValue']}"></option>
                                    </select>
                                    </li>
                                    <li>
                                        尾 状 态:<select name="lastStatus"
                                                         th:with="lastStatus=${@dict.getType('shipmentHeaderStatus')}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${lastStatus}" th:text="${e['dictLabel']}"
                                                th:value="${e['dictValue']}"></option>
                                    </select>
                                    </li>
                                    <li>
                                        操作人:<input type="text" name="lastUpdatedBy"/>
                                    </li>
                                    <li>
                                        MOM回传状态:<select id="pushSuccessStatus" name="pushSuccessStatus">
                                        <option value="">所有</option>
                                        <option value="0">未回传</option>
                                        <option value="1">回传成功</option>
                                        <option value="2">回传失败</option>
                                        <option value="3">提前过账</option>
                                    </select>
                                    </li>
                                    <li>
                                        自动出库状态:<select id="autoShipmentStatus" name="autoShipmentStatus">
                                        <option value="">所有</option>
                                        <option value="0">正常单据</option>
                                        <option value="1">预自动出库</option>
                                        <option value="2">已自动出库</option>
                                        <!--                                        <option value="3">自动执行中</option>-->
                                        <option value="4">执行中失败</option>

                                    </select>
                                    </li>
                                    <li>
                                        主体颜色:<input type="text" name="materialColor"/>
                                    </li>
                                    <li>
                                        物料名称:<input type="text" name="materialName"/>
                                    </li>
                                    <li>
                                        物料编码:<input type="text" name="materialCode"/>
                                    </li>
                                    <li>
                                        备注:<input type="text" name="shipmentNote"/>
                                    </li>
                                    <li>
                                        合并前单号:<input type="text" name="recordCode"/>
                                    </li>
                                    <li class="time">

                                        <label>日计划导入日期: </label>
                                        <input type="text" class="time-input" id="dailyScheduleImportDate"
                                               placeholder="日计划导入日期"
                                               name="importDate" autocomplete="off"/>

                                        <label>计划开工日期: </label>
                                        <input type="text" class="time-input" id="requestedStartDate"
                                               placeholder="计划开工日期"
                                               name="startDate" autocomplete="off"/>

                                        <label>计划完成日期: </label>
                                        <input type="text" class="time-input" id="requestedDeliveryDate"
                                               placeholder="计划完成日期"
                                               name="deliveryDate" autocomplete="off"/>

                                        <label>创建时间: </label>
                                        <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                               name="createdBegin" autocomplete="off"/>
                                        <span>-</span>
                                        <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                               name="createdEnd" autocomplete="off"/>
                                    </li>
                                    <li class="time" style="height: 30px">
                                        <label>任务完成时间: </label>
                                        <input type="text" class="time-input" id="startCompleteTime"
                                               placeholder="开始时间" name="completeTimeBegin" autocomplete="off"/>
                                        <span>-</span>
                                        <input type="text" class="time-input" id="endTimeCompleteTime"
                                               placeholder="结束时间" name="completeTimeEnd" autocomplete="off"/>
                                    </li>
                                    <li>
                                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                                class="fa fa-search"></i>&nbsp;搜索</a>
                                        <a class="btn btn-warning btn-rounded btn-sm"
                                           onclick="$.form.reset('receiptHeader-form')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                        <!--<a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="receipt:receiptHeader:export"><i class="fa fa-download"></i>&nbsp;导出</a>-->
                                    </li>
                                </ul>
                            </div>
                        </form>
                    </div>
                    <div class="btn-group hidden-xs" id="toolbar" role="group">
                        <a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()"
                           shiro:hasPermission="shipment:bill:add">
                            <i class="fa fa-plus"></i> 新增
                        </a>
                        <!--                        <a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()"-->
                        <!--                           shiro:hasPermission="shipment:remove">-->
                        <!--                            <i class="fa fa-trash-o"></i> 删除-->
                        <!--                        </a>-->
                        <a class="btn btn-outline btn-success btn-rounded" onclick="wave()"
                           shiro:hasPermission="shipment:bill:billMerge">
                            <i class="fa fa-plus"></i> 单据合并
                        </a>
                        <a class="btn btn-outline btn-success btn-rounded" onclick="autoBillMerge()"
                           shiro:hasPermission="shipment:bill:autoBillMerge">
                            <i class="fa fa-plus"></i> 自动合并单据
                        </a>
                        <a id="openAutoShipmentBtn" class="btn btn-outline btn-success btn-rounded"
                           onclick="autoShipment(1)"
                           shiro:hasPermission="shipment:bill:open">
                            <i></i> 开启自动出库
                        </a>
                        <a id="pauseAutoShipmentBtn" class="btn btn-outline btn-success btn-rounded"
                           onclick="autoShipment(2)"
                           shiro:hasPermission="shipment:bill:close">
                            <i></i> 暂停自动出库
                        </a>
                        <a id="closeAutoShipmentBtn" class="btn btn-outline btn-success btn-rounded"
                           onclick="autoShipment(0)"
                           shiro:hasPermission="shipment:bill:close">
                            <i></i> 关闭自动出库
                        </a>


                        <a class="btn btn-outline btn-success btn-rounded"
                           onclick="autoShipmentChoose()"
                           shiro:hasPermission="shipment:bill:close">
                            <i></i> 自动出库单据选择
                        </a>
                        <a id="autoShipmentStatusBtn" class="btn btn-danger btn-rounded"></a>
                    </div>
                    <table id="bootstrap-table" data-mobile-responsive="true"
                           class="table table-bordered table-hover text-nowrap"></table>
                </div>
                <div class="tab-pane fade" id="tabDetail">
                    <div class="col-sm-12 select-info">
                        <form id="shipmentHeadForm">
                            <div class="tab-content">
                                <div class="tab-pane fade in active" id="tabBase">
                                    <div class="select-list">
                                        <ul>
                                            <li>出库单id:<input type="text" name="shipmentId" id="shipmentId">
                                            <li>
                                            <li>出库单号:<input type="text" name="shipmentCode" id="shipmentCode"></li>
                                            <li>通知单号:<input type="text" name="noticeNo" id="noticeNo"></li>
                                            <input type="hidden" name="shipmentWarehouseId" id="shipmentWarehouseId">
                                            <li><input type="text" name="shipmentWarehouseCode" style="display: none"
                                                       id="shipmentWarehouseCode"></li>
                                            <input type="hidden" name="shipmentCompanyId" id="shipmentCompanyId">
                                            <li><input type="text" name="shipmentCompanyCode"
                                                       id="shipmentCompanyCode" style="display: none"></li>
                                            <li>出库单类型:<input type="text" name="shipmentType" id="shipmentType">
                                            </li>
                                            <li>总数量:<input type="text" name="shipmentTotalQty" id="shipmentTotalQty">
                                            </li>
                                            <li>总行数:<input type="text" name="shipmentTotalLines"
                                                              id="shipmentTotalLines"></li>
                                            <li>单据头状态:<input type="text" name="shipmentFirstStatus"
                                                                  id="shipmentFirstStatus"></li>
                                            <li>单据尾状态:<input type="text" name="shipmentLastStatus"
                                                                  id="shipmentLastStatus"></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="btn-group hidden-xs" id="toolbar-detail" role="group" style="padding:20px 0;">

                        <a class="btn btn-outline btn-success btn-rounded" onclick="add()"
                           shiro:hasPermission="shipment:bill:add">
                            <i class="fa fa-plus"></i> 新增
                        </a>
                        <!--                        <a class="btn btn-outline btn-danger btn-rounded" onclick="batRemove()"-->
                        <!--                           shiro:hasPermission="shipment:remove">-->
                        <!--                            <i class="fa fa-trash-o"></i> 删除-->
                        <!--                        </a>-->
                        <a class="btn btn-outline btn-default btn-rounded" onclick="loadDetail()">
                            <i class="fa fa-refresh"></i> 刷新
                        </a>
                        <a class="btn btn-outline btn-success btn-rounded" onclick="shipmentDetailPrint()"
                           shiro:hasPermission="shipment:bill:report">
                            <i class="fa fa-print"></i> 打印
                        </a>
                        <!--<a class="btn btn-outline btn-success btn-rounded" onclick="autoZone()" shiro:hasPermission="shipment:bill:add">-->
                        <!--<i class="fa fa-plus"></i> 自动分配库区-->
                        <!--</a>-->
                        <!--<a class="btn btn-outline btn-success btn-rounded" onclick="addzone()" shiro:hasPermission="shipment:bill:add">-->
                        <!--<i class="fa fa-plus"></i> 分配库区-->
                        <!--</a>-->
                        <a class="btn btn-outline btn-primary btn-rounded to-receive" onclick="Toshipping(0)"
                           shiro:hasPermission="shipment:shippingCombination:combination">
                            <i class="fa fa-hand-lizard-o"></i> 手动组盘
                        </a>
                        <a class="btn btn-outline btn-primary btn-rounded auto-shipment" onclick="Toshipping(1)"
                           shiro:hasPermission="shipment:shippingCombination:combination">
                            <i class="fa fa-code-fork"></i> 自动组盘
                        </a>

                        <!--                        <a class="btn btn-outline btn-primary btn-rounded auto-shipment-task" onclick="Toshipping(2)"-->
                        <!--                           shiro:hasPermission="shipment:shippingCombination:combination">-->
                        <!--                            <i class="fa fa-code-fork"></i> 自动组盘并生成任务-->
                        <!--                        </a>-->
                        <a class="btn btn-outline btn-primary btn-rounded auto-shipment" onclick="Toshipping(3)"
                           shiro:hasPermission="shipment:shippingCombination:combination">
                            <i class="fa fa-code-fork"></i> 自动平库组盘
                        </a>
                    </div>
                    <table id="bootstrap-table-detail" data-row-style="rowStyle" data-mobile-responsive="true"
                           class="table table-bordered table-hover text-nowrap"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var noReturnRequiredFlag = [[${@permission.hasPermi('shipment:shipmentHeader:noReturnRequired')}]];
    var printFlag = [[${@permission.hasPermi('shipment:bill:report')}]]; //打印
    var editFlag = [[${@permission.hasPermi('shipment:bill:edit')}]];
    var removeFlag = [[${@permission.hasPermi('shipment:remove')}]];
    var postFlag = [[${@permission.hasPermi('shipment:post')}]];
    var prefix = ctx + "shipment/shipmentHeader";
    var prefix_detail = ctx + "shipment/shipmentDetail";
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var shipmentTypes = [[${@ShipmentTypeService.getType()}]];
    var company = [[${@companyService.getCode()}]];
    var warehouses = [[${@WarehouseService.getCode()}]];
    var customer = [[${@CustomerService.getCode()}]];
    var shipmentHeaderStatus = [[${@dict.getType('shipmentHeaderStatus')}]];
    var stations = [[${@dict.getType('station')}]];
    var uploadStatus = [[${@dict.getType('uploadStatus')}]];
    var detailCreateUrl = prefix_detail + "/add";
    var detailRemoveUrl = prefix_detail + "/remove";
    var postUrl = prefix + "/post";
    var reviewUrl = prefix + "/review";
    var analysisUrl = prefix + "/analysis";
    var inventoryStatus = [[${@dict.getType('inventorySts')}]];
    var rossDoccking = [[${@permission.hasPermi('shipment:bill:rossDoccking')}]];
    var rossDocckingUrl = prefix_detail + "/rossDoccking";
    var shipmentId = "";
    var shipmentCode = "";
    var originalWarehouse = [[${@dict.getType('originalWarehouse')}]];


    //日计划导入日期
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var day1 = new Date();
        day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000 * 1);
        // laydate.render({ elem: '#requestedDeliveryDate', theme: 'molv',value: new Date(day1), isInitValue: true});
        laydate.render({elem: '#dailyScheduleImportDate', theme: 'molv'});
    });

    //计划完工日期
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var day1 = new Date();
        day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000 * 1);
        // laydate.render({ elem: '#requestedDeliveryDate', theme: 'molv',value: new Date(day1), isInitValue: true});
        laydate.render({elem: '#requestedDeliveryDate', theme: 'molv'});
    });

    //计划开工日期
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var day1 = new Date();
        day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000 * 1);
        // laydate.render({ elem: '#requestedDeliveryDate', theme: 'molv',value: new Date(day1), isInitValue: true});
        laydate.render({elem: '#requestedStartDate', theme: 'molv'});
    });
    //完成开始
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var day1 = new Date();
        day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000 * 1);
        laydate.render({elem: '#startCompleteTime', theme: 'molv'});
    });
    //完成结束
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var day1 = new Date();
        day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000 * 1);
        laydate.render({elem: '#endTimeCompleteTime', theme: 'molv'});
    });

    $(function () {
        loadAutoShipmentStatus();

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "出库单",
            sortName: "created",
            // height:610,
            sortOrder: "desc",
            sidePagination: "server",
            pageSize: 10,
            showExport: true, //导出
            exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
            search: false,
            columns: [
                {
                    checkbox: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a id="table_edit" class="btn btn-success btn-xs ' + printFlag + '" href="#" onclick="receiptPrint(\'' + row.id + '\',1)"><i class="fa fa-print"></i>打印1</a> ');
                        actions.push('<a id="table_edit" class="btn btn-success btn-xs ' + printFlag + '" href="#" onclick="receiptPrint(\'' + row.id + '\',2)"><i class="fa fa-print"></i>打印2</a> ');
                        // actions.push('<a class="btn btn-info btn-xs " href="#" onclick="detail(\'' + row.id + '\',\'' + row.code + '\')"><i class="fa fa-list-ul"></i>列表</a> ');
                        if (row.lastStatus < 500) {
                            actions.push('<a class="btn btn-info btn-xs ' + postFlag + '" href="#" onclick="posting(\'' + row.id + '\')"><i class="fa fa-edit"></i>结束</a> ');
                        }
                        if (row.firstStatus < 100) {
                            // actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash-o"></i>删除</a>');
                        }
                        if (row.firstStatus == 500 && row.lastStatus == 500) {
                            actions.push('<a class="btn btn-info btn-xs ' + '" href="#" onclick="backERP(\'' + row.id + '\')"><i class="fa fa-upload"></i>回传</a>');
                        }
                        if (row.pushSuccessStatus === 2) {
                            actions.push('<a class="btn btn-danger btn-xs ' + noReturnRequiredFlag + '" href="#" onclick="noReturnRequired(\'' + row.id + '\')"><i class="fa fa-trash-o"></i>无需回传</a>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'warehouse',
                    title: '原仓库',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(originalWarehouse, value);
                    }
                },
                {
                    field: 'id',
                    title: '出库单id',
                    visible: false
                },
                {
                    field: 'autoShipmentStatus',
                    title: '自动出库状态',
                    visible: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (value != undefined) {
                            if (value == 1) {
                                return '<span style="color:green">预自动出库</span>'
                            } else if (value == 2) {
                                return '<span style="color:black">已自动出库</span>'
                            } else if (value == 0) {
                                return '<span>正常单据</span>'
                            } else if (value == 4) {
                                return '<span style="color:#b90e0e">执行中失败,请查看错误信息</span>'
                            } else if (value == 3) {
                                return '<span style="color:#2a75ab">自动执行中</span>'
                            }
                        }
                        return '';
                    }
                },
                {
                    field: 'shipmentType',
                    title: '出库类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(shipmentTypes, function (index, dict) {
                            if (dict.code == value) {
                                actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },
                {
                    field: 'code',
                    title: '出库单号',
                },
                {
                    field: 'firstStatus',
                    title: '头状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(shipmentHeaderStatus, value);
                    },
                },
                {
                    field: 'lastStatus',
                    title: '尾状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(shipmentHeaderStatus, value);
                    },
                },
                {
                    field: 'totalQty',
                    title: '总数量'
                },
                {
                    field: 'totalLines',
                    title: '总行数'
                },
                {
                    field: 'warehouseCode',
                    title: '仓库',
                    visible: false,
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(warehouses, function (index, dict) {
                            if (dict.code == value) {
                                actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },

                {
                    field: 'dailyScheduleImportDate',
                    title: '日计划导入日期',
                    visible: false
                },
                {
                    field: 'requestedStartDate',
                    title: '计划开工日期',
                },
                {
                    field: 'requestedDeliveryDate',
                    title: '计划完成日期',
                },
                // {
                //     field: 'workshop',
                //     title: '生产车间',
                //     formatter: function (value, row, index) {
                //         var actions = [];
                //         if (value == undefined || value == '')
                //             value = " "
                //         else
                //             actions.push("<div class='textEllipsis'>" + value + "</div>")
                //         return actions.join(" ")
                //     }
                // },
                {
                    field: 'workshop',
                    title: '生产车间',
                },
                {
                    field: 'noticeNo',
                    title: '通知单号',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == undefined || value == '')
                            value = " "
                        else
                            actions.push('<pre style="max-height:50px; white-space: pre-wrap; width:250px">' + value + '</pre>')
                        return actions.join(" ")
                    }
                },
                {
                    field: 'superiorName',
                    title: '母件名称',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == undefined || value == '')
                            value = " "
                        else
                            actions.push('<pre style="max-height:50px; white-space: pre-wrap; width:250px">' + value + '</pre>')
                        return actions.join(" ")
                    }
                },
                {
                    field: 'superiorCode',
                    title: '母件编码',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == undefined || value == '')
                            value = " "
                        else
                            actions.push('<pre style="max-height:50px; white-space: pre-wrap; width:250px">' + value + '</pre>')
                        return actions.join(" ")
                    }
                },
                {
                    field: 'recordCode',
                    title: '合并前单号',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == undefined || value == '')
                            value = " "
                        else
                            actions.push('<pre style="max-height:50px; white-space: pre-wrap; width:250px">' + value + '</pre>')
                        return actions.join(" ")
                    }
                },
                {
                    field: 'customerCode',
                    title: '客户',
                    align: 'center',
                    visible: false,
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(customer, function (index, dict) {
                            if (dict.code == value) {
                                actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },
                {
                    field: 'priority',
                    title: '优先级',
                    visible: false
                },
                {
                    field: 'created',
                    title: '创建时间',
                },
                {
                    field: 'createdBy',
                    title: '创建用户',
                },
                {
                    field: 'lastUpdated',
                    title: '最后修改时间',
                    visible: true
                },
                {
                    field: 'completeTime',
                    title: '任务完成时间',
                },
                {
                    field: 'lastUpdatedBy',
                    title: '操作人',
                    visible: true
                },
                {
                    field: 'paintStatus',
                    title: '喷漆状态'
                },
                {
                    field: 'materialColor',
                    title: '主体颜色'
                },
                {
                    field: 'errorMsg',
                    title: '错误信息',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == undefined || value == '')
                            value = " "
                        else
                            actions.push('<pre style="max-height:50px; white-space: pre-wrap; width:500px">' + value + '</pre>')
                        return actions.join(" ")
                    }
                },
                {
                    field: 'processType',
                    title: '调整单号',
                },
                {
                    field: 'shipmentNote',
                    title: '备注',
                },
                {
                    field: 'transferWarehouseName',
                    title: '调入仓库名称',
                },
                {
                    field: 'pushSuccessStatus',
                    title: '回传状态',
                    visible: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (value != undefined) {
                            if (value == 0) {
                                return '<span style="color:black">未回传</span>'
                            } else if (value == 1) {
                                return '<span style="color:green">回传成功</span>'
                            } else if (value == 2) {
                                return '<span style="color:#b90e0e">回传失败</span>'
                            } else if (value == 3) {
                                return '<span style="color:#263594">提前过账</span>'
                            }
                        }
                        return '';
                    }
                },]
        };
        $.table.init(options);
    });

    $("#bootstrap-table-detail").bootstrapTable(
        {
            /*url: prefix_detail + "/list",*/
            createUrl: prefix_detail + "/add",
            updateUrl: prefix_detail + "/edit/{id}",
            removeUrl: prefix_detail + "/remove",
            // queryParams: queryParams,
            // showRefresh: true, //刷新
            modalName: "出库明细",
            search: false,
            clickToSelect: true,
            showExport: false, //导出
            exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
            sortName: "lastUpdated",
            sortOrder: "desc",
            pagination: true,   // 是否显示分页(*)
            pageNumber: 1,                                      // 初始化加载第一页,默认第一页
            pageSize: 10,                                       // 每页的记录行数(*)
            pageList: [10, 25, 50],                             // 可供选择的每页的行数(*)
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '明细id'
                },
                {
                    field: 'shipmentCode',
                    title: '出库单号',
                },
                {
                    field: 'materialCode',
                    title: '物料编码'
                },
                {
                    field: 'materialName',
                    title: '物料名称'
                },
                {
                    field: 'materialSpec',
                    title: '物料规格'
                },
                {
                    field: 'materialUnit',
                    title: '物料单位'
                },
                {
                    field: 'policy',
                    title: '供需政策'
                },
                /*{
                    field: 'status',
                    title: '明细状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(shipmentHeaderStatus, value);
                    },
                    visible:true
                },*/
                {
                    field: 'manufactureDate',
                    title: '生产日期',
                    visible: false
                },
                {
                    field: 'expirationDate',
                    title: '失效日期',
                    visible: false
                },
                {
                    field: 'agingDate',
                    title: '入库日期',
                    visible: false
                },
                {
                    field: 'inventorySts',
                    title: '库存状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(inventoryStatus, value);
                    },
                },
                {
                    field: 'qty',
                    title: '单据数量'
                },
                {
                    field: 'taskQty',
                    title: '已出数量'
                },
                {
                    field: 'inventoryQty',
                    title: '库存数量'
                },
                {
                    field: 'batch',
                    title: '批次',
                    visible: false
                },
                {
                    field: 'lot',
                    title: '批号',
                    visible: false
                },
                {
                    field: 'projectNo',
                    title: '项目号',
                    visible: false
                },
                {
                    field: 'port',
                    title: '出库口',
                    visible: false

                },
                {
                    field: 'status',
                    title: '明细状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(shipmentHeaderStatus, value);
                    }
                },

                {
                    field: 'created',
                    title: '创建时间'
                },
                {
                    field: 'createdBy',
                    title: '创建用户'
                },
                {
                    field: 'lastUpdated',
                    title: '最后修改时间'
                },
                {
                    field: 'lastUpdatedBy',
                    title: '最后操作人'
                },
                {
                    field: 'preMergerWorkshop',
                    title: '合并前车间',
                },
                {
                    field: 'recordCode',
                    title: '合并前单据号'
                },
                {
                    field: 'noticeNo',
                    title: '通知单号',
                },
                {
                    field: 'receiptCode',
                    title: '指定的入库单号',
                },
                {
                    field: 'containerCode',
                    title: '托盘号',
                },
                // {
                //     title: '操作',
                //     align: 'center',
                //     formatter: function (value, row, index) {
                //         var actions = [];
                //         if (row.status < 100) {
                //             // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         }
                //         return actions.join('');
                //     }
                // }
            ]
        }
    );

    function backERP(id) {
        var url = prefix + "/backERP";
        var data = {"id": id};
        $.operate.submit(url, "post", "json", data);
    }

    function submit(url, type, dataType, data, content) {
        $.modal.loading("正在处理中,请稍后...");
        var config = {
            url: url,
            type: type,
            dataType: dataType,
            data: data,
            contentType: content,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    if (result.data !== null) {
                        layer.open({
                            title: ''
                            , content: result.data,
                            closeBtn: false
                        });
                        $("body").focus();
                    } else {
                        $.modal.msg(result.msg);
                    }

                } else {
                    $.modal.alertError(result.msg);
                }
                $("#list-btn").click();
                $.modal.closeLoading();
            }
        };
        $.ajax(config)
    }


    /*入库单列表-详细*/
    function detail(id, code) {
        shipmentId = id;
        shipmentCode = code;
        $("#myTab li").removeClass("active");
        $("#tabHeader").removeClass("in active");
        $("#myTab li:eq(1)").addClass("active");
        $("#tabDetail").addClass("in active");

        loadDetail();
    }

    /** 载入明细 */
    function loadDetail() {
        $.ajax({
            url: ctx + 'shipment/shipmentDetail/list',
            type: 'post',
            data: {
                shipmentId: shipmentId
            },
            success: function (value) {
                $("#bootstrap-table-detail").bootstrapTable('load', value.data);
            }
        })
        $.ajax({
            url: "shipmentHeader/getShipmentHeader",
            type: "post",
            data: {
                id: shipmentId
            },
            success: function (value) {
                $('#shipmentId').val(value.data.id);
                $('#shipmentCode').val(value.data.code);
                $('#shipmentWarehouseCode').val(value.data.warehouseCode);
                $('#shipmentCompanyCode').val(value.data.companyCode);
                $('#shipmentSourceCode').val(value.data.referCode);
                $('#shipmentSourcePlatform').val(value.data.referPlatform);
                $('#shipmentShipTo').val(value.data.customerCode);
                $('#shipmentPriority').val(value.data.priority);
                $('#shipmentTotalQty').val(value.data.totalQty);
                $('#shipmentTotalLines').val(value.data.totalLines);
                $('#shipmentFirstStatus').val(shipmentHeaderStatus.filter(function (a) {
                    return a.dictValue == value.data.firstStatus
                })[0].dictLabel);
                $('#shipmentLastStatus').val(shipmentHeaderStatus.filter(function (a) {
                    return a.dictValue == value.data.lastStatus
                })[0].dictLabel);
                $('#shipmentCreated').val(value.data.created);
                $('#shipmentCreatedBy').val(value.data.createdBy);
                $('#shipmentLastUpdated').val(value.data.lastUpdated);
                $('#shipmentLastUpdatedBy').val(value.data.lastUpdatedBy);
                //$('#shipmentEnable').val(value.data.enable);
                //$('#shipmentDeleted').val(value.data.deleted);
                if (value.data.deleted == false) {
                    $('#shipmentDeleted').val('否')
                } else {
                    $('#shipmentDeleted').val('是')
                }
                $('#shipmentUserDef1').val(value.data.userDef1);
                $('#shipmentUserDef2').val(value.data.userDef2);
                $('#shipmentUserDef3').val(value.data.userDef3);


            }
        })
    }

    /* 添加主单据 */
    function add() {
        if (shipmentId == '') {
            $.modal.open("未选择出库单", "404.html");
        } else {
            var url = detailCreateUrl + "?shipmentId=" + $('#shipmentId').val()
                + "&shipmentCode=" + $('#shipmentCode').val()
                + "&companyId=" + $('#shipmentCompanyId').val()
                + "&companyCode=" + $('#shipmentCompanyCode').val();
            +"&sourceCode=" + $('#shipmentSourceCode').val();
            $.modal.open("添加", url);
        }
    }

    //修改自动出库状态
    function autoShipment(type) {
        var url = prefix + "/autoShipment/" + type;
        $.ajax({
            url: url,
            type: "get",
            success: function (response) {
                if (response.code === 200) {
                    // $.modal.alertSuccess(response.msg);
                    // 刷新当前页面
                    location.reload();
                } else {
                    $.modal.alertError('失败:' + response.msg);
                }
            }
        })
    }


    /* 打印 */
    function receiptPrint(id, version) {
        var shipmentCode = "1";
        var url = prefix + "/autoreport/" + id + "/" + shipmentCode + "/" + version;
        $.ajax({
            url: url,
            type: "get",
            success: function (response) {
                if (response.code === 200) {
                    $.modal.alertSuccess('打印成功');
                } else {
                    $.modal.alertError('打印失败:' + response.msg);
                }
            }
        })
    }

    /* 加载自动出库的状态 */
    function loadAutoShipmentStatus() {
        var url = prefix + "/loadAutoShipmentStatus";
        $.ajax({
            url: url,
            type: "get",
            success: function (response) {
                if (response.code === 200) {
                    var text = response.msg
                    var element = document.getElementById("autoShipmentStatusBtn");
                    if (element) {
                        element.innerHTML = '<i>' + text + '</i>';
                    }
                    if (text === "已关闭自动出库") {
                        element.classList.add("btn-outline");
                    }
                } else {
                    $.modal.alertError('修改自动出库状态失败:' + response.msg);
                }
            }
        })
    }

    /* 提前过账 */
    function posting(id) {
        $.modal.confirm("确定要结束单据吗?", function () {
            var url = $.common.isEmpty(id) ? postUrl : postUrl.replace("{id}", id);
            var data = {"ids": id};
            localHeaderSubmit(url, "post", "json", data);
        });
    }

    /* 自动合并一个单据 */
    function autoBillMerge() {
        var url = prefix + "/autoBillMerge/";
        $.ajax({
            url: url,
            type: "get",
            success: function (response) {
                if (response.code === 200) {
                    $.modal.alertSuccess(response.msg);
                } else {
                    $.modal.alertError(response.msg);
                }
            }
        })
    }

    /* 编辑明细单据 */
    function edit(id) {
        if (shipmentId == '') {
            $.modal.open("未选择出库单", "404.html");
        } else {
            var url = prefix_detail + "/edit/" + id;
            $.modal.open("编辑明细", url);
        }
    }

    /* 单个删除 */
    function remove(id) {
        $.modal.confirm("确定删除该条出库单明细信息吗?", function () {
            var url = $.common.isEmpty(id) ? detailRemoveUrl : detailRemoveUrl.replace("{id}", id);
            var data = {"ids": id};
            localSubmit(url, "post", "json", data);
        });
    }

    /* 批量删除 */
    function batRemove() {
        var rows = $("#bootstrap-table-detail").bootstrapTable('getSelections');
        // console.log(rows);
        // var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
            var url = detailRemoveUrl;
            var data = {
                "ids": rows.map(function (v) {
                    return v.id;
                }).join(',')
            };
            localSubmit(url, "post", "json", data);
        });
    }

    /* 订单审核 */
    function review() {
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var url = reviewUrl;
        var data = {
            "ids": rows.map(function (v) {
                return v.id;
            }).join(',')
        };
        localHeaderSubmit(url, "post", "json", data);

    }


    //子单打印
    function shipmentDetailPrint() {
        let rows = $("#bootstrap-table-detail").bootstrapTable('getSelections');
        if (rows.length === 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        let ids = "";
        for (let i = 0; i < rows.length; i++) {
            ids = ids + rows[i].id + ","
        }

        let url = prefix_detail + "/report/" + ids;
        $.modal.open("出库单铭牌打印", url);
    }

    /* 订单分析 */
    function analysis() {
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要分析选中的" + rows.length + "条数据吗?", function () {
            var url = detailanalysisUrl;
            var data = {
                "ids": rows.map(function (v) {
                    return v.id;
                }).join(',')
            };
            localHeaderSubmit(url, "post", "json", data);
        });
    }

    function localSubmit(url, type, dataType, data) {
        $.modal.loading("正在处理中,请稍后...");
        var config = {
            url: url, type: type, dataType: dataType, data: data, success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(result.msg);
                    loadDetail(shipmentId, shipmentCode)
                } else {
                    $.modal.alertError(result.msg)
                }
                $.modal.closeLoading()
            }
        };
        $.ajax(config)
    }

    function localHeaderSubmit(url, type, dataType, data) {
        $.modal.loading("正在处理中,请稍后...");
        var config = {
            url: url, type: type, dataType: dataType, data: data, success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(result.msg);
                    $.table.refresh();
                } else {
                    $.modal.alertError(result.msg)
                }
                $.modal.closeLoading()
            }
        };
        $.ajax(config)
    }

    /* 无需回传 */
    function noReturnRequired(id) {
        var url = prefix + "/noReturnRequired";
        var data = {"id": id};
        $.operate.submit(url, "post", "json", data);
    }


    /* 出库组盘 */
    function Toshipping(flag) {
        let storage = window.localStorage;
        storage.shipmentCode = shipmentCode;
        let url = ctx + "shipment/shippingCombination";
        if (flag == 2) {
            storage.auto = flag;
            createMenuItem(url, "出库自动组盘");
            parent.$('.tabReload').click();
        } else if (flag == 0) {
            $.ajax({
                url: ctx + "shipment/shipmentDetail/shippingCombination",
                type: 'post',
                data: {
                    shipmentCode
                },
                success: function (res) {
                    if (res.code === 200) {
                        createMenuItem(url, "出库组盘");
                        parent.$('.tabReload').click();
                    } else {
                        $.modal.alert(res.msg)
                    }
                }
            });
        } else if (flag == 1) {
            storage.auto = flag;
            createMenuItem(url, "出库自动组盘");
            parent.$('.tabReload').click();
        } else if (flag == 3) {
            storage.auto = flag;
            createMenuItem(url, "出库自动组盘");
            parent.$('.tabReload').click();
        }
    }

    /* 点击明细面板 */
    $("#myTab li:eq(1)").click(function () {
        // if (shipmentId == '' || shipmentCode == '') {
        //     shipmentId = $("#bootstrap-table tr:eq(1) td:eq(1)").text();
        //     shipmentCode = $("#bootstrap-table tr:eq(1) td:eq(2)").text();
        // }
        detail(shipmentId, shipmentCode);
    });

    /* 点击主表面板 */
    $("#myTab li:eq(0)").click(function () {
        $.ajax({
            url: prefix + "/list",
            type: "post",
            success: function (value) {
                $("#bootstrap-table").bootstrapTable('refresh', value.data);
            }
        })
    });

    function wave() {
        let url = prefix + '/wave?ids=';
        let rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length === 0) {
            $.modal.msgWarning("请至少选择一条记录");
        } else {
            let ids = "";
            for (let i = 0; i < rows.length; i++) {
                ids = ids + rows[i].id + ","
            }
            ids = ids.substring(0, ids.length - 1);
            url = url + ids;
            $.modal.open("确认提交合并单据", url, 800, 250)
        }
    }

    // //自动分配库区
    // function autoZone() {
    //     let code=$("#shipmentCode").val();
    //     $.ajax({
    //         url:prefix_detail+'/addZones',
    //         type:'post',
    //         data:{
    //             code:code
    //         },
    //         success:function (res) {
    //             if (res.code === 200) {
    //                 $.modal.msgSuccess(res.msg);
    //                 loadDetail();
    //             }
    //             else{
    //                 $.modal.msgError(res.msg);
    //             }
    //         }
    //     })
    //

    function autoShipmentChoose() {
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要自动出库选中的" + rows.length + "条数据吗?", function () {
            var url = prefix + '/autoShipmentChoose';
            var data = {
                "ids": rows.map(function (v) {
                    return v.id;
                }).join(',')
            };
            $.modal.loading("正在处理中,请稍后...");
            var config = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess(result.msg);
                        $.table.refresh();
                    } else {
                        $.modal.alertError(result.msg)
                    }
                    $.modal.closeLoading()
                }
            };
            $.ajax(config)
        });
    }
</script>
</body>
</html>