<!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>
    #toolbar1 {
        display: inline-block;
        /*position: absolute;*/
        margin: 10px auto;
        line-height: 34px;
    }

    .time3 label, .time3 span, .time3 input {
        float: left;
    }

    .time3 label {
        margin-top: 5px;
    }

    .time3 span {
        display: block;
        margin: 5px 5px;
    }
</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="task-form">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        入库单号:<input type="text" name="code"/>
                                    </li>
                                    <li>
                                        入库类型:
                                        <select id="receiptType" name="receiptType"></select>

                                    </li>
                                    <li>
                                        货主:
                                        <select id="companyCode" name="companyCode"></select>

                                    </li>
                                    <li>
                                        U8仓库:<select id="uWarehouseCode" name="uWarehouseCode"></select>
                                    </li>

                                    <li>
                                        上游单号:<input type="text" name="referCode"/>
                                    </li>
                                    <li>
                                        供应商:<input type="text" name="supplierCode"/>
                                    </li>
                                    <li>
                                        <!--头 状 态:<input type="text" name="firstStatus"/>-->
                                        头状态:<select name="firstStatus"
                                                       th:with="firstStatus=${@dict.getType('receiptHeaderStatus')}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${firstStatus}" th:text="${e['dictLabel']}"
                                                th:value="${e['dictValue']}"></option>
                                    </select>
                                    </li>
                                    <li>
                                        <!--尾 状 态:<input type="text" name="lastStatus"/>-->
                                        尾状态:<select name="lastStatus"
                                                       th:with="lastStatus=${@dict.getType('receiptHeaderStatus')}">
                                        <option value="">所有</option>
                                        <option th:each="e : ${lastStatus}" th:text="${e['dictLabel']}"
                                                th:value="${e['dictValue']}"></option>
                                    </select>
                                    </li>
                                    <li class="time">
                                        <label>创建时间: </label>
                                        <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                               name="createdBegin"/>
                                        <span>-</span>
                                        <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                               name="createdEnd"/>
                                    </li>
                                    <li>
                                        创建者:<input type="text" name="createdBy"/>
                                    </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('task-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="receipt:receiptHeader:add">
                            <i class="fa fa-plus"></i> 新增
                        </a>

                        <a class="btn btn-outline btn-info btn-rounded" onclick="yueku()">
                            <i class="fa fa-random"></i> 越库
                        </a>

                        <a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()"
                           shiro:hasPermission="receipt:receiptHeader:remove">
                            <i class="fa fa-trash-o"></i> 删除
                        </a>
                        <a class="btn btn-info" onclick="$.table.importExcel()">
                            <i class="fa fa-upload"></i>导入
                        </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="tab-content">
                        <div class="tab-pane in active" id="tabBase">
                            <div class="select-list">
                                <ul>
                                    <li>入库单ID:<input type="text" name="receiptId" id="receiptId"></li>
                                    <li>入库单号:<input type="text" name="receiptCode" id="receiptCode"></li>

                                    <li>上游订单类型:<input type="text" name="referType" id="referType"></li>
                                    <li>总数量:<input type="text" name="receiptTotalQty" id="receiptTotalQty"></li>
                                    <li>总行数:<input type="text" name="receiptTotalLines" id="receiptTotalLines">
                                    </li>
                                    <li>单据头状态:<input type="text" name="receiptFirstStatus"
                                                          id="receiptFirstStatus"></li>
                                    <li>单据尾状态:<input type="text" name="receiptLastStatus"
                                                          id="receiptLastStatus"></li>
                                </ul>
                            </div>
                        </div>

                    </div>
                    <div class="btn-group hidden-xs" id="toolbar1" role="group">
                        <a class="btn btn-outline btn-success btn-rounded" onclick="add()"
                           shiro:hasPermission="receipt:receiptDetail:add">
                            <i class="fa fa-plus"></i> 新增
                        </a>
                        <a class="btn btn-outline btn-danger btn-rounded" onclick="batRemove()"
                           shiro:hasPermission="receipt:receiptDetail:remove">
                            <i class="fa fa-trash-o"></i> 删除
                        </a>
                        <a class="btn btn-outline btn-success btn-rounded" onclick="batUWarehouse()"
                           shiro:hasPermission="receipt:receiptDetail:add">
                            <i class="fa fa-cog"></i> 修改u8仓库
                        </a>
                        <a class="btn btn-outline btn-primary btn-rounded to-receive"
                           onclick="createStation(receiptCode)" shiro:hasPermission="receipt:receiving:add">
                            <i class="fa fa-cart-plus"></i> 组盘信息
                        </a>
                        <a class="btn btn-outline btn-success btn-rounded" onclick="receiptDetailPrint()"
                           shiro:hasPermission="shipment:bill:report">
                            <i class="fa fa-print"></i> 打印
                        </a>
                        <a class="btn btn-outline btn-primary btn-rounded" onclick="Toreceiving(receiptCode)">
                            <i class="fa fa-cart-plus"></i> 收货
                        </a>
                        <a class="btn btn-outline btn-primary btn-rounded" onclick="ToreceivingSn(receiptCode)">
                            <i class="fa fa-cart-plus"></i> SN收货
                        </a>
                    </div>
                    <table id="bootstrap-table1" 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 printFlag = [[${@permission.hasPermi('receipt:receiptHeader:report')}]];
    var editFlag = [[${@permission.hasPermi('receipt:receiptHeader:edit')}]];
    var removeFlag = [[${@permission.hasPermi('receipt:receiptHeader:remove')}]];
    let receiveFlag = [[${@permission.hasPermi('receipt:receiptHeader:receive')}]];
    var addFlag = [[${@permission.hasPermi('receipt:receiptHeader:add')}]];

    var prefix = ctx + "receipt/receiptHeader";
    var detailPrefix = ctx + "receipt/receiptDetail";
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var receiptTypes = [[${@receiptTypeService.getHideType()}]];
    var receiptHeaderStatus = [[${@dict.getType('receiptHeaderStatus')}]];
    var company = [[${@companyService.getCode()}]];
    var detailCreateUrl = detailPrefix + "/add";
    var detailUpdateUrl = detailPrefix + "/edit/{id}";
    var detailRemoveUrl = detailPrefix + "/remove";


    var receiptId = '';
    var receiptCode = '';
    let status = [[${status}]];
    // var statusFirst = [[${statusFirst}]];
    // var statusLast = [[${statusLast}]];

    var uWarehouseNames = [[${@warehouseWu.getName()}]];

    // setInterval(refreshV, 1000 * 60);

    function refreshV() {
        //$.table.refresh();
    }

    function initCompany() {
        $("select[name='companyCode']").children().remove();
        $("select[name='companyCode']").append(`<option value="">所有</option>`);
        for (let item of company) {
            let option = `<option value="${item.code}">${item.name}</option>`;
            $("select[name='companyCode']").append(option);
        }
    }

    function initReceiptType() {
        $("select[name='receiptType']").children().remove();
        $("select[name='receiptType']").append(`<option value="">所有</option>`);
        for (let item of receiptTypes) {
            let option = `<option value="${item.code}">${item.name}</option>`;
            $("select[name='receiptType']").append(option);
        }
    }

    $(function () {
        initCompany();
        initReceiptType();
        $("select[name='companyCode']").change(function (e) {
            let companyCode = $("select[name='companyCode'] option:selected").val();
            $.ajax({
                url: prefix + '/getwarehouse',
                type: 'post',
                data: {code: companyCode},
                success: function (response) {
                    if (response.code === 200) {
                        $("select[name='uWarehouseCode']").children().remove();
                        $("select[name='uWarehouseCode']").append(`<option value="">所有</option>`);
                        for (let item of response.data) {
                            let option = `<option value="${item.uWarehouseCode}">${item.uWarehouseName}</option>`;
                            $("select[name='uWarehouseCode']").append(option);
                        }
                    } else {
                        $.modal.msgError(response.msg)
                    }
                }
            })
        })
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            importUrl: detailPrefix + "/importData",
            importTemplateUrl: detailPrefix + "/importTemplate",
            modalName: "入库单",
            // sidePagination: "server",
            queryParams: queryParams,
            search: false,
            pageSize: 10,


            columns: [{
                checkbox: true
            },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // if (row.trackCode == "" && row.kuaidiCom == "") {
                        //     actions.push('<a class="btn btn-primary btn-xs ' + editFlag + ' href="#" onclick="eddit(\'' + row.id + '\')"><i class="fa fa-cart-plus"></i>导入</a> ');
                        // }
                        /*if (row.trackCode != '' ) {
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + ' href="#" onclick="eddit(\'' + row.id + '\')"><i class="fa fa-cart-plus"></i>分单</a> ');
                        }*/
                        actions.push('<a id="table_edit" class="btn btn-success btn-xs ' + printFlag + '" href="#" onclick="receiptPrint(\'' + row.id + '\')"><i class="fa fa-print"></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> ');
                        // }
                        /* if (row.firstStatus ==150 || row.lastStatus == 150 ){
                             actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="arrivalNotice(\'' + row.id + '\')" ><i class="fa fa-edit"></i>到货通知</a> ');
                         }
                         if (row.firstStatus ==180 || row.lastStatus == 180 ){
                             actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="check(\'' + row.id + '\')" ><i class="fa fa-edit"></i>质检</a> ');
                         }*/
                        if (row.firstStatus == 200 && row.lastStatus == 200)
                            actions.push('<a class="btn btn-primary btn-xs to-receive" ' + addFlag + ' onclick="Toreceiving(\'' + row.code + '\')"><i class="fa fa-cart-plus"></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.receiptType == 'outsourced_r' || row.receiptType == 'purchase_r') {
                            if (row.isReturnSrm == 0) {
                                actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="returnSrm(\'' + row.id + '\')"><i class="fa fa-edit"></i>SRM</a> ');
                            }

                        }
                        /*if(row.firstStatus!=900){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="receive(\''+row.id+'\')"><i class="fa fa-upload"></i>确认回传</a>');

                        }*/
                        // if (row.firstStatus == 800 && row.lastStatus == 800) {
                        //     actions.push('<a class="btn btn-info btn-xs ' + receiveFlag + '" href="#" onclick="backERP(\''+row.id+'\')"><i class="fa fa-upload"></i>回传</a>');
                        // }
                        return actions.join('');
                    }
                },
                {
                    field: 'createdBy',
                    title: '创建用户',
                    sortable: true
                },
                {
                    field: 'created',
                    title: '创建时间',
                    formatter: function (value, row, index) {
                        let time = value.slice(5, 10);
                        return `<span>${time}</span>`
                    }
                },
                {
                    field: 'id',
                    title: '入库单id',
                    sortable: true,
                    visible: false,
                },
                {
                    field: 'receiptType',
                    title: '入库类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(receiptTypes, function (index, dict) {
                            if (dict.code == value) {
                                actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },

                {
                    field: 'companyCode',
                    title: '货主',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(company, function (index, dict) {
                            if (dict.code == value) {
                                actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },

                {
                    field: 'warehouseCode',
                    title: '仓库编码',
                    visible: false
                },
                {
                    field: 'uWarehouseName',
                    title: 'U8仓库',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value) {
                            actions.push("<span class='badge badge-info'>" + value + "</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'supplierName',
                    title: '供应商',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value;
                        // var actions = [];
                        // $.each(supplier, function (index, dict) {
                        //     if (dict.code == value) {
                        //         actions.push("<span >" + dict.name + "</span>");
                        //         return false;
                        //     }
                        // });
                        // return actions.join('');
                    }
                },

                {
                    field: 'totalQty',
                    title: '总数量'
                },
                {
                    field: 'totalLines',
                    title: '总行数'
                },
                {
                    field: 'firstStatus',
                    title: '头状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(receiptHeaderStatus, value);
                    }
                },
                {
                    field: 'lastStatus',
                    title: '尾状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(receiptHeaderStatus, value);
                    }
                },
                {
                    field: 'referCode',
                    title: '上游单号',
                    sortable: true
                },
                {
                    field: 'created',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'lastUpdated',
                    title: '最后修改时间',
                    visible: false,
                    sortable: true
                },
                {
                    field: 'lastUpdatedBy',
                    title: '更新用户',
                    visible: false,
                },
                {
                    field: 'backMsg',
                    title: '回传信息',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 8, "open");
                    }

                },
                {
                    field: 'code',
                    title: '入库单号',
                },
                {
                    field: 'userDef2',
                    title: '自定义字段2',
                    visible: false
                },
                {
                    field: 'userDef3',
                    title: '自定义字段3',
                    visible: false
                }]
        };
        $.table.init(options);
    });

    $("#bootstrap-table1").bootstrapTable({
        // url: detailPrefix + "/list",
        createUrl: detailPrefix + "/add",
        updateUrl: detailPrefix + "/edit/{id}",
        removeUrl: detailPrefix + "/remove",

        // search: true, //搜索
        sortable: true, //排序
        showRefresh: true, //刷新
        showToggle: true, //视图切换
        clickToSelect: true,
        showColumns: true, //列选择
        // detailView:true,
        showExport: true, //导出
        exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库明细",
        sortName: "lastUpdated",
        sortOrder: "desc",
        iconSize: "outline",
        toolbar: "#toolbar1",
        contentType: "application/x-www-form-urlencoded",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 10,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50, 100],                             // 可供选择的每页的行数(*)
        onRefresh: function () {
            loadDetail();
        },
        columns: [{
            checkbox: true
        },
            {
                title: '操作',
                align: 'center',
                events: 'operateEvents',
                formatter: function (value, row, index) {
                    // console.log(detailWarehouse)
                    var actions = [];
                    actions.push('<a id="table_edit" class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a id="table_edit" class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editHeader(\'' + row.receiptId + '\')"><i class="fa fa-edit"></i>编辑主表</a> ');

                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.id + '\')"><i class="fa fa-trash-o"></i>删除</a>');
                    return actions.join('');
                }
            },
            {
                field: 'id',
                title: 'id',
                visible: false
            },
            {
                field: 'receiptId',
                title: 'receiptId',
                visible: false
            },
            {
                field: 'receiptCode',
                title: '入库单编码',
                visible: false
            },
            {
                field: 'materialCode',
                title: '物料编码'
            },
            {
                field: 'materialName',
                title: '物料名称'
            },
            {
                field: 'materialSpec',
                title: '物料规格'
            },

            {
                field: 'materialUnit',
                title: '物料单位'
            },

            {
                field: 'uWarehouseCode',
                title: 'U8仓库',
                formatter: function (value, row, index) {
                    // console.log(value)
                    // console.log(row.companyCode)
                    // console.log(uWarehouseNames)
                    for (let item of uWarehouseNames) {
                        if (item.companyCode == row.companyCode && item.uWarehouseCode == value) {
                            return item.uWarehouseName;
                        }
                    }
                }
            },
            // {
            //     field: 'projectNo',
            //     title: '项目号',
            // },
            {
                field: 'moCode',
                title: '工作令号',
            },
            {
                field: 'materialUnitZh',
                title: '单位说明'
            },
            {
                field: 'qcCheck',
                title: '是否质检',
                align: "center",
                formatter: function (value, row, index) {
                    var actions = [];
                    if (value == 0) {
                        actions.push("<span class='badge badge-info'>是</span>");
                    } else {
                        actions.push("<span class='badge badge-info'>否</span>");
                    }
                    return actions.join('');
                },
                visible: false
            },
            {
                field: 'supplierCode',
                title: '供应商编码',
                visible: false
            },
            {
                field: 'batch',
                title: '批次',
                visible: false
            },
            {
                field: 'lot',
                title: '批号',
                visible: false
            },
            {
                field: 'projectNo',
                title: '项目号',
                visible: false
            },
            {
                field: 'manufactureDate',
                title: '生产日期',
                visible: false
            },
            {
                field: 'expirationDate',
                title: '失效日期',
                visible: false
            },
            {
                field: 'agingDate',
                title: '入库日期',
                visible: false
            },
            {
                field: 'qty',
                title: '单据数量'
            },
            {
                field: 'taskQty',
                title: '已收数量'
            },
            {
                field: 'inventoryQty',
                title: '库存数量'
            },
            {
                field: 'referCode',
                title: 'ERP单号',
                visible: false
            },
            {
                field: 'referId',
                title: 'ERP内部号',
                visible: false
            },
            {
                field: 'referLineNum',
                title: 'ERP行号',
                visible: false
            },
            {
                field: 'locatingRule',
                title: '定位规则',
                visible: false
            },
            {
                field: 'inventorySts',
                title: '库存状态',
                visible: false
            },
            {
                field: 'itemListPrice',
                title: '标价',
                visible: false
            },
            {
                field: 'itemNetPrice',
                title: '净价',
                visible: false
            },
            {
                field: 'price',
                title: '单价',
                visible: false
            },
            {
                field: 'statusFlowCode',
                title: '流程编码',
                visible: false
            },
            // {
            //     field: 'isVirtualBom',
            //     title: '是否虚拟套件',
            //     align: "center",
            //     formatter: function (value, row, index) {
            //         return $.table.selectDictLabel(isVirtualBoms, value);
            //     },
            //     visible: false
            // },
            {
                field: 'created',
                title: '创建时间'
            },
            {
                field: 'color',
                title: '颜色'
            },
            {
                field: 'createdBy',
                title: '创建用户',
                visible: false
            },
            {
                field: 'lastUpdated',
                title: '最后修改时间',
                visible: false
            },
            {
                field: 'lastUpdatedBy',
                title: '更新用户',
                visible: false
            },
            {
                field: 'userDef1',
                title: '自定义字段1',
                visible: false
            },
            {
                field: 'userDef2',
                title: '自定义字段2',
                visible: false
            },
            {
                field: 'userDef3',
                title: '自定义字段3',
                visible: false
            }
        ]
    });

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

    /* 入库单列表-详细 */
    function loadDetail() {


        $.ajax({
            url: ctx + "receipt/receiptHeader/getReceiptHeader",
            type: "post",
            data: {
                id: receiptId
            },
            success: function (value) {
                $('#receiptId').val(value.data.id);
                $('#receiptCode').val(value.data.code);
                receiptCode = value.data.code;
                $('#receiptCompanyId').val(value.data.companyId);
                $('#receiptCompanyCode').val(value.data.companyCode);
                $('#referCode').val(value.data.referCode);
                $('#referType').val(value.data.referType);
                $('#receiptTotalQty').val(value.data.totalQty);
                $('#receiptTotalLines').val(value.data.totalLines);


            }
        })
        $.ajax({
            url: ctx + 'receipt/receiptDetail/list',
            type: "post",
            data: {
                receiptId: receiptId,
            },
            success: function (value) {
                $("#bootstrap-table1").bootstrapTable('load', value.data);
            }
        });
    }

    //组盘信息
    function createStation(receiptCode) {
        let code = receiptCode;
        let url = detailPrefix + "/receiptContainerDetails/" + code;
        $.modal.open("组盘信息", url);
    }

    /* 打印 */
    function receiptPrint(id) {
        var url = prefix + "/report/" + id;
        $.modal.open("入库单打印", url);
    }

    /* 新增主表 */
    function add() {
        if (receiptId == '') {
            $.modal.open("未选择入库单", "error/404.html");
        } else {
            table.set("bootstrap-table1");
            var url = detailPrefix + "/add/" + receiptId + "/" + receiptCode;
            $.modal.open("添加" + table.options.modalName, url);
        }
    }

    /* 编辑主表 */
    function edit(id) {
        var url = detailUpdateUrl.replace("{id}", id);
        $.modal.open("修改入库单明细", url);
    }

    /* 编辑主表 */
    function editHeader(id) {
        var url = prefix + "/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};
            $.operate.submit(url, "post", "json", data);
            setTimeout(gotoindex, 1000);//延时3秒执行页面跳转方法
            function gotoindex() {
                loadDetail();
            }

        });
    }

    /* 批量删除主表 */
    function batRemove() {
        var rows = $("#bootstrap-table1").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
            var url = detailRemoveUrl;
            var ids = "";
            for (var i = 0; i < rows.length; i++) {
                ids = ids + rows[i].id + ","
            }
            var data = {"ids": ids.substring(0, ids.length - 1)};
            $.operate.submit(url, "post", "json", data);
            setTimeout(gotoindex, 1000);//延时3秒执行页面跳转方法
            function gotoindex() {
                loadDetail();

            }
        });
    }

    function batUWarehouse() {
        var rows = $("#bootstrap-table1").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        let companyCode = rows[0].companyCode;
        let warehouseCode = rows[0].warehouseCode;
        let ids = rows[0].id;
        for (let i = 1; i < rows.length; i++) {
            if (rows[i].processStatus > 0) {
                $.modal.alertError("存在已操作的记录,不能批量修改:" + row[i].materialCode);
                return;
            }
            ids = ids + "," + rows[i].id;
        }
        var url = detailPrefix + "/batUWarehouse/" + ids + "/" + companyCode + "/" + warehouseCode;
        $.modal.open("修改主表", url);
    }

    //提交
    function submit(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();
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            }
        };
        $.ajax(config)
    }

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

        var url = detailPrefix + "/report/" + ids;
        $.modal.open("入库铭牌打印", url);
    }

    /* 收货 */
    function Toreceiving(code) {
        let storage = window.localStorage;
        storage.receiving_code = code;
        createMenuItem(ctx + "receipt/receiving", "收货");
        parent.$('.tabReload').click();
    }

    function returnSrm(id) {
        var url = ctx + 'task/taskHeader/handleBack';
        var data = {"receiptId": id};
        $.operate.post(url, data);
    }

    /* 收货 */
    function ToreceivingSn(code) {
        let storage = window.localStorage;
        storage.receiving_code = code;
        createMenuItem(ctx + "receipt/receiving/receivingSn", "SN收货");
        parent.$('.tabReload').click();
    }

    /* 点击明细面板 */
    $("#myTab li:eq(1)").click(function () {
        detail(receiptId, "");
    });

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


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

    function queryParams(params) {
        var curParams = {
            // 传递参数查询参数
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order,
            status: status,

        };
        return curParams
    }


    function yueku() {
        let rows = $.table.selectColumns("id");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        let url = prefix + "/yueku";
        let data = {"ids": rows.join()};
        $.operate.submit(url, "post", "json", data);
    }
</script>
</body>
</html>