/**
 * [OElove] (C)2010-2099 oelove.com  biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/11/11 by BO $
*/
$(function() {
    
    //user通用初始化上传
    $("[f='but_upload_image']").each(function(index, e){
        //e.getAttribute('data-mod');
        var up_id = $(e).attr('id');
        var module = $(e).attr('data-mod');
        if (typeof(module) == 'undefined') {
            module = 'upload';
        }
        var thumb = $(e).attr('data-thumb');
        if (typeof(thumb) == 'undefined') {
            thumb = '';
        }
        var forbidcom = $(e).attr('data-forbidcom');
        if (typeof(forbidcom) == 'undefined') {
            forbidcom = '';
        }
        var forbidwater = $(e).attr('data-forbidwater');
        if (typeof(forbidwater) == 'undefined') {
            forbidwater = '';
        }
        
        //实例化上传控件
        var upload = new OEUploader({
            el: "#"+up_id,
            data:{
                'uploadpart':'file', 'module':module, 
                'thumb':thumb, 'forbidcom':forbidcom, 'forbidwater':forbidwater
            },
            url: _OE_FILE+'&c=index&a=upload'
        });
        
        upload.on("success", function(data){
            var response = data.response;
            var result = data.result;
            var imgthumb = data.thumbimg;
            var imgurl = data.uploadimg;
            var base64img = data.base64img;
            if (typeof(base64img) == 'undefined') {
                base64img = '';
            }
            var attid = data.attid;
            if (typeof(attid) == 'undefined') {
                attid = '';
            }
            if (response == '1') {
                if ($("#"+up_id+"_thumb").length > 0) {
                    $("#"+up_id+"_thumb").val(imgthumb);
                }
                if ($("#"+up_id+"_url").length > 0) {
                    $("#"+up_id+"_url").val(imgurl);
                }
                if ($("#"+up_id+"_preview").length > 0) {
                    var img = _ROOT_PATH+imgurl;
                    $("#"+up_id+"_preview").attr("src", img);
                    $("#"+up_id+"_preview").show();
                }
                //同步云存储
                _oeloveFileSynYun(attid);
            }
            else {
                if (result == '' || result == null) {
                    result = '上传失败，请检查';
                }
                OEUI.message.msg({
                    text: result
                });
            }
            
        });
    });
    
});