var el = {
    form : '#form',
    useState: '#useState',
    attachment: '#attachment',
}
$(function () {
    // 初始化维度下拉框
    $('#dc').combobox({
        valueField: 'code',
        textField: 'name',
        url: g.ctx + 'pc/tender/expertManage/rest/dc/listAll',
        editable: false,
        prompt: '--- 请选择 ---',
        panelHeight: 'auto',
        panelWidth: 300,
        onSelect:function (data) {
            $('#typeNames').textbox('setValue',data.typeNames);
        }
    });
});
 function saveOrUpdate(call) {
    if (!$(el.form).form('validate')) {
        layer.msg("必填项未填写!");
        return
    }
    var array = $(el.form).serializeArray();
    var person = {};
    person.id = id;
    var dcArray = [];
    var category=[];
    person.userId = 0;
    $.each(array, function (index, item) {
        switch (item.name) {
            case 'dc':
                dcArray.push(item.value);
                break;
            default:
                person[item.name] = item.value;
                break;
        }
    });
    person['dimensionCodes'] = dcArray;
    person['categoryId'] = category;
    $.ajax({
        url: g.ctx + 'pc/tender/expertManage/rest/saveOrUpdate',
        type: 'post',
        contentType: 'application/json',
        data: JSON.stringify(person),
        success: function (data) {
            layer.msg("操作成功!");
            call();
        },
            complete: function(data) {
                top.layer.close(loading);
            },
            error: function (data) {
                layer.alert(JSON.parse(data.responseText).message);
            }
        });

}
// 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/tender/expertManage/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 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);
                        $("#supplierCode").val(cbox.supplierCode);
                        $('#supplierName').textbox('setValue', cbox.supplierName)
                        userOrgyDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    userOrgyDialog.dialog('close');
                }
            }
        ]
    });
}