<link href="<?php echo asset_url('css/fileinput.min.css')?>" media="all" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo asset_url('js/fileinput.min.js') ?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/fileinput_locale_zh.js') ?>"></script>

<style type="text/css">
.form-group{width: 60%} 
#container_map{height: 300px}
.file-footer-buttons button{display: none}
.file-drop-disabled{clear: both;}
.regiswidth div.form-group .form-control-feedback {
    top: 0px!important;
    right: 15px;
}
.regiswidth div.form-group .help-block {
    position: absolute;
    right: 43px;
    top: 3px;
}
.cover {
    margin-top: 20px !important;
}
</style>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
<script src="http://webapi.amap.com/maps?v=1.3&key=93cd0129276159ec3ff4c38a8831492a&plugin=AMap.Geocoder"></script>

<div class="col-md-10" role="main" >
    <nav class="breadcrumb"></i> 分享圈<span class="c-gray en">&gt;</span>云话题管理</nav>
    <div class="xgsj_wbox">
        <div class="title-box" style="border:0;padding: 20px 0px;">
            <p class="t-p" style="width: 500px;display: inline-block;">话题详情</p>
            <form action="<?php echo site_url('sharecircle/topic/goback')?>" method="post">
            <input type="hidden" name="fenyelistback"   value='<?php echo $fenye;?>' > 
            <button type="submit"  class="sjxg_fh" data-dismiss="modal" style="margin-top:8px;width:142px;height:32px;">返回</button>
            </form>
        </div>
        <div class="bs-example">
            <form action="<?php echo site_url('sharecircle/topic/save_topic/' . $topic_info['id'])?>" method="post" class="registerForm regiswidth" enctype="multipart/form-data">
                <div class="form-group" style="margin-bottom: 20px!important">
                    <span class="dianm sjxg_tle_span">*标题：</span>
                    <div class="examp">
                        <input type="text" name="title"  class="form-control" value="<?php echo $topic_info['title']?>" >
                    </div>
                </div>

                <div class="form-group" style="margin-bottom: 10px!important">
                    <span class="dianm sjxg_tle_span">*类型：</span>
                    <div class="examp topic_ex">
                        <select name="typeid" class="selectmr" style="width:100%;height:34px;margin-top:0px" data-bv-notempty="" data-bv-notempty-message="请选择一项" data-bv-field="category">
                            <option value="">请选择类型</option>
                            <?php if (!empty($topic_type)):?>
                                <?php foreach ($topic_type as $value) :?>
                                    <option <?php if($value['id'] == $topic_info['typeid']) { ?> selected="selected" <?php } ?> value="<?php echo $value['id']?>"><?php echo $value['tname']?></option>
                                <?php endforeach; endif; ?>
                        </select>
                    </div>
                </div>

                <div class="form-group form-group2" style="width:60% ;margin-bottom: 20px!important">
                    <span class="smallimg jianjie sjxg_tle_span">*上传列表图：</span>
                    <div class="examp" id="small_container">
                        <p class="shaopupload sjxg_img_btn">
                            <input type="file" name="avatar" id="small" multiple="" class="brefile">
                        </p>
                    </div>
                </div>

                <div class="form-group form-group2" style="width:60% ;margin-bottom: 10px!important">
                    <span class="cover jianjie sjxg_tle_span">*上传封面图：</span>
                    <div class="examp" id="pic_container">
                        <p class="shaopupload shaopupload1 sjxg_img_btn">
                            <input type="file" name="avatar" id="pic" multiple="" class="brefile">
                        </p>
                    </div>
                </div>
               
                <div class="form-group update_topic" style="margin-bottom: 30px!important;">
                    <p class="t-p" style="font-size: 22px; color: #7d7d7d;vertical-align: middle; padding-top: 15px; padding-bottom: 15px;">话题数据</p>
                    <span style="margin-right: 300px;">人气：<?php echo $topic_info['buzzcount']?></span>
                    <span>页显人气：</span><input type="text" name="extracount" class="form-control" value="<?php echo $topic_info['extracount']?>">
                </div>
                <div class="form-group update_topic" style="margin-bottom: 30px!important;">
                    <span>参与人数：<?php echo $topic_info['involcount']?></span>
                     <span style="float:right;margin-right: 392px;">关注人数：<?php echo $topic_info['concerncount']?></span>
                </div>
               <!--  <div class="form-group update_topic" style="margin-bottom: 30px!important;">
                   
                </div> -->
                
                 <button class="edit_btn"  type="submit" style="width:142px;height:32px; margin-top: 20px!important;">提交</button>

                <input type="hidden" value="<?php echo $topic_info['listimg']?>" name="listimg">
                <input type="hidden" value="<?php echo $topic_info['detailimg']?>" name="detailimg">
                 <input type="hidden" name="fenyelist"   value='<?php echo $fenye;?>' > 
            </form>
        </div>
    </div>
</div>

	
<script type="text/javascript">

function init_upload(target, min, max, name, initialPreview, initialPreviewConfig, mode){
	var ele = $(target);
	ele.fileinput({
		minFileCount : min,
		dropZoneEnabled : false,
		maxFileCount : max,       
		validateInitialCount: true,
        overwriteInitial: false,
		uploadUrl : '<?php echo site_url('sharecircle/topic/upload_topic');?>'+'/'+mode,
		language: "zh",
		showUpload : false,
		previewSettings : {
		    image: {width: "130px", height: "auto"},
		    html: {width: "213px", height: "160px"},
		    text: {width: "160px", height: "136px"},
		    video: {width: "213px", height: "160px"},
		    audio: {width: "213px", height: "80px"},
		    flash: {width: "213px", height: "160px"},
		    object: {width: "213px", height: "160px"},
		    other: {width: "160px", height: "160px"}
		},
        initialPreview: initialPreview,
        initialPreviewConfig: initialPreviewConfig
	});

	ele.on('fileuploaded', function(event, data, previewId, index){
		var input = '<input type="hidden" value="'+data.response.url+'" name="'+name+'"/>'
		$(input).appendTo('form');
	});

	ele.on('filebatchselected', function(event, files, extra) {

			$("#save").attr('disabled', false);
	});

	ele.on('fileclear', function(event) {
        $("input[name='"+name+"']").remove();
    });

    ele.on('filedeleted', function(event, key) {
        $("input[name='"+name+"']").eq(key).remove();
    });
}


$(function(){
    var pic_initialPreview = [
        "<img src='<?php echo $topic_info['detailimg'];?>' class='file-preview-image' style='width:130px;height:auto' alt='' title=''><p>原始图片</p>",
    ];
    var small_initialPreview = [
        "<img src='<?php echo $topic_info['listimg'];?>' class='file-preview-image' style='width:130px;height:auto'><p>原始图片</p>",
    ];
    var pic_initialPreviewConfig = [
        {caption: "", width: "130px", url: "", key: ""},
    ];
    var small_initialPreviewConfig = [
        {caption: "", width: "130px", url: "", key: ""},
    ];
    init_upload('#small', 1, 2, 'listimg',small_initialPreview, small_initialPreviewConfig,'small_pics')
    init_upload('#pic', 1, 2, 'detailimg', pic_initialPreview, pic_initialPreviewConfig,'pic')

    $('.registerForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh',
            excluded : ':disabled'
        },

        fields: {
            title: {
                message: '标题无效',
                validators: {
                    notEmpty: {
                        message: '标题不能是空的'
                    },
                    stringLength: {
                        max: 255,
                        message: '标题不能大于255个字符'
                    }
                }
            },
            typeid: {
                message: '类型无效',
                validators: {
                    notEmpty: {
                        message: '类型必须选择'
                    }
                }
            }
        }
    })
    .on('success.form.bv',function(e){
        e.preventDefault();
        var small_num = $('#small_container').find('.file-preview-thumbnails .file-preview-frame').length;
        var pic_num = $('#pic_container').find('.file-preview-thumbnails .file-preview-frame').length;

        if(small_num < 1){
            alert('请上传列表图');
            window.location.href = '#small_container'
            return false;
        }


        if(pic_num < 1){
            alert('请上传封面图');
            window.location.href = '#pic_container'
            return false;
        }

        var form = this;
        e.preventDefault();

        $('#small').on('filebatchuploadcomplete', function(event, files, extra) {
            form_submit(form);
        });
        $('#pic').on('filebatchuploadcomplete', function(event, files, extra) {
            form_submit(form);
        });
        $('#small').fileinput('upload');
        $('#pic').fileinput('upload');
        $('#message_pic').fileinput('upload');

        form_submit(form);
    })

    function form_submit(form){
        var small_upload_num = $('#small').fileinput('getFileStack').length;
        var pic_upload_num = $('#pic').fileinput('getFileStack').length;
        if(small_upload_num == 0 && pic_upload_num == 0){
            form.submit();
        }

    }
})

</script>



