addtalk.html 6.1 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="divport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>发动态</title>
    <link rel="stylesheet" href="__TMPL__/public/assets/css/init.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/swiper-3.4.2.min.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_793738_etrccfh2qxm.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/diseaseColumn.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/ChatCircle.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/chat.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/weui.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/myweui.css">
    <script src="__TMPL__/public/assets/js/fontsize.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>
<body>
<div class='box'>
    <div class='textarea_box'>
        <textarea class='textarea' placeholder=''></textarea>
    </div>
    <div class="weui-uploader">
        <div class="weui-uploader__hd">
            <p class="title">上传图片(最多九张)</p>
        </div>
        <div class="weui-uploader__bd">
            <ul class="weui-uploader__files" id="uploaderFiles">
            </ul>
            <div class="weui-uploader__input-box addpic">
                <!--<input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple/>-->
            </div>
        </div>
    </div>
</div>
<!--dibu-->
<div class="null_box"></div>
<div class="submit_btn">发布</div>
<script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
<script src="__TMPL__/public/assets/js/weui.js"></script>
<script src="__TMPL__/public/assets/js/myweui.js"></script>
<!--<script>
    $(function () {
        var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
            $gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
            $uploaderInput = $("#uploaderInput"),
            $uploaderFiles = $("#uploaderFiles");

        $uploaderInput.on("change", function (e) {
            var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
            for (var i = 0, len = files.length; i < len; ++i) {
                var file = files[i];
                console.log(file);
                if (url) {
                    src = url.createObjectURL(file);
                } else {
                    src = e.target.result;
                }
                console.log(src);
                $uploaderFiles.append($(tmpl.replace('#url#', src)));
            }
        });

        $uploaderFiles.on("click", "li", function () {
            $galleryImg.attr("style", this.getAttribute("style"));

            $gallery.fadeIn(100);
        });

        $gallery.on("click", function () {
            $gallery.fadeOut(100);
        });
    });
    $('.submit_btn').on('click',function (e) {
       /*获取页面的所有信息*/
        var textinfo=$('textarea').val();
        console.log(textinfo);


    })
</script>-->

<script type="application/javascript">
    var serverIds = '';
    wx.config({$sdk});
    $('.addpic').on('click',function (res) {
        console.log(11111);
        var length = $('.length').length;
        if(length>=9){
            alert('不能上传了')
            $('#addpic').hide();
            return false;
        }
        wx.chooseImage({
            count: 9-length, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
            success: function (res) {
//							alert(res.localIds);
//							alert(res.localIds.length);
                console.log(res.localIds);
                console.log(1111111111);
                for(var i=0;i<res.localIds.length;i++){
                    // $('.addpic').before('<img style="width:100px;height:100px;" class="length" src="'+res.localIds[i]+'"/>')
                    $('.addpic').before('<li class="weui-uploader__file length" src="'+res.localIds[i]+'" style="background-image:url('+res.localIds[i]+')"></li>')
                }
               uploadImages(res.localIds)// 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
            }
        });
    })

    function uploadImages(localIds) {
        var localId = localIds.pop();
        wx.uploadImage({
            localId: localId,
            isShowProgressTips: 1,
            success: function (res) {
                var serverId = res.serverId; // 返回图片的服务器端ID
                console.log(serverId);

                serverIds += serverId + ',';
                if (localIds.length > 0) {
                    uploadImages(localIds);
                }
            },
            fail: function (res) {
                $modal.toast(JSON.stringify(res));
            }
        });
    }

    $('.submit_btn').on('click',function (e) {
        /*获取页面的所有信息*/
        var textinfo=$('textarea').val();
       if (!textinfo){
           alert('内容不能为空');
           return;
       }
        var picture=new Array()
        var length = $('.length').length;
       console.log(length);
        for(var i=0;i<length;i++){
            picture[i]=$('.length').eq(i).attr('src');
        }
        console.log(i);
        console.log(picture);
        $.ajax({
            url: "{:url('addPost')}",
            type: "post",
            num:i,
            data: {
                group_id:{$group_id},
                'num':i,
                'post_content': textinfo,
                'media': serverIds
            },
            success: function (data) {
               if (data==1){
                   alert('发布成功!增加{$firend}积分');
                   window.location.href='{:url('index')}'
               } else {
                   alert('发布失败!');
               }
            }
        })



    })

</script>
</body>
</html>