123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- //压缩完后的图片
- var compressImages = {};
- var dd = dialog({contentType:'load', skin:'bk-popup', content:'保存中...'});
- var Request = GetRequest();
- var id = Request['id'],
- code = decodeURIComponent(Request['type']),
- time = decodeURIComponent(Request['time']),
- val1 = decodeURIComponent(Request['val']);
- var lastDate = '';
- var images_old='';
- var imagesStr = decodeURIComponent(Request['image']);
- if(imagesStr){
- var arr = imagesStr.split(',');
- var newArr = $.map(arr,function(o,i){
- return getImgUrl(o)
- })
- images_old = newArr.join(',')
- }
-
- $(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
- });
- }
- }
- });
- /* 选择日期 */
- var opt1 = {
- preset: 'date',
- theme: 'ios',
- lang: 'zh',
- dateFormat: 'yy-mm-dd',
- minDate: new Date(1900, 01, 01)
- };
- $('input[data-time=date]').mobiscroll(opt1);
- if (id) {
- var date = new Date(time.replace(/\-/g, "/"))
- $("#date").val(date.Format("yyyy-MM-dd"));
- } else {
- var date = new Date()
- $("#date").val(date.Format("yyyy-MM-dd"));
- }
- if (id) {
- $('#ys_val').val(val1);
- var imgArr = images_old.split(',');
- for (var i = 0, len = imgArr.length; i < len; i++) {
- appendFile(imgArr[i]);
- }
- }
-
- document.getElementById("goback").addEventListener("tap", function() {
- var date = document.getElementById("date").value;
- var val = document.getElementById("ys_val").value;
- var images = getImages();
- lastDate = date.substring(0,10);
- if (val && date) {
-
- } else {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请填写完整信息'}).show();
- return;
- }
- var data = {};
- data.record_date = date + ' 00:00:00';
- data.content = val;
-
- if(images.length == 0){
- dialog({contentType:'tipsbox',bottom:true, 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 = getWxImages();
- serverId = "";
- if (images[0].length > 0) {
- var i = 0, length = images[0].length;
- function upload() {
- wx.uploadImage({
- localId: images[0][i],
- isShowProgressTips: 0,
- success: function (res) {
- i++;
- serverId =serverId + "," + res.serverId;
- if (i < length) {
- upload();
- }
- if(i == images[0].length){
- serverId = serverId + "," + images[1].join(',');
- doSubmit(data);
- }
- },
- fail: function (res) {
- alert('上传图片失败');
- dd.close()
- }
- })
- }
- upload();
- }else{
- serverId = images[1].join(',');
- doSubmit(data);
- }
- }
- //提交咨询
- function doSubmit(data) {
- if(serverId.substr(0,1) == ','){
- var data1 = serverId.substr(1);
- if(data1.substr(-1) == ','){
- data.mediaIds = data1.substring(0,data1.length - 1);
- }else{
- data.mediaIds = data1;
- }
- }else{
- data.mediaIds = serverId;
- }
- if (id) {
- var params = {
- id:id,
- type:1,
- value1:data.record_date,
- value2:data.content,
- value3:data.mediaIds,
- mediaIds:data.mediaIds
- }
- sendPost("patient/health_record/modifyHealthCare", params, "json", "post", addDietFailed, addDietSuccess);
- } else {
- //发送ajax请求
- sendPost("patient/health_record/add_diet", data, "json", "post", addDietFailed, addDietSuccess);
- }
- }
- function addDietFailed(res) {
- dd.close();
- if (res && res.msg) {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show();
- }
- }
- function addDietSuccess(res) {
- if (res.status == 200) {
- dd.close().remove();
- setTimeout(function(){
- window.location.href='yinshi-view.html?dateT=' + lastDate;
- },1000)
- } 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 = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
- $("body").append(nHtml);
- $(".delimgpop").click(function() {
- $(this).remove()
- });
- };
- //删除图片
- function delImg(dom) {
- var $li = $(dom).parent();
- $li.remove();
- $("#image_tips").text(getImages().length + "/3");
- var amount = getImages().length;
- if(amount <= 2){
- $("#add_img_li").show();
- }
- return;
- }
- // 添加文件
- function appendFile(p) {
- var amount = getImages().length;
- if (amount >= 2) {
- $("#add_img_li").hide();
- }
- if(amount < 3){
- var $add_img_li = $("#add_img_li");
- var $li = $('<li>' + ' <img src="' + p + '" data-src="' + p + '" onclick="viewImg(this)">' + ' <a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a>' + '</li>');
- $add_img_li.before($li);
- $("#image_tips").text(getImages().length + "/3");
- }
- }
- //获取需要上传的图片
- function getImages() {
- var images = [];
- $("#img_ul").find("img").each(function() {
- var imgSrc = $(this).attr("data-src");
- images.push(imgSrc);
- });
- return images;
- }
- //获取需要微信上传的图片
- function getWxImages() {
- var images = [];
- var noimages = [];
- $("#img_ul").find("img").each(function() {
- var imgSrc = $(this).attr("data-src");
- if(imgSrc.indexOf('group1/')>-1){
- noimages.push(imgSrc);
- }else{
- images.push(imgSrc);
- }
- });
- return [images,noimages];
- }
|