yjk-step1.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. var $body = $('.yjk-body');
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  4. var cache = window.localStorage.getItem("oneStep"+userAgent.uid);
  5. var Request = GetRequest();
  6. var going = Request["isContinue"];
  7. //定义弹窗
  8. function toast(msg){
  9. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
  10. }
  11. //请求失败
  12. function queryFailed(){
  13. d.close()
  14. toast('请求失败')
  15. }
  16. $(function(){
  17. //先判断是否有缓存
  18. if(cache && going){
  19. var cacheObj = JSON.parse(cache)
  20. var html = template('msg_tmp',{data:cacheObj,submitBtn:1})
  21. $body.html(html)
  22. baseInfoInit()
  23. }else if(cache){
  24. dialog({
  25. content: '<div><div class="c-f16 c-333 c-t-left mb10">检测到有未提交信息,是否继续填写?</div></div>',
  26. okValue: '继续',
  27. cancelValue: '清空',
  28. cancel: function () {
  29. window.localStorage.removeItem("oneStep"+userAgent.uid)
  30. queryBaseInfo()
  31. },
  32. ok: function() {
  33. var cacheObj = JSON.parse(cache)
  34. var html = template('msg_tmp',{data:cacheObj,submitBtn:0})
  35. $body.html(html)
  36. baseInfoInit()
  37. }
  38. }).showModal()
  39. }else{
  40. queryBaseInfo()
  41. }
  42. //请求用户数据
  43. function queryBaseInfo(){
  44. d.show()
  45. sendPost('patient/baseinfo',{},'json','post', queryFailed,function(res){
  46. d.close()
  47. if(res.status == 200){
  48. var html = template('msg_tmp',{data:res.data,submitBtn:0})
  49. $body.html(html)
  50. baseInfoInit()
  51. }else{
  52. toast('获取信息失败')
  53. }
  54. })
  55. }
  56. })
  57. //初始化
  58. function baseInfoInit() {
  59. var opt = {
  60. preset: 'date',
  61. theme: 'ios',
  62. lang: 'zh',
  63. minDate: new Date(1900, 01, 01)
  64. };
  65. var marital = {
  66. theme: 'ios',
  67. lang:'zh',
  68. customWheels:true,
  69. wheels: [
  70. [
  71. {
  72. keys: ['20','10'],
  73. values: ['已婚', '未婚']
  74. }
  75. ]
  76. ],
  77. onSelect: function(valueText, inst){
  78. var dd = eval("[" + valueText + "]");
  79. $('#marital').val(dd[0].values);
  80. $('#marital').attr('data-id',dd[0].keys);
  81. }
  82. }
  83. $('#birthday').mobiscroll(opt);
  84. $('#lastMenstruation').mobiscroll(opt);
  85. $('#marital').mobiscroll(marital);
  86. //选择居委会
  87. selectCommittee()
  88. //选择户籍
  89. initExpressAddr($('#idAddress'))
  90. //提交事件
  91. $('.j-btn').click(function(){
  92. var $this = $(this)
  93. commit($this)
  94. })
  95. }
  96. /*判断输入是否为合法的医社保卡号*/
  97. function isSsc(inputString){
  98. var partten = /^([a-zA-Z]{1}[a-zA-Z0-9]{8}|[0-9]{12})$/;
  99. if(partten.test(inputString)){
  100. return true;
  101. }else{
  102. return false;
  103. }
  104. }
  105. /*判断输入是否为合法的手机号码*/
  106. function isphone(inputString){
  107. var partten = /^[1][3578][0-9]{9}$/;
  108. if(partten.test(inputString)){
  109. return true;
  110. }else{
  111. return false;
  112. }
  113. }
  114. /*判断输入是否为合法的身份证*/
  115. function isID(inputString){
  116. var idCardReg = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
  117. if(inputString.length == 15) {
  118. idCardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
  119. }
  120. if(idCardReg.test(inputString)){
  121. return true;
  122. }else{
  123. return false;
  124. }
  125. }
  126. //验证信息
  127. function validate(data) {
  128. if (!data.name) {
  129. toast('请输入姓名')
  130. return false;
  131. }
  132. if (!isSsc(data.ssc)) {
  133. toast('医保卡号不正确')
  134. return false;
  135. }
  136. if (!isID(data.idcardAll)) {
  137. toast('身份证不正确')
  138. return false;
  139. }
  140. if (!data.birthday) {
  141. toast('请选择出生日期')
  142. return false;
  143. }
  144. if (!isphone(data.mobile)) {
  145. toast('手机号码不正确')
  146. return false;
  147. }
  148. if (!data.lastMenstruation) {
  149. toast('请选择末次月经')
  150. return false;
  151. }
  152. if (!data.marital) {
  153. toast('请选择婚姻状况')
  154. return false;
  155. }
  156. if (!data.allergy) {
  157. toast('请输入过敏史')
  158. return false;
  159. }
  160. if (!data.permanentProvinceCode) {
  161. toast('请选择户籍地址')
  162. return false;
  163. }
  164. if (!data.countryCode) {
  165. toast('请选择所属居委会')
  166. return false;
  167. }
  168. if (!data.address) {
  169. toast('请输入现居住地址')
  170. return false;
  171. }
  172. return true;
  173. }
  174. // 提交第一步
  175. function commit($this) {
  176. var params = {}
  177. params.name = $("#name").val().trim(); //姓名
  178. params.ssc = $("#medicalCard").val().trim(); //医保卡号
  179. params.idcardAll = $("#idCard").val().trim(); //身份证
  180. params.birthday = $("#birthday").val(); //出生日期
  181. params.mobile = $("#mobile").val().trim(); //手机号码
  182. params.lastMenstruation = $("#lastMenstruation").val();//末次月经
  183. params.marital = $("#marital").attr('data-id')//婚姻状况
  184. params.maritalName = $("#marital").val()
  185. params.allergy = $("#allergy").val().trim(); //过敏史
  186. params.address = $("#address").val().trim(); //现居住址
  187. params.countryCode = $("#committee").attr('data-code');//居委会
  188. params.countryName = $("#committee").val();
  189. params.permanentProvince = $("#idAddress").attr('data-provinceName') //户籍
  190. params.permanentCity = $("#idAddress").attr('data-cityName')
  191. params.permanentProvinceCode = $("#idAddress").attr('data-province')
  192. params.permanentCityCode = $("#idAddress").attr('data-city')
  193. params.allergy = $("#allergy").val().trim();
  194. if(validate(params)){
  195. window.localStorage.setItem("oneStep"+userAgent.uid,JSON.stringify(params))
  196. if($this.text()=='直接提交'){
  197. window.location.href = "yjk-preview.html"
  198. }else{
  199. if($("#marital").attr('data-id') == 20){
  200. window.location.href = 'yjk-step2.html';
  201. }else{
  202. window.location.href = 'yjk-step3.html';
  203. }
  204. }
  205. }
  206. }