var el = {
    form: '#form',
    useState: '#useState',
    attachment: '#attachment',
}
$(function () {

});

function saveOrUpdate(call) {
    if ($(el.form).form('validate')) {
        var formData = $(el.form).serializeJson();
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/sys/mold/moldForm/rest/moldMove/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 searchSupplier() {
    var userOrgyDialog = openDialog('userOrgyDialog', g.ctx + 'pc/supplier/supplierSelect?single=1', {
        title: "选择供应商",
        width: '800px',
        height: '500px',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            userOrgyDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.confirm,
                handler: function () {
                    topWin.frames['userOrgyDialog'].chooseRow(function (cbox) {
                        console.log(cbox)
                        $("#supplierId").val(cbox.id);
                        //$("#supplierName").val(cbox.supplierName);
                        $('#supplierCode').textbox('setValue', cbox.supplierCode)
                        $('#supplierName').textbox('setValue', cbox.supplierName)
                        userOrgyDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    userOrgyDialog.dialog('close');
                }
            }
        ]
    });

}

function delFactory(call) {
    if ($(el.form).form('validate')) {
        var formData = $(el.form).serializeJson();
        // var moldId = formData.moldId
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/sys/mold/moldForm/rest/moldMove/remove',
            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("红色框为必输项，请填写！");
    }
    // if ($(el.form).form('validate')) {
    //     var formData = $(el.form).serializeJson();
    //     parent.layer.confirm('是否删除？', function (index) {
    //         var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
    //         var url = g.ctx + 'pc/sys/mold/moldForm/rest/moldMove/remove';
    //         $.ajax({
    //             url: url,
    //             method: "post",
    //             data: formData,
    //             success: function (data) {
    //                 parent.layer.close(index);
    //                 $(el.tb).datagrid('reload');
    //             },
    //             complete: function (data) {
    //                 top.layer.close(loading);
    //             },
    //             error: function (data) {
    //                 layer.close(index);
    //                 layer.alert(JSON.parse(data.responseText).message);
    //             }
    //         });
    //     });
    // } else {
    //     layer.msg("红色框为必输项，请填写！");
    // }
}