add-consult.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.ready(function(){
  133. wx.chooseImage({
  134. count: 9-getImages().length,
  135. success: function (res) {
  136. for (var i in res.localIds) {
  137. appendFile(res.localIds[i]);
  138. }
  139. }
  140. });
  141. });
  142. }
  143. function uploadImage(data){
  144. $("#commit").css("pointer-events","none");
  145. var images = getImages();
  146. if (images.length == 0) {
  147. return;
  148. }
  149. var i = 0, length = images.length;
  150. serverId = "";
  151. function upload() {
  152. wx.uploadImage({
  153. localId: images[i],
  154. isShowProgressTips: 0,
  155. success: function (res) {
  156. i++;
  157. if(serverId.length == 0){
  158. serverId = res.serverId;
  159. }
  160. else{
  161. serverId =serverId + "," + res.serverId;
  162. }
  163. if (i < length) {
  164. upload();
  165. }
  166. if(i == images.length){
  167. doSubmit(data);
  168. }
  169. },
  170. fail: function (res) {
  171. $("#commit").css("pointer-events","");
  172. alert(JSON.stringify(res));
  173. }
  174. });
  175. }
  176. upload();
  177. }
  178. // 添加文件
  179. function appendFile(p) {
  180. var amount = getImages().length;
  181. if (amount >= 8) {
  182. $("#add_img_li").hide();
  183. }
  184. if(amount < 9){
  185. 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>');
  186. var $add_img_li = $("#add_img_li");
  187. $add_img_li.before($li);
  188. $("#image_tips").text(getImages().length + "/9");
  189. }
  190. }
  191. //获取需要上传的图片
  192. function getImages() {
  193. var images = [];
  194. $("#img_ul").find("img").each(function() {
  195. var imgSrc = $(this).attr("data-src");
  196. images.push(imgSrc);
  197. });
  198. return images;
  199. }
  200. //查看图片
  201. function viewImg(dom) {
  202. var $img = $(dom);
  203. var thissrc = $img.attr("data-src");
  204. var mWid = $(window).width();
  205. var mHei = $(window).height();
  206. 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>';
  207. $("body").append(nHtml);
  208. $(".delimgpop").click(function() {
  209. $(this).remove()
  210. });
  211. };
  212. //删除图片
  213. function delImg(dom) {
  214. var $li = $(dom).parent();
  215. $li.remove();
  216. $("#image_tips").text(getImages().length + "/9");
  217. var amount = getImages().length;
  218. if(amount <= 8){
  219. $("#add_img_li").show();
  220. }
  221. return;
  222. }
  223. //微信sdk配置出错
  224. wx.error(function (res) {
  225. alert("wx.error:" + res.errMsg);
  226. });
  227. //提交咨询
  228. function doSubmit(data) {
  229. data.mediaIds = serverId;
  230. data.doctor = doctorCode;
  231. var url = 'patient/consult/add';//新增三师或家庭
  232. sendPost(url, data, 'json', 'post', submitFailed, submitSuccess);
  233. }
  234. function submitSuccess(res) {
  235. if (res.status == 200) {
  236. $("#commit").css("pointer-events","");
  237. d.close();
  238. //页面跳转到消息页面
  239. localStorage.setItem("signInfo_tab", 0);
  240. var direct_url = "../../qygl/html/sign_info.html?doctor="+doctorCode+"&consult="+res.data.consult+"&patientcode="+patientcode;
  241. window.location.href = direct_url;
  242. } else {
  243. submitFailed(res);
  244. }
  245. }
  246. function queryFailed(res){
  247. d.close();
  248. if (res && res.msg) {
  249. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  250. } else {
  251. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  252. }
  253. }
  254. function submitFailed(res) {
  255. $("#commit").css("pointer-events","");
  256. d.close();
  257. if (res && res.msg) {
  258. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  259. } else {
  260. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show();
  261. }
  262. }
  263. function getWxSign(){
  264. //从后台那边获取签名等信息
  265. var params = {};
  266. params.pageUrl = window.location.href;
  267. $.ajax(server + "weixin/getSign", {
  268. data: params,
  269. dataType: "json",
  270. type: "post",
  271. success: function(res){
  272. if (res.status == 200) {
  273. var t = res.data.timestamp;
  274. var noncestr = res.data.noncestr;
  275. var signature = res.data.signature;
  276. wx.config({
  277. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  278. appId: appId, // 必填,公众号的唯一标识
  279. timestamp: t, // 必填,生成签名的时间戳
  280. nonceStr: noncestr, // 必填,生成签名的随机串
  281. signature: signature,// 必填,签名,见附录1
  282. jsApiList: [
  283. 'chooseImage',
  284. 'uploadImage'
  285. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  286. });
  287. }
  288. else{
  289. // dialog({
  290. // title:'提示',
  291. // skin:"ui-dialog ax-popup pror",
  292. // content:"获取微信签名失败",
  293. // ok: function (){}
  294. // }).showModal();
  295. }
  296. }
  297. });
  298. }