

let el = {
    id:'#id',
    purchaseMethod3:'#purchaseMethod3'
};


$(function () {
    $("#purchaseMethodTow").combobox({
        // url: g.ctx + 'pc/sys/dict/getDicByType?type=purchase_method',
        // method: 'GET',
        valueField: 'code',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---',
        editable: false,
        panelHeight: 'auto',
        data: [
            {codeWithDesc: '询价', code: 'Z0011'},
            {codeWithDesc: '招标', code: 'Z002'},
            {codeWithDesc: '震坤行商城', code: 'Z003'},
            {codeWithDesc: '未转', code: 'Z005'}
        ],
        onLoadSuccess: function(){  // 数据加载成功后的回调函数
            $(this).combobox('select', $(el.purchaseMethod3).val());  // 选择值为'1'的项
        }
    });
});


// 保存配额
function savePurchaseMethod(call) {
    // var purchaseMethod = $("#purchaseMethodTow").val();
    var purchaseMethod = $('#purchaseMethodTow').combobox('getValue');


    if ( purchaseMethod === null || purchaseMethod === undefined || purchaseMethod === '' || purchaseMethod === '0'){
        layer.msg('请选择采购方式');
        return ;
    }
    let loadIndex = layer.load(2);
    $.ajax({
        url: g.ctx + 'pc/inquiry/purchase/apply/bill/detail/rest/updateDetailMethod',
        type: "POST",
        contentType: 'application/json',
        data: JSON.stringify({
            id: $(el.id).val(),
            purchaseMethod: purchaseMethod
        }),
        success: function (data) {
            layer.close(loadIndex);
            // if (data) {
            //     parent.layer.msg('保存成功', {icon: 1, time: 2000});
            //     closeLayer();
            // } else {
            //     parent.layer.msg('保存失败：' + data.msg, {icon: 2, time: 2000});
            // }
            call();
        },
        error: function (data) {
            layer.close(loadIndex);
            topWin.layer.alert(data.responseJSON.message, {icon: 2});
        }
    });

}

/**
 * 关闭弹框
 */
function closeLayer() {
    parent.layer.closeAll();
}
