const el = {
    form : '#form',
    useState: '#useState',
    requiredFlag: '#requiredFlag',
    supplierCode: '#supplierCode'
}
$(function () {
    // 初始化出货检验报告是否必填下拉框
    $(el.requiredFlag).combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=required_flag',
        panelHeight: 'auto',
        method: 'GET',
        valueField: 'code',
        textField: 'name',
        prompt: '-- 请选择 --',
        editable: false
    });
});

/**
 * 保存
 */
function saveOrUpdate(call) {
    if($(el.form).form('validate')){
        const formData = $(el.form).serializeJson();
        const loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            url: g.ctx + 'pc/sys/supplierOrderFileSetting/rest/saveOrUpdate',
            method: 'post',
            data: formData,
            success: function () {
                call();
            },
            complete: function() {
                top.layer.close(loading);
            },
            error: function (data) {
                layer.alert(JSON.parse(data.responseText).message);
            }
        });
    }else{
        layer.msg("红色框为必输项，请填写！");
    }
}

/**
 * 打开供应商搜索对话框
 */
function searchSupplier(){
    const 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) {
                        $("#supplierId").val(cbox.id);
                        $("#supplierCode").textbox('setValue',cbox.supplierCode);
                        $('#supplierName').textbox('setValue', cbox.supplierName)
                        userOrgyDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    userOrgyDialog.dialog('close');
                }
            }
        ]
    });
}
