add-consult.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var request = GetRequest(),
  3. doctorCode = request["doctorCode"],
  4. docInfo,
  5. patientInfo = window.localStorage.getItem(agentName1);
  6. var serverId = ""; //微信图片上传获取的图片id
  7. $(function(){
  8. if(patientInfo){
  9. patientInfo = JSON.parse(patientInfo);
  10. }
  11. $("#lbl_patient").text(patientInfo.name);
  12. //获取医生信息
  13. getDoctorInfo();
  14. bindEvents();
  15. getWxSign();
  16. })
  17. function getDoctorInfo(){
  18. d.show();
  19. var url = "family_contract/homepage/homepage",
  20. params = {
  21. doctor: doctorCode
  22. };
  23. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  24. if(res.status == 200){
  25. d.close();
  26. docInfo = res.data;
  27. var text = docInfo.name;
  28. if(docInfo.jobName){
  29. text += "("+docInfo.jobName+")"
  30. }
  31. $("#lbl_doctor").text(text);
  32. }else{
  33. queryFailed(res);
  34. }
  35. })
  36. }
  37. function bindEvents(){
  38. //提交咨询
  39. $("#commit").click(function() {
  40. if($(this).hasClass("active")){
  41. var txtContent = $("#txtContent").val();
  42. if(txtContent){
  43. txtContent = utf16toEntities(txtContent.replace(/\s+/g,""));
  44. }
  45. var data = {
  46. type: 1,
  47. symptoms: txtContent || "",
  48. voice: ""
  49. };
  50. if (validate(data)) {
  51. //验证通过执行
  52. d.showModal();
  53. var images = getImages();
  54. if(images.length == 0){
  55. $("#commit").css("pointer-events","none");
  56. serverId = '';
  57. doSubmit(data);
  58. }
  59. else{
  60. uploadImage(data);
  61. }
  62. }
  63. }
  64. });
  65. }
  66. //验证信息
  67. function validate(data) {
  68. if (data.symptoms.length < 10) {
  69. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请至少用10个字描述您的症状'}).show();
  70. return false;
  71. }
  72. if (data.symptoms.length > 500) {
  73. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请在500字以内完成您的症状描述'}).show();
  74. return false;
  75. }
  76. // if(!$(".input-group-pack > input[type=checkbox]").attr("checked")){
  77. // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请勾选"我已阅读咨询说明"'}).show();
  78. // return false;
  79. // }
  80. return true;
  81. }
  82. function chooseImage(){
  83. wx.chooseImage({
  84. count: 9-getImages().length,
  85. success: function (res) {
  86. for (var i in res.localIds) {
  87. appendFile(res.localIds[i]);
  88. }
  89. }
  90. });
  91. }
  92. function uploadImage(data){
  93. $("#commit").css("pointer-events","none");
  94. var images = getImages();
  95. if (images.length == 0) {
  96. return;
  97. }
  98. var i = 0, length = images.length;
  99. serverId = "";
  100. function upload() {
  101. wx.uploadImage({
  102. localId: images[i],
  103. isShowProgressTips: 0,
  104. success: function (res) {
  105. i++;
  106. if(serverId.length == 0){
  107. serverId = res.serverId;
  108. }
  109. else{
  110. serverId =serverId + "," + res.serverId;
  111. }
  112. if (i < length) {
  113. upload();
  114. }
  115. if(i == images.length){
  116. doSubmit(data);
  117. }
  118. },
  119. fail: function (res) {
  120. $("#commit").css("pointer-events","");
  121. alert(JSON.stringify(res));
  122. }
  123. });
  124. }
  125. upload();
  126. }
  127. // 添加文件
  128. function appendFile(p) {
  129. var amount = getImages().length;
  130. if (amount >= 8) {
  131. $("#add_img_li").hide();
  132. }
  133. if(amount < 9){
  134. 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>');
  135. var $add_img_li = $("#add_img_li");
  136. $add_img_li.before($li);
  137. $("#image_tips").text(getImages().length + "/9");
  138. }
  139. }
  140. //获取需要上传的图片
  141. function getImages() {
  142. var images = [];
  143. $("#img_ul").find("img").each(function() {
  144. var imgSrc = $(this).attr("data-src");
  145. images.push(imgSrc);
  146. });
  147. return images;
  148. }
  149. //查看图片
  150. function viewImg(dom) {
  151. var $img = $(dom);
  152. var thissrc = $img.attr("data-src");
  153. var mWid = $(window).width();
  154. var mHei = $(window).height();
  155. 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>';
  156. $("body").append(nHtml);
  157. $(".delimgpop").click(function() {
  158. $(this).remove()
  159. });
  160. };
  161. //删除图片
  162. function delImg(dom) {
  163. var $li = $(dom).parent();
  164. $li.remove();
  165. $("#image_tips").text(getImages().length + "/9");
  166. var amount = getImages().length;
  167. if(amount <= 8){
  168. $("#add_img_li").show();
  169. }
  170. return;
  171. }
  172. //微信sdk配置出错
  173. wx.error(function (res) {
  174. alert("wx.error:" + res.errMsg);
  175. });
  176. //提交咨询
  177. function doSubmit(data) {
  178. data.mediaIds = serverId;
  179. data.doctor = doctorCode;
  180. var url = 'patient/consult/add';//新增三师或家庭
  181. sendPost(url, data, 'json', 'post', submitFailed, submitSuccess);
  182. }
  183. function submitSuccess(res) {
  184. if (res.status == 200) {
  185. $("#commit").css("pointer-events","");
  186. d.close();
  187. //页面跳转到消息页面
  188. localStorage.setItem("signInfo_tab", 0);
  189. var direct_url = "../../qygl/html/sign_info.html?doctor="+doctorCode+"&consult="+res.data.consult;
  190. window.location.href = direct_url;
  191. } else {
  192. submitFailed(res);
  193. }
  194. }
  195. function queryFailed(res){
  196. d.close();
  197. if (res && res.msg) {
  198. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  199. } else {
  200. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  201. }
  202. }
  203. function submitFailed(res) {
  204. $("#commit").css("pointer-events","");
  205. d.close();
  206. if (res && res.msg) {
  207. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  208. } else {
  209. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show();
  210. }
  211. }
  212. function getWxSign(){
  213. //从后台那边获取签名等信息
  214. var params = {};
  215. params.pageUrl = window.location.href;
  216. $.ajax(server + "weixin/getSign", {
  217. data: params,
  218. dataType: "json",
  219. type: "post",
  220. success: function(res){
  221. if (res.status == 200) {
  222. var t = res.data.timestamp;
  223. var noncestr = res.data.noncestr;
  224. var signature = res.data.signature;
  225. wx.config({
  226. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  227. appId: appId, // 必填,公众号的唯一标识
  228. timestamp: t, // 必填,生成签名的时间戳
  229. nonceStr: noncestr, // 必填,生成签名的随机串
  230. signature: signature,// 必填,签名,见附录1
  231. jsApiList: [
  232. 'chooseImage',
  233. 'uploadImage'
  234. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  235. });
  236. }
  237. else{
  238. // dialog({
  239. // title:'提示',
  240. // skin:"ui-dialog ax-popup pror",
  241. // content:"获取微信签名失败",
  242. // ok: function (){}
  243. // }).showModal();
  244. }
  245. }
  246. });
  247. }