yjk-step2.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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("twoStep"+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. $(function(){
  12. //先判断是否有缓存
  13. if(cache && going){
  14. var cacheObj = JSON.parse(cache)
  15. showPage(cacheObj)
  16. }else if(cache){
  17. dialog({
  18. content: '<div><div class="c-f16 c-333 c-t-left mb10">检测到有未提交信息,是否继续填写?</div></div>',
  19. okValue: '继续',
  20. cancelValue: '清空',
  21. cancel: function () {
  22. window.localStorage.removeItem("twoStep"+userAgent.uid)
  23. showPage({})
  24. },
  25. ok: function() {
  26. var cacheObj = JSON.parse(cache)
  27. showPage(cacheObj)
  28. }
  29. }).showModal()
  30. }else{
  31. showPage({})
  32. }
  33. //显示页面
  34. function showPage(data){
  35. var html = template('msg_tmp',{data:data})
  36. $body.html(html)
  37. baseInfoInit()
  38. }
  39. })
  40. //初始化
  41. function baseInfoInit() {
  42. var opt = {
  43. preset: 'date',
  44. theme: 'ios',
  45. lang: 'zh',
  46. minDate: new Date(1900, 01, 01)
  47. }
  48. $('#weddingDate').mobiscroll(opt);
  49. $('#spouseBirthday').mobiscroll(opt);
  50. //点击
  51. $('#page2_next').bind('tap',function(){
  52. commit(function(){
  53. window.location.href = "yjk-step3.html"
  54. })
  55. })
  56. $('#page2_submit').bind('tap',function(){
  57. commit(function(){
  58. window.location.href = "yjk-preview.html"
  59. })
  60. })
  61. }
  62. //保存数据到缓存
  63. function commit(fun){
  64. var params={}
  65. params.weddingDate = $("#weddingDate").val();
  66. params.spouseName = $("#spouseName").val();
  67. params.spouseBirthday = $("#spouseBirthday").val();
  68. params.spouseMobile = $("#spouseMobile").val();
  69. if(validate(params)){
  70. window.localStorage.setItem("twoStep"+userAgent.uid,JSON.stringify(params))
  71. fun&&fun.call(this)
  72. }
  73. }
  74. /*判断输入是否为合法的手机号码*/
  75. function isphone(inputString){
  76. var partten = /^[1][3578][0-9]{9}$/;
  77. if(partten.test(inputString)){
  78. return true;
  79. }else{
  80. return false;
  81. }
  82. }
  83. //验证信息
  84. function validate(data) {
  85. if(data.spouseMobile){
  86. if (!isphone(data.spouseMobile)) {
  87. toast('手机号码格式不对')
  88. return false;
  89. }
  90. }
  91. return true;
  92. }