/**
 *
 * @author BOGON
 * @version 1.0
 */
'use strict';
var el = {
    lifnr: '#lifnr',
    werks:'#werks',
    supplierName: '#supplierName',
    matnr: '#matnr',
    materialName: '#materialName',
    ebeln: '#ebeln',
    bwart: '#bwart',
    pgName: '#pgName',
    createTimeStart: '#createTimeStart',
    createTimeEnd: '#createTimeEnd',
    bodyHeight: document.documentElement.clientHeight
};


$(function () {
    page.inittb();
    initQuery();
})
var page = {
    inittb: function () {
        const col = [[{
            title: '移动类型', field: 'bwart', width: 120, align: 'left'
        }, {
            title: 'SAP订单号', field: 'ebeln', width: 120, align: 'left'
        }, /*{
            field: 'zlsdh', title: 'SC订单号', width: 90
        },*/ {
            title: '订单行号', field: 'ebelp', width: 120, align: 'left'
        }, {
            title: '物料编号', field: 'matnr', width: 120, align: 'left'
        }, {
            field: 'materialName', title: '物料名称', width: 280, align: 'left', //sortable: true
        }, /*{
            field: 'specs', title: '物料规格', width: 280, lign: 'left'
        },*/ {
            title: '移动数量', field: 'menge', width: 120, align: 'left'
        }, {
            title: '计量单位', field: 'meins', width: 120, align: 'left'
        }, {
            title: '退货原因', field: 'zremark', width: 120, align: 'left'
        }, {
            field: 'pgName',
            title: '采购组',
            width: 110,
            sortable: true,
            prop: 'pgName',
            formatter: function (value, row) {
                if (value) {
                    return '(' + row.pgCode + ')' + value;
                }
                return '';
            }
        }, {
            title: '供应商编码', field: 'lifnr', width: 120, align: 'left'
        }, {
            field: 'supplierName', title: '供应商名称', width: 190, // sortable: true
        }, {
            title: '工厂', field: 'werks', width: 120, align: 'left'
        }, {
            title: '工厂名称', field: 'factoryName', width: 120, align: 'left'
        }, {
            title: '辅助数量', field: 'erfmg', width: 120, align: 'left'
        }, {
            title: '辅助单位', field: 'erfme', width: 120, align: 'left'
        }, {
            title: '制单人', field: 'usnam', width: 120, align: 'left'
        }, {
            title: '物料凭证编号', field: 'mblnr', width: 120, align: 'left'
        }, {
            title: '物料凭证项目', field: 'zeile', width: 120, align: 'left'
        }, {
            title: '凭证中的过帐日期', field: 'budat', width: 120, align: 'left'
        }, {
            title: '凭证的年份', field: 'mjahr', width: 120, align: 'left'
        }, {
            title: '扣款比例', field: 'zkkbl', width: 120, align: 'left'
        }, {
            title: '送货单号', field: 'zzshdh', width: 120, align: 'left', formatter: function (value, row) {
                return "<a href='javascript:void(0)' onclick=\"lookUpDetail('" + value + "')\">" + value + "</a>";
            }
        }, {
            title: '送货单行号', field: 'zzshdhxm', width: 120, align: 'left'
        }, {
            title: '质检单号', field: 'prueflos', width: 120, align: 'left'
        }, {
            title: '参考凭证的凭证号', field: 'lfbnr', width: 120, align: 'left'
        }, {
            title: '参考凭证年度', field: 'lfbja', width: 120, align: 'left'
        }, {
            title: '参考凭证项目', field: 'lfpos', width: 120, align: 'left'
        }, {
            title: '凭证抬头文本', field: 'bktxt', width: 120, align: 'left'
        }, {
            title: '库存地点', field: 'lgort', width: 120, align: 'left'
        }, {
            title: '凭证日期', field: 'bldat', width: 120, align: 'left'
        }, {
            title: '税率', field: 'mwskz', width: 120, align: 'left'
        }, {
            title: '创建时间',
            field: 'createTime',
            width: 120,
            align: 'left',
            formatter: function (value, row, index) {
                // return moment(page.formatterDate(value)).format("YYYY-MM-DD HH:mm");
                return moment(value).format("YYYY-MM-DD HH:mm");
            }

        }]]
        //var searchHeight = $(el.searchForm).outerHeight() - 10;
        //var pager = initGridPager(el.bodyHeight - searchHeight * 2 - 120, 40);
        $('#tb').datagrid({
            iconCls: 'icon-list',
            width: '100%',
            url: g.ctx + 'pc/order/goodReceipt/rest/list',
            method: 'GET',
            height: $(window).height() - $('#searchForm').outerHeight() - 10,
            singleSelect: true,
            pagination: true,
            loadMsg: "数据加载中......",
            rownumbers: true,
            fitColumns: false,
            nowrap: true,
            remoteSort: false,
            striped: true,
            page: 1,
            pageSize: 20,
            toolbar: [ {
                text: '导出',
                iconCls: 'icon-import',
                handler: function () {
                    setOperationLog("导出按钮", "退货凭证查询");
                    openExportDialog('pc/order/goodReceipt/rest/export','tb',{lfbnr:$(el.lfbnr).val(),ebeln:$(el.ebeln).val(),pgName:$(el.pgName).val(),lifnr:$(el.lifnr).val(),matnr:$(el.matnr).val(),materialName:$(el.materialName).val(),createTimeStart:$(el.createTimeStart).val(),createTimeEnd:$(el.createTimeEnd).val(),supplierName:$(el.supplierName).val(),bwart:$(el.bwart).val(),werks:$(el.werks).val()});
                }
            }],
            queryParams: {
                page: 1, rows: 10, // postTimeStart:$('#postTimeStart').datebox('getValue'),
                // postTimeEnd:$('#postTimeEnd').datebox('getValue')
            },
            columns: col
        });
    }
}

//初始化查询
function initQuery() {
    $(el.bwart).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=movement_type',
        method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false
    });


    $(el.werks).combobox({
        url: g.ctx + 'pc/sys/factory/rest/listAll',
        editable: false,
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
        onLoadSuccess: function () { //加载完成后,设置选中第一项
            var val = $(this).combobox("getData");
            for (var item in val[0]) {
                if (item === "code") {
                    $(this).combobox("select", val[0][item]);
                    loadGrid();
                }
            }
        }
    });

}

function lookUpDetail(no) {
    var url = g.ctx + "pc/order/deliveryOrder/page/createOrUpdate?type=2&no=" +no;
    var deliveryCreateDialog =openDialog("deliveryCreateDialog", url, {
        title: '送货单查看',
        width: '100%',
        height: '100%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            deliveryCreateDialog.dialog('destroy');
        },
        buttons: [{
            text: '关闭', iconCls: 'icon-cancel', handler: function () {
                deliveryCreateDialog.dialog('close');
            }
        }]
    })
    /*openMainLayerWinPlus("查看", '/delivery/order/detail?no=' + no, "75%", "93%", function () {
    });*/
}



