add-consult.js 9.2 KB

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