var selectType = '', suggestContent = '', teleContent = '', serverId = "",//储存上传后图片地址 $action_btn = $("#action_btn"); var d = dialog({contentType:'load', skin:'bk-popup'}); var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'}); var userAgent = window.localStorage.getItem(agentName); var pagetype=34; $(function(){ checkUserAgent(); //从后台那边获取签名等信息 var params = {}; params.pageUrl = window.location.href; $.ajax(server + "weixin/getSign", { data: params, dataType: "json", type: "post", success: function(res){ if (res.status == 200) { var t = res.data.timestamp; var noncestr = res.data.noncestr; var signature = res.data.signature; wx.config({ // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: appId, // 必填,公众号的唯一标识 timestamp: t, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature,// 必填,签名,见附录1 jsApiList: [ 'chooseImage', 'uploadImage' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } else{ // dialog({ // title:'提示', // skin:"ui-dialog ax-popup pror", // content:"获取微信签名失败", // ok: function (){} // }).showModal(); console.log("获取微信签名失败"); } } }); }) //重写判断用户是否登录 function checkUserAgent(){ var userAgent = window.localStorage.getItem(agentName); if(!userAgent){ var agentOpenid = window.localStorage.getItem(OpenidAgent); if(!agentOpenid){ var Request = new Object(); Request = GetRequest(); var code = Request["code"]; if(code == "" || code == null || code == undefined){ d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'授权失败'}).show(); } else{ d.show(); var data = {}; data.code = code; sendPost('weixin/getOpenidByCode', data, 'json', 'post', openidFailed, openidSuccess); } } else{ var jsonstr = $.parseJSON(agentOpenid); var openid = jsonstr.openid; window.location.href = server + "wx/html/home/html/login.html?type=" + pagetype + "&openid=" + openid; } } } function chooseImage(){ wx.chooseImage({ count: 3-getImages().length, success: function (res) { for (var i in res.localIds) { appendFile(res.localIds[i]); } } }); } function uploadImage(){ var images = getImages(); if (images.length == 0) { return; } var i = 0, length = images.length; serverId = ""; function upload() { wx.uploadImage({ localId: images[i], isShowProgressTips: 0, success: function (res) { i++; if(serverId.length == 0){ serverId = res.serverId; } else{ serverId =serverId + "," + res.serverId; } if (i < length) { upload(); } if(i == length){ doSubmit(); } }, fail: function (res) { dd.close(); alert(JSON.stringify(res)); } }); } upload(); } // 添加文件 function appendFile(p) { var amount = getImages().length; if (amount >= 2) { $("#add_img_li").hide(); } if(amount < 3){ var $li = $('
  • '); var $add_img_li = $("#add_img_li"); $add_img_li.before($li); } } //获取需要上传的图片 function getImages() { var images = []; $("#img_ul").find(".img-src").each(function() { var imgSrc = $(this).data("src"); images.push(imgSrc); }); return images; } //查看图片 function viewImg(dom) { var $img = $(dom); var thissrc = $img.attr("data-src"); var mWid = $(window).width(); var mHei = $(window).height(); var nHtml = '
    '; $("body").append(nHtml); $(".delimgpop").click(function() { $(this).remove() }); }; //删除图片 function delImg(dom) { var $li = $(dom).parent(); $li.remove(); var amount = getImages().length; if(amount <= 2){ $("#add_img_li").show(); } return; } //微信sdk配置出错 wx.error(function (res) { alert("wx.error:" + res.errMsg); }); //提交 function doSubmit() { var params = {}; params.description = suggestContent; params.type = selectType*1; params.contact = teleContent; params.images = serverId ? serverId: ""; sendPost("patient/feedback/saveFeedback", params,'json','POST',queryFail,querySuccess); } function queryFail(res){ dd.close(); if (res && res.msg) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } } function querySuccess(res){ dd.close(); if(res.status == 200){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'感谢您的反馈'}).show(); setTimeout(function(){ location.reload(); },1000) }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show(); } } //选择类型 $('.j-select-type').on('click',function(){ mui('#popover').popover('toggle'); var $this = $(this); $('#selected_name').text($this.find('a').text()); selectType = $this.data('type'); }); //action 按钮 $action_btn.on('tap', function(){ suggestContent = $.trim($("#question").val()), teleContent = $.trim($('#contact').val()); if(selectType){ if(suggestContent){ if(teleContent){ if(!(/^[1-9]\d{4,10}$/).test(teleContent)){ if(!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(teleContent)){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入有效的QQ、邮箱或手机号码'}).show(); return; } } } //先将新增的图片上传然后再处理其他业务 dd.showModal(); var images = getImages(); if(images.length == 0){ serverId = ''; doSubmit(); } else{ uploadImage(); } }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'问题和意见不能为空'}).show(); return false; } }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择类型'}).show(); return false; } }) //跳转去历史反馈记录页 $("#goToHistory").on('click', function(){ window.location.href = "feedback-records.html"; })