view-shezhishijianduan-time.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;(function ($) {
  2. var showDateDom1 = $('#mobIn1');
  3. var showDateDom2 = $('#mobIn2');
  4. var showDateDom3 = $('#mobIn3');
  5. var showDateDom4 = $('#mobIn4');
  6. var showDateDom5 = $('#mobIn5');
  7. var showDateDom6 = $('#mobIn6');
  8. var showDateDom7 = $('#mobIn7');
  9. var iosSelect1 = null;
  10. var iosSelect2 = null;
  11. var iosSelect3 = null;
  12. var iosSelect4 = null;
  13. var iosSelect5 = null;
  14. var iosSelect6 = null;
  15. var iosSelect7 = null;
  16. var starNum1 = 0;
  17. var starNum2 = 0;
  18. // 初始化时间
  19. var now = new Date();
  20. var nowHours = now.getHours();
  21. var nowSeconds = now.getMinutes();
  22. showDateDom1.attr('data-hours', cN(nowHours));
  23. showDateDom1.attr('data-seconds', cN(nowSeconds));
  24. showDateDom1.attr('data-thours', cN(nowHours));
  25. showDateDom1.attr('data-tseconds', cN(nowSeconds));
  26. // 数据初始化
  27. function cN (v) {
  28. return v < 10 ? '0' + v : v;
  29. }
  30. function formatHours (s) {
  31. var arr = [];
  32. for (var i = s; i <= 23; i++) {
  33. arr.push({
  34. id: cN(i) + '',
  35. value: cN(i)
  36. });
  37. }
  38. return arr;
  39. }
  40. function formatSeconds (s) {
  41. var arr = [];
  42. for (var i = s; i <= 59; i++) {
  43. arr.push({
  44. id: cN(i) + '',
  45. value: cN(i)
  46. });
  47. }
  48. return arr;
  49. }
  50. var hoursData = function (callback) {
  51. callback(formatHours(starNum1));
  52. };
  53. var secondData = function(h,callback) {
  54. callback(formatSeconds(starNum2))
  55. };
  56. var hoursTData = function (h,s,callback) {
  57. h = parseInt(h);
  58. callback(formatHours(h));
  59. };
  60. var secondTData = function(h,s,h1,callback) {
  61. s = parseInt(s);
  62. callback(formatSeconds(0))
  63. };
  64. for (var i = 1; i <= 7; i++) {
  65. $('#mobIn' + i).on('click', function () {
  66. var $me = $(this);
  67. var oneLevelId = $me.attr('data-hours');
  68. var twoLevelId = $me.attr('data-seconds');
  69. var threeLevelId = $me.attr('data-thours');
  70. var fourLevelId = $me.attr('data-tseconds');
  71. var $n = $me.closest('.time-item').next(),
  72. $p = $me.closest('.time-item').prev(),
  73. ind = $me.closest('.time-item').index();
  74. if ($p.length) {
  75. if (!$p.find('input').val()) {
  76. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请先选择上一个时间段!'}).show();
  77. return;
  78. }
  79. }
  80. if (ind == 0) {
  81. starNum1 = 0;
  82. starNum2 = 0;
  83. } else {
  84. starNum1 = parseInt(oneLevelId);
  85. starNum2 = parseInt('00');
  86. }
  87. new IosSelect(4,
  88. [ hoursData, secondData, hoursTData, secondTData],
  89. {
  90. title: '',
  91. itemHeight: 35,
  92. relation: [ 1, 1, 1, 1],
  93. oneLevelId: oneLevelId,
  94. twoLevelId: twoLevelId,
  95. threeLevelId: threeLevelId,
  96. fourLevelId: fourLevelId,
  97. showLoading: true,
  98. callback: function (selectOneObj, selectTwoObj, selectThreeObj, selectFourObj) {
  99. $n.find('input').attr('data-hours', selectThreeObj.id);
  100. $n.find('input').attr('data-seconds', selectFourObj.id);
  101. $n.find('input').attr('data-thours', selectThreeObj.id);
  102. $n.find('input').attr('data-tseconds', selectFourObj.id);
  103. $me.attr('data-hours', selectOneObj.id);
  104. $me.attr('data-seconds', selectTwoObj.id);
  105. $me.attr('data-thours', selectThreeObj.id);
  106. $me.attr('data-tseconds', selectFourObj.id);
  107. starNum1 = parseInt(selectThreeObj.id);
  108. starNum2 = parseInt(selectFourObj.id);
  109. $me.val(selectOneObj.value + ':' + selectTwoObj.value + '-' + selectThreeObj.value + ':' + selectFourObj.value);
  110. }
  111. });
  112. });
  113. }
  114. })(jQuery);