var el = {
    form : '#form',
    useState: '#useState',
    attachment: '#attachment',
}
$(function () {
    //加载模具数据
    // $('#moldId').combobox({
    //     valueField: 'id',
    //     textField: 'moldCode',
    //     url: g.ctx + 'pc/sys/mold/moldForm/rest/listAll',
    //     editable: true,
    //     prompt: '--- 请选择 ---',
    //     panelHeight: 'auto',
    //     panelWidth: 300,
    //     onSelect:function (data) {
    //         $('#moldName').textbox('setValue',data.moldName);
    //     }
    // });
});
function saveOrUpdate(call) {
    if($(el.form).form('validate')){
        var formData = $(el.form).serializeJson();
        var attachData = $(el.attachment).attr('data-fileIds')
        formData.attachment = attachData
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/sys/mold/moldSettings/rest/saveOrUpdate',
            method: 'post',
            data: formData,
            success: function (data) {
                call();
            },
            complete: function(data) {
                top.layer.close(loading);
            },
            error: function (data) {
                layer.alert(JSON.parse(data.responseText).message);
            }
        });
    }else{
        layer.msg("红色框为必输项，请填写！");
    }
}

/**
 * 选择物料页面
 */
function selectMaterial() {
    var selectMaterialElement = openDialog("selectMaterialDialog", g.ctx + 'pc/sys/product/select/dialog?single=1', {
        title: '选择物料',
        width: '80%',
        height: '75%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            selectMaterialElement.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.confirm,
                handler: function () {
                    topWin.frames['selectMaterialDialog'].chooseRows(function (cbox) {console.log(cbox)
                        //$("#supplierId").val(cbox.id);
                        $("#productCode").textbox('setValue',cbox.materialCode);
                        $('#productName').textbox('setValue',cbox.materialName);
                        selectMaterialElement.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    selectMaterialElement.dialog('close');
                }
            }
        ]


    });
}

/**
 * 选择物料页面
 */
function selectMoldForm() {
    var selectMaterialElement = openDialog("selectMaterialDialog", g.ctx + 'pc/sys/mold/moldSettings/select', {
        title: '选择模具',
        width: '80%',
        height: '75%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            selectMaterialElement.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.confirm,
                handler: function () {
                    topWin.frames['selectMaterialDialog'].chooseRows(function (cbox) {console.log(cbox)
                        //$("#supplierId").val(cbox.id);
                        $("#moldCode").textbox('setValue',cbox.moldCode);
                        $('#moldName').textbox('setValue',cbox.moldName);
                        $('#moldId').val(cbox.id);
                        selectMaterialElement.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    selectMaterialElement.dialog('close');
                }
            }
        ]


    });
}
