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:'提交中...'}); $(function(){ //从后台那边获取签名等信息 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(); } } }); }) 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 name = $("#name").val(), idcard = $("#idcard").val(); var params = { description: suggestContent, type: selectType*1, phone: teleContent, name: name, idcard: idcard, images: serverId ? serverId: "" }; sendPost("/patientFeedback/feedback/saveAppeal", 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(){ mui.back(); },1000) }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show(); } } function validate(){ var content = $.trim($("#question").val()), telephone = $.trim($('#phone').val()), name = $.trim($('#name').val()), idcard = $.trim($('#idcard').val()); if(!selectType){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择类型'}).show(); return false; } if(!content || content.length == 0){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'问题和意见不能为空'}).show(); return false; } if(!name || name.length == 0){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入姓名'}).show(); return false; } if(!idcard || idcard.length == 0){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入身份证号'}).show(); return false; }else{ if (!/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2010)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/i.test(idcard)) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'身份证号格式错误'}).show(); return false; } } if(!telephone || telephone.length == 0){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'手机号码不能为空'}).show(); return false; }else{ if(!/^0?(13[0-9]|15[0-9]|18[0-9]|14[57]|17[0-9]|16[0-9]|19[0-9])[0-9]{8}$/i.test(telephone)){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入有效的手机号码'}).show(); return false; } } return true; } //选择类型 $('.j-select-type').on('tap',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($('#phone').val()); var isValid = validate(); if(isValid){ //先将新增的图片上传然后再处理其他业务 dd.showModal(); var images = getImages(); if(images.length > 0){ uploadImage(); } else{ serverId = ''; doSubmit(); } } }) $("#goToHistory").on('click', function(){ window.location.href = "account-back-list.html"; })