var processGridManager = null;
$(document).ready(function () {
    loadProcessListGrid();
    bindQueryEvent();
});
function loadProcessListGrid(){
    var toolbarOptions = UICtrl.getDefaultToolbarOptions({
        addHandler: function(){
            UICtrl.addGridRow(processGridManager);
        },
        deleteHandler: function () {
            var _grid = UICtrl.getGridManager('#processListGrid');
            DataUtil.delSelectedRows({
                action: 'technologyProcess/deleteTechnologyProcess.ajax',
                param: {},
                gridManager: _grid,
                idFieldName: 'technologyProcessId',
                onSuccess: function () {
                    reloadGrid();
                }
            });
        }
    });
    processGridManager =  UICtrl.grid("#processListGrid", {
        columns: [
            { display: "工序名称", name: "processName", width: 120, minWidth: 60, type: "string", align: "left",
                editor: {
                    required: true, type: "select",
                    data: {
                        type: 'system',
                        name: "processNameGroup",
                        back: {
                            processId: "processId",
                            processName:"processName",
                            processType:"processType",
                            processTypeTextView:"processTypeTextView",
                            workHours:"workHours",
                            processContent:"processContent",
                            processRemark:"processRemark",
                        }
                    },
                }
            },
            { display: "工序类别", name: "processTypeTextView", width: 120, minWidth: 60, type: "string", align: "left",
                /*editor : {
                    type : 'combobox',
                    data : $("#processType").combox('getJSONData'),
                    required : true,
                    valueField : 'processType'
                }*/
            },
            { display: "工时", name: "workHours", width: 120, minWidth: 60, type: "number", align: "left",
                /*editor: {
                    required: true,
                    type: 'text',
                    mask: 'positiveMoney'
                }*/
            },
            { display: "工序内容", name: "processContent", width: 180, minWidth: 60, type: "string", align: "left",
                /*editor: {
                    required: true,
                    type: 'text'
                }*/
            },
            { display: "工序说明", name: "processRemark", width: 180, minWidth: 60, type: "string", align: "left",
                /*editor: {
                    required: true,
                    type: 'text'
                }*/
            },
            {display: '资源', name: "resourceName", width: 180, align: "left", type: "string",
                editor: {
                    required: true, type: "select",
                    data: {
                        type: 'system',
                        name: "resourceNameGroup",
                        getParam: function (item) {
                            return {paramValue: item.processType}
                        },
                        back: {
                            gxmc: "resourceName",
                            id: "resourceId"
                        }
                    },
                }
            },
            { display: "工序物料", name: "materialName", width: 180, minWidth: 60, type: "string", align: "left",
                editor: {
                    required: false,
                    type: 'text'
                }
            },
        ],
        dataAction: "server",
        url: web_app.name + '/technologyProcess/slicedTechnologyProcessList.ajax',
        parms:{technologyId:$("#technologyId").val()},
        pageSize: 20,
        usePager: true,
        toolbar: toolbarOptions,
        enabledEdit: true,
        width: "98%",
        height: 500,
        heightDiff: -8,
        checkbox: true,
        fixedCellHeight: true,
        selectRowButtonOnly: true,
    });
    UICtrl.setSearchAreaToggle(processGridManager);
}

function bindQueryEvent() {
    $('#productName').searchbox({
        type: "product", name: "productCode",
        onChange: function (value, data) {
            $('#productId').val(data.productId);
            $('#productName').val(data.productName);
        }
    });
}

