var el = {
    form : '#form',
    qualityNotice: '#qualityNotice',
    emptyTd: '.empty-td',
    qualityNoticeData: '.quality_notice_data',
    qualityNoticeCode: '#qualityNoticeCode',
    suppllierName: '#suppllierName',
    badReason: '#badReason',
    problemSource: '#problemSource',
    auditAttachment: '#auditAttachment',
    ncrAttachment: '#ncrAttachment',
    planAuditTimeStr: '#planAuditTimeStr',
    userIdMap: {},
}


/**
 * 初始化页面特殊输入框
 */
$(function () {
    timeSelect();
    // 初始化稽核原因下拉框
    $('#auditReason').combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=audit_reason',
        panelHeight: 260,
        method: 'GET',
        valueField: 'code',
        textField: 'name',
        prompt: '-- 请选择 --',
        editable: false
    });
    // 初始化稽核结果下拉框
    $('#auditResult').combobox({
        url: g.ctx + 'pc/sys/dict/getDicByType?type=audit_result',
        panelHeight: 260,
        method: 'GET',
        valueField: 'code',
        textField: 'name',
        prompt: '-- 请选择 --',
        editable: false
    });
    //是否为风险供应商
    $('#isRiskSupplier').combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        value:"1",
        data: [
            {value: '0', label: '是'},
            {value: '1', label: '否'}
        ],
        // multiple: true,
    });
    // 初始化公司下拉框
    $('#companyCode').combobox({
        valueField: 'companyCode',
        textField: 'dataPrimary',
        url: g.ctx + 'pc/sys/company/rest/listAll',
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
        panelWidth: 300,
        onSelect:function (data) {
            $('#companyName').textbox('setValue',data.companyName);
        }
    });


});

/**
 * @param call
 * 编辑和保存
 */

function saveOrUpdate(call) {
    debugger
    if($(el.form).form('validate')){
        var formData = $(el.form).serializeJson();

        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        $.ajax({
            contentType: 'application/json',
            url: g.ctx + 'pc/sys/productGroup/rest/saveOrUpdate',
            method: 'post',
            data: JSON.stringify(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 categorySearch() {
    debugger
var purchaseCategoryDialog = openDialog("purchaseCategoryDialog", g.ctx + 'pc/sys/purchaseCategory/index?select=1', {
    title: '采购品类选择器',
    width: '80%',
    height: '80%',
    cache: false,
    modal: true,
    border: false,
    draggable: false,
    shadow: false,
    onClose: function () {
        purchaseCategoryDialog.dialog('destroy');
    },
    buttons: [{
        text: itablei8n.save,
        handler: function () {
            topWin.frames['purchaseCategoryDialog'].chooseRow(function (row) {
                debugger
                console.log(row.firstLevelPurchaseCode)
                console.log(888888888888888888888888888)
                //$("#categoryCode").val(row.firstLevelPurchaseCode);
                $('#categoryName').textbox('setValue', row.firstLevelPurchaseName);
                $('#categoryCode').textbox('setValue', row.firstLevelPurchaseCode);
                purchaseCategoryDialog.dialog('close');
            });
        }
    }, {
        text: itablei8n.close, handler: function () {
            purchaseCategoryDialog.dialog('close');
        }
    }]
})
}




