immune-confirm.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. var d = dialog({ contentType: 'load', skin: 'bk-popup' });
  2. var imgKey = null;
  3. var selectData = ''; //用户信息
  4. var orgInfo, //前一个页面保存在localStorage的数据
  5. arrangeDate, //前一个页面保存在localStorage的数据
  6. patientInfo; //如果儿童没有身份证号和社保卡号,则使用当前用户的身份证号和社保卡号
  7. $(function() {
  8. // checkUserAgent();
  9. queryInit();
  10. });
  11. function queryInit(){
  12. orgInfo = window.localStorage.getItem("orgInfo");
  13. if(orgInfo && orgInfo != "") {
  14. orgInfo = JSON.parse(orgInfo);
  15. $("#hospitalName").text(orgInfo.name);
  16. } else {
  17. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'机构数据异常重新选择!',bottom:true}).show();
  18. return;
  19. }
  20. arrangeDate = window.localStorage.getItem("arrangeDate");
  21. if(arrangeDate && arrangeDate != "") {
  22. arrangeDate = JSON.parse(arrangeDate);
  23. $("#yyTime").text(arrangeDate.timeStr);
  24. } else {
  25. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'预约日期异常请返回重新选择!',bottom:true}).show();
  26. return;
  27. }
  28. initValidate();
  29. getImmuneMembers();
  30. bindEvents();
  31. }
  32. function initValidate() {
  33. var serurl = "patient/captcha";
  34. var posttype = "get";
  35. if(imgKey != null) {
  36. serurl = serurl + "/" + imgKey;
  37. posttype = "post";
  38. }
  39. sendPost(serurl, {}, "json", posttype, function(res) {
  40. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: "验证码获取失败!", bottom: true }).show();
  41. }, function(res) {
  42. if(res.status == 200) {
  43. imgKey = res.data.key;
  44. $("#validateDiv").attr("src", "data:image/png;base64," + res.data.image);
  45. } else {
  46. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: "验证码获取失败!", bottom: true }).show();
  47. }
  48. })
  49. }
  50. //获得接种儿童信息
  51. function getImmuneMembers(){
  52. var url = "/patient/family/members";
  53. sendPost(url, {}, 'json', 'get', queryFailed, function(res){
  54. if(res.status == 200){
  55. if(res.data.immunemembers.length > 0){
  56. var keys = [],
  57. values = [];
  58. for(i=0; i<res.data.immunemembers.length; i++){
  59. var item = res.data.immunemembers[i];
  60. keys.push(item.child_code);
  61. values.push(item.name);
  62. }
  63. $("#userName").mobiscroll({
  64. theme: 'ios',
  65. lang:'zh',
  66. customWheels:true,
  67. wheels: [
  68. [
  69. {
  70. keys: keys,
  71. values: values
  72. }
  73. ]
  74. ],
  75. onSelect: function(valueText, inst){
  76. var dd = eval("[" + valueText + "]");
  77. $("#userName").val(dd[0].values);
  78. $("#userName").attr('data-id',dd[0].keys);
  79. selectData = _.findWhere(res.data.immunemembers, {child_code: dd[0].keys});
  80. //填充身份证号
  81. if(!selectData.idcard || !selectData.ssc){
  82. getPatientInfo();
  83. }else{
  84. $("#idCard").val(selectData.idcard);
  85. }
  86. }
  87. });
  88. }
  89. }else{
  90. queryFailed(res);
  91. }
  92. });
  93. }
  94. //获得患者信息
  95. function getPatientInfo(){
  96. var url = "patient/baseinfo";
  97. sendPost(url, {}, 'json', 'get', function(res){
  98. if(res.msg){
  99. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg, bottom: true }).show();
  100. }else{
  101. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '加载数据失败', bottom: true }).show();
  102. }
  103. }, function(res){
  104. if(res.status == 200){
  105. patientInfo = res.data;
  106. $("#idCard").val(patientInfo.idcardAll);
  107. }else{
  108. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg, bottom: true }).show();
  109. }
  110. })
  111. }
  112. function bindEvents() {
  113. var scroller1 = new IScrollPullUpDown('wrapper', {
  114. probeType: 2,
  115. bounceTime: 250,
  116. bounceEasing: 'quadratic',
  117. mouseWheel: false,
  118. scrollbars: true,
  119. fadeScrollbars: true,
  120. click: true,
  121. interactiveScrollbars: false
  122. }, null, null);
  123. $("#validateDiv").on("click", function() {
  124. initValidate();
  125. });
  126. $("#mobile").on("focus", function() {
  127. $(".searchbar-clear").css("pointer-events", "none").css("opacity", 0);
  128. if($(this).val()) {
  129. $(this).next().css("pointer-events", "auto").css("opacity", 1);
  130. $(this).next().show();
  131. }
  132. }).on("input", function() {
  133. $(this).next().css("pointer-events", "auto").css("opacity", 1);
  134. $(this).next().show();
  135. });
  136. $(".visit-ul").on("click", ".searchbar-clear", function() {
  137. $(this).prev().val("");
  138. $(this).css("pointer-events", "none").css("opacity", 0);
  139. $(this).prev().focus();
  140. return false;
  141. });
  142. window.addEventListener("resize", function() {
  143. var u = navigator.userAgent;
  144. if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
  145. var self = document.getElementById("validateCode");
  146. setTimeout(function() {
  147. self.scrollIntoView({ block: "end", behavior: "smooth" });
  148. }, 150);
  149. }
  150. });
  151. //保存
  152. $("#confirmBtn").on('click', function(){
  153. var $this = $(this);
  154. if($this.hasClass("disabled")){
  155. return false;
  156. }
  157. var childName = $("#userName").val(),
  158. idCard = $("#idCard").val(),
  159. mobile = $("#mobile").val(),
  160. validateCode = $("#validateCode").val();
  161. if(!isphone(mobile)){
  162. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'手机号格式不正确'}).show();
  163. return;
  164. }
  165. $("#validateCode").blur();
  166. $("#mobile").blur();
  167. $this.addClass("disabled");
  168. //校验验证码是否正确
  169. d.show();
  170. sendPost("patient/captcha/"+imgKey,{"text":validateCode},"json","get",function(res){
  171. d.close();
  172. dialog({
  173. contentType:'tipsbox',
  174. skin:'bk-popup' ,
  175. content:"验证码校验失败!",
  176. bottom:true
  177. }).show();
  178. initValidate();
  179. $this.removeClass("disabled");
  180. },function(res){
  181. if(res.status==200){
  182. if(res.pass==true){
  183. imgKey = null;
  184. //发送确认请求
  185. var url = "/patient/guahao/imm/RegisterImmune",
  186. params = {
  187. OrgCode: orgInfo.code,
  188. SectionType: arrangeDate.time,
  189. strStart: arrangeDate.startTime,
  190. BarCode: selectData.barcode,
  191. SSID: selectData.ssc ? selectData.ssc : patientInfo.ssc,
  192. PatientName: selectData.name,
  193. PatientID: selectData.idcard ? selectData.idcard : patientInfo.ssc,
  194. PatientPhone: mobile
  195. };
  196. sendPost(url, params, 'JSON', 'POST', queryFailed, submitSuccess);
  197. }else{
  198. d.close();
  199. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码错误,请重新输入!",bottom:true}).show();
  200. $this.removeClass("disabled");
  201. }
  202. }else{
  203. d.close();
  204. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码校验失败!",bottom:true}).show();
  205. $this.removeClass("disabled");
  206. }
  207. });
  208. });
  209. }
  210. function submitSuccess(res) {
  211. d.close();
  212. if(res.status == 200) {
  213. $("#confirmBtn").removeClass("disabled");
  214. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '预约成功!', bottom: true }).show();
  215. setTimeout(function() {
  216. location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" + wxurl + "%2fwdyy%2fhtml%2fmy-appointment.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  217. }, 200);
  218. } else {
  219. $("#confirmBtn").removeClass("disabled");
  220. queryFailed(res);
  221. }
  222. }
  223. function queryFailed(res) {
  224. d.close();
  225. $("#confirmBtn").removeClass("disabled");
  226. if(res && res.msg) {
  227. if((res.msg).indexOf("SOAP") >= 0) {
  228. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: "医院接口访问异常,请刷新后重试!", bottom: true }).show();
  229. return false;
  230. }
  231. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg, bottom: true }).show();
  232. } else {
  233. dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '加载失败', bottom: true }).show();
  234. }
  235. }