//压缩完后的图片 var compressImages = {}; var dd = dialog({contentType:'load', skin:'bk-popup', content:'保存中...'}); $(function() { /* 选择日期 */ $('input') var opt1 = { preset: 'date', theme: 'ios', lang: 'zh', minDate: new Date(1900, 01, 01) }; $('input[data-time=date]').mobiscroll(opt1); //从后台那边获取签名等信息 var params = {}; params.pageUrl = server + "wx/html/ssgg/html/add-diet-record.html"; $.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 }); } } }); document.getElementById("goback").addEventListener("tap", function() { var date = document.getElementById("date").value; var val = document.getElementById("ys_val").value; var images = getImages(); if (val && date) { } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请填写完整信息'}).show(); return; } var data = {}; data.record_date = date; data.content = val; if(images.length == 0){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择图片'}).show(); return; } else{ dd.showModal(); uploadImage(data); } }); }); //微信sdk配置出错 wx.error(function (res) { alert("wx.error:" + res.errMsg); }); var serverId = ""; function chooseImage(){ wx.chooseImage({ count: 3-getImages().length, success: function (res) { for (var i in res.localIds) { if(i < 3) appendFile(res.localIds[i]); } } }); } function uploadImage(data){ 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 == images.length){ doSubmit(data); } }, fail: function (res) { alert(JSON.stringify(res)); } }); } upload(); } //提交咨询 function doSubmit(data) { data.mediaIds = serverId; //发送ajax请求 sendPost("patient/health_record/add_diet", data, "json", "post", addDietFailed, addDietSuccess); } function addDietFailed(res) { dd.close(); if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'提交失败'}).show(); } } function addDietSuccess(res) { if (res.status == 200) { dd.close().remove(); window.history.back(); } else { //非200则为失败 addDietFailed(res); } } //查看图片 function viewImg(dom) { var $img = $(dom); var thissrc = $img.attr("data-src"); var mWid = $(window).width(); var mHei = $(window).height(); var nHtml = '