add-consult.js 9.7 KB

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