start-sign3.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. var d1 = dialog({contentType:'load', skin:'bk-popup'});
  2. var d = dialog({contentType:'load', skin:'bk-popup', content:'提交签约信息,请稍后...'});
  3. var Request = new Object();
  4. Request = GetRequest();
  5. var doctor = Request["doctor"];
  6. var doctorName = Request["doctorName"];
  7. var hospitalName = Request["hospitalName"];
  8. var idcard = Request["idcard"];
  9. var code = Request["code"];
  10. var level =Request["level"];
  11. var is_renew = window.localStorage.getItem("is_renew");
  12. if(code){
  13. closeWindow();
  14. }
  15. // 从医生主页传递的签约邀请code
  16. var signInvitationCode = Request["inviCode"];
  17. var patientCode = Request["patientCode"];
  18. if(!patientCode || patientCode=="undefined") {
  19. patientCode = "";
  20. }
  21. $(function(){
  22. if(level==2){
  23. $(".bottom-title").html(decodeURI(doctorName)+"医生为全科医生,与其签约后,"+decodeURI(doctorName)+"医生将为您选择一个健管师,共同为您提供各项健康服务");
  24. }else{
  25. $(".bottom-title").html(decodeURI(doctorName)+"医生为健管师,与其签约后,"+decodeURI(doctorName)+"医生将为您选择一个全科医生,共同为您提供各项健康服务");
  26. }
  27. if (decodeURI(doctorName)) {
  28. document.getElementById("doctorName").innerText = decodeURI(doctorName);
  29. }
  30. if (decodeURI(hospitalName)) {
  31. document.getElementById("hospitalName").innerText = decodeURI(hospitalName);
  32. }
  33. if(signInvitationCode&&signInvitationCode!="undefined") {
  34. $('#name_label').text('代理家人');
  35. $(".div-family-remark").show();
  36. }
  37. query();
  38. $("#idcard").on("blur", function() {
  39. var value = $(this).val();
  40. validateIdcard(value);
  41. });
  42. })
  43. //查询用户信息
  44. function query() {
  45. d1.show();
  46. var data={};
  47. if(signInvitationCode&&signInvitationCode!="undefined") {
  48. sendPost('patient/getPatientByInviLogCode', {invilogCode: signInvitationCode}, 'json', 'post', queryFailed, querySuccess);
  49. } else {
  50. sendPost('patient/baseinfo', data, 'json', 'post', queryFailed, querySuccess);
  51. }
  52. }
  53. function queryFailed(res) {
  54. d1.close();
  55. if (res && res.msg) {
  56. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  57. } else {
  58. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'用户信息获取失败'}).show();
  59. }
  60. }
  61. function querySuccess(res) {
  62. if (res.status == 200) {
  63. var data = res.data;
  64. var name = data.name;
  65. var mobile = data.mobile;
  66. var idcard = data.idcard;
  67. var idcardAll = data.idcardAll;
  68. var ssc = data.ssc;
  69. var medicareNumber = data.medicareNumber;
  70. if(!name) name = "";
  71. if(!mobile) mobile = "";
  72. if(!ssc) ssc = "";
  73. if(!idcard) idcard = "";
  74. document.getElementById("name").value = name;
  75. document.getElementById("mobile").value = mobile;
  76. document.getElementById("ssc").value = ssc;
  77. document.getElementById("idcard").value = idcard;
  78. document.getElementById("medicareNumber").value = medicareNumber || "";
  79. $('#committee').text(data.countryName);
  80. $('#committee').attr('data-code',data.countryCode);
  81. $(".userName").html(name);
  82. $('#idcard').attr('data-idcard',idcardAll);
  83. if(!ssc || ssc ==""){
  84. dialog({
  85. content: '对不起,未办理医保卡或在2016年6月之后办理医保卡的居民暂不能进行签约。请保证在您的帐户中(我的资料)正确录入您的医保卡号,然后再重试!',
  86. cancelValue: '我知道了',
  87. cancel: function () {
  88. wx.closeWindow();
  89. }
  90. }).showModal();
  91. }
  92. //选择居委会
  93. selectCommittee()
  94. //如果是改签,获取改签原因列表
  95. if(parseInt(is_renew) == 1){
  96. var url = "/patient/sign/getRenewChangeReason";
  97. sendPost(url, {}, 'json', 'get', queryFailed, function(res1){
  98. if(res1.status == 200){
  99. $("#renewReason").show();
  100. initSelectData(res1);
  101. d1.close();
  102. }else{
  103. queryFailed(res1);
  104. }
  105. });
  106. }else{
  107. d1.close();
  108. }
  109. } else {
  110. queryFailed(res);
  111. }
  112. }
  113. //填充下拉框数据
  114. function initSelectData(res){
  115. var arr_key = [],
  116. arr_value = [];
  117. for(i=0; i<res.data.length; i++){
  118. var item = res.data[i];
  119. arr_key.push(item.code);
  120. arr_value.push(item.value);
  121. }
  122. // console.log(arr_key);
  123. // console.log(arr_value);
  124. $('#reason').mobiscroll({
  125. theme: 'ios',
  126. lang: 'zh',
  127. customWheels: true,
  128. wheels: [
  129. [{
  130. keys: arr_key,
  131. values: arr_value
  132. }]
  133. ],
  134. onSelect: function(valueText, inst) {
  135. var dd = eval("[" + valueText + "]");
  136. $('#reason').val(dd[0].values);
  137. $('#reason').attr("data-code",dd[0].keys);
  138. }
  139. });
  140. }
  141. //验证信息
  142. function validate(data) {
  143. if (data.name == "") {
  144. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请输入您的姓名'}).show();
  145. return false;
  146. }
  147. if (data.ssc == "") {
  148. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'医保卡号信息未完善!'}).show();
  149. return false;
  150. }
  151. if (data.countryCode == "") {
  152. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择所属居委会'}).show();
  153. return false;
  154. }
  155. if(data.medicareNumber == "") {
  156. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请输入医疗保险号'}).show();
  157. return false;
  158. }
  159. // if (data.idcard != "" && !isIdcard(data.idcard)) {
  160. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'身份证号格式不正确'}).show();
  161. // return false;
  162. // }
  163. // if (data.mobile != "" && !isphone(data.mobile)) {
  164. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'手机号格式不正确'}).show();
  165. // return false;
  166. // }
  167. //增加改签原因的判断
  168. if(parseInt(is_renew) == 1){
  169. var reason = $("#reason").attr("data-code");
  170. if(!reason){
  171. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择改签原因!'}).show();
  172. return false;
  173. }
  174. }
  175. return true;
  176. }
  177. function validateIdcard(v){
  178. if ( v == "" ||( v != "" && !isIdcard(v))) {
  179. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'身份证号格式不正确'}).show();
  180. return false;
  181. }
  182. }
  183. function validatePhone(v){
  184. if(v != "" && !isphone(v)){
  185. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'手机号格式不正确'}).show();
  186. document.getElementById("mobile").focus();
  187. return false;
  188. }
  189. return true;
  190. }
  191. function validateSsc(v){
  192. if(!isSsc(v)){
  193. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'医保卡号格式不正确'}).show();
  194. document.getElementById("ssc").focus();
  195. return false;
  196. }
  197. return true;
  198. }
  199. //提交签约
  200. function submitSign(){
  201. var data = {};
  202. data.name = $("#name").val();
  203. data.ssc = $("#ssc").val();
  204. data.medicareNumber = $("#medicareNumber").val();
  205. data.mobile = $("#mobile").val();
  206. //data.idcard = $("#idcard").val();
  207. data.idcard = $('#idcard').attr('data-idcard');
  208. data.countryCode = $("#committee").attr('data-code');
  209. //判断是否是续签变更医生的情况
  210. if(validate(data)){
  211. d.showModal();
  212. if(parseInt(is_renew)){
  213. var url = "/patient/family_contract/signRenew",
  214. params = {
  215. doctor: doctor || "",
  216. patient: patientCode,
  217. reason: $("#reason").attr("data-code"),
  218. countryCode:$("#committee").attr('data-code'),
  219. medicareNumber: $("#medicareNumber").val()
  220. };
  221. sendPost(url, params, "json", "post", operateFailed, operateSuccesss2);
  222. return;
  223. }
  224. data.doctor = doctor;
  225. data.doctorType = level;
  226. data.patient = patientCode;
  227. // 存入缓存。以便建档成功时提交签约信息
  228. window.localStorage.removeItem("jiandangCase1")
  229. window.localStorage.removeItem("jiandangCase2")
  230. if(window.localStorage.getItem('is_signData')) {
  231. window.localStorage.removeItem('is_signData');
  232. }
  233. data.jwCountryCode = $("#committee").attr('data-jwcode');
  234. data.countryName = $('#committee').text().trim();
  235. data.signInvitationCode = signInvitationCode;
  236. var dataStr = JSON.stringify(data);
  237. window.localStorage.setItem('is_signData', dataStr);
  238. sendPost("patient/family_contract/sign", data, "json", "post", operateFailed, operateSuccesss);
  239. }
  240. }
  241. //失败
  242. function operateFailed(res) {
  243. d.close();
  244. if (res && res.msg) {
  245. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  246. if(res.status == -2) {// 跳转自助建档
  247. window.location.href = "../../jdqy/html/zizhujiandang.html";
  248. } else {
  249. window.localStorage.removeItem('is_signData');
  250. }
  251. } else {
  252. window.localStorage.removeItem('is_signData');
  253. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'提交失败'}).show();
  254. }
  255. return;
  256. }
  257. function operateSuccesss(res) {
  258. if (res.status == 200) {
  259. window.localStorage.removeItem('is_signData');
  260. d.close();
  261. if(signInvitationCode&&signInvitationCode!="undefined") {
  262. dialog({
  263. content: '签约申请已提交,请耐心等待,<br/>医生通过后即可为您的家人提供家庭医生服务',
  264. okValue:'我知道了',
  265. ok: function() {
  266. wx.closeWindow();
  267. }
  268. }).showModal();
  269. }else{
  270. window.location.href = "../../ssgg/html/doctor-homepage-new.html?waitSign=1&state=" + doctor;
  271. }
  272. // window.location.href = "doctor-home-page.html?doctor=" + doctor;
  273. } else {
  274. //非200则为失败
  275. operateFailed(res);
  276. }
  277. }
  278. //续签申请成功后页面跳转
  279. function operateSuccesss2(res) {
  280. if (res.status == 200) {
  281. d.close();
  282. dialog({
  283. content: '续签申请已提交,请耐心等待,<br/>医生通过后即可为您的家人提供家庭医生服务',
  284. okValue:'我知道了',
  285. ok: function() {
  286. window.location.replace("../../qygl/html/signing_management.html");
  287. }
  288. }).showModal();
  289. } else {
  290. //非200则为失败
  291. operateFailed(res);
  292. }
  293. }
  294. function closeWindow() {
  295. var Request = new Object();
  296. Request = GetRequest();
  297. var code = Request["code"];
  298. //从后台那边获取签名等信息
  299. var params = {};
  300. params.pageUrl = window.location.href;
  301. $.ajax(server + "weixin/getSign", {
  302. data: params,
  303. dataType: "json",
  304. type: "post",
  305. success: function(res) {
  306. if(res.status == 200) {
  307. var t = res.data.timestamp;
  308. var noncestr = res.data.noncestr;
  309. var signature = res.data.signature;
  310. wx.config({
  311. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  312. appId: appId, // 必填,公众号的唯一标识
  313. timestamp: t, // 必填,生成签名的时间戳
  314. nonceStr: noncestr, // 必填,生成签名的随机串
  315. signature: signature, // 必填,签名,见附录1
  316. jsApiList: [
  317. 'closeWindow'
  318. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  319. });
  320. }
  321. }
  322. });
  323. }