in.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // pages/in/in.js
  2. var date = new Date();
  3. var currentHours = date.getHours();
  4. var currentMinute = date.getMinutes();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. startDate: "请选择日期",
  11. multiArray: [['今天', '明天', '3-2', '3-3', '3-4', '3-5'], [0, 1, 2, 3, 4, 5, 6], [0, 10, 20]],
  12. multiIndex: [0, 0, 0],
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. },
  19. /**
  20. * 生命周期函数--监听页面初次渲染完成
  21. */
  22. onReady: function () {
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面隐藏
  31. */
  32. onHide: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面卸载
  36. */
  37. onUnload: function () {
  38. },
  39. /**
  40. * 页面相关事件处理函数--监听用户下拉动作
  41. */
  42. onPullDownRefresh: function () {
  43. },
  44. /**
  45. * 页面上拉触底事件的处理函数
  46. */
  47. onReachBottom: function () {
  48. },
  49. /**
  50. * 用户点击右上角分享
  51. */
  52. onShareAppMessage: function () {
  53. },
  54. pickerTap:function() {
  55. date = new Date();
  56. var monthDay = ['今天','明天'];
  57. var hours = [];
  58. var minute = [];
  59. currentHours = date.getHours();
  60. currentMinute = date.getMinutes();
  61. // 月-日
  62. for (var i = 2; i <= 28; i++) {
  63. var date1 = new Date(date);
  64. date1.setDate(date.getDate() + i);
  65. var md = (date1.getMonth() + 1) + "-" + date1.getDate();
  66. monthDay.push(md);
  67. }
  68. var data = {
  69. multiArray: this.data.multiArray,
  70. multiIndex: this.data.multiIndex
  71. };
  72. if(data.multiIndex[0] === 0) {
  73. if(data.multiIndex[1] === 0) {
  74. this.loadData(hours, minute);
  75. } else {
  76. this.loadMinute(hours, minute);
  77. }
  78. } else {
  79. this.loadHoursMinute(hours, minute);
  80. }
  81. data.multiArray[0] = monthDay;
  82. data.multiArray[1] = hours;
  83. data.multiArray[2] = minute;
  84. this.setData(data);
  85. },
  86. bindMultiPickerColumnChange:function(e) {
  87. date = new Date();
  88. var that = this;
  89. var monthDay = ['今天', '明天'];
  90. var hours = [];
  91. var minute = [];
  92. currentHours = date.getHours();
  93. currentMinute = date.getMinutes();
  94. var data = {
  95. multiArray: this.data.multiArray,
  96. multiIndex: this.data.multiIndex
  97. };
  98. // 把选择的对应值赋值给 multiIndex
  99. data.multiIndex[e.detail.column] = e.detail.value;
  100. // 然后再判断当前改变的是哪一列,如果是第1列改变
  101. if (e.detail.column === 0) {
  102. // 如果第一列滚动到第一行
  103. if (e.detail.value === 0) {
  104. that.loadData(hours, minute);
  105. } else {
  106. that.loadHoursMinute(hours, minute);
  107. }
  108. data.multiIndex[1] = 0;
  109. data.multiIndex[2] = 0;
  110. // 如果是第2列改变
  111. } else if (e.detail.column === 1) {
  112. // 如果第一列为今天
  113. if (data.multiIndex[0] === 0) {
  114. if (e.detail.value === 0) {
  115. that.loadData(hours, minute);
  116. } else {
  117. that.loadMinute(hours, minute);
  118. }
  119. // 第一列不为今天
  120. } else {
  121. that.loadHoursMinute(hours, minute);
  122. }
  123. data.multiIndex[2] = 0;
  124. // 如果是第3列改变
  125. } else {
  126. // 如果第一列为'今天'
  127. if (data.multiIndex[0] === 0) {
  128. // 如果第一列为 '今天'并且第二列为当前时间
  129. if(data.multiIndex[1] === 0) {
  130. that.loadData(hours, minute);
  131. } else {
  132. that.loadMinute(hours, minute);
  133. }
  134. } else {
  135. that.loadHoursMinute(hours, minute);
  136. }
  137. }
  138. data.multiArray[1] = hours;
  139. data.multiArray[2] = minute;
  140. this.setData(data);
  141. },
  142. loadData: function (hours, minute) {
  143. var minuteIndex;
  144. if (currentMinute > 0 && currentMinute <= 10) {
  145. minuteIndex = 10;
  146. } else if (currentMinute > 10 && currentMinute <= 20) {
  147. minuteIndex = 20;
  148. } else if (currentMinute > 20 && currentMinute <= 30) {
  149. minuteIndex = 30;
  150. } else if (currentMinute > 30 && currentMinute <= 40) {
  151. minuteIndex = 40;
  152. } else if (currentMinute > 40 && currentMinute <= 50) {
  153. minuteIndex = 50;
  154. } else {
  155. minuteIndex = 60;
  156. }
  157. if (minuteIndex == 60) {
  158. // 时
  159. for (var i = currentHours + 1; i < 24; i++) {
  160. hours.push(i);
  161. }
  162. // 分
  163. for (var i = 0; i < 60; i += 10) {
  164. minute.push(i);
  165. }
  166. } else {
  167. // 时
  168. for (var i = currentHours; i < 24; i++) {
  169. hours.push(i);
  170. }
  171. // 分
  172. for (var i = minuteIndex; i < 60; i += 10) {
  173. minute.push(i);
  174. }
  175. }
  176. },
  177. loadHoursMinute: function (hours, minute){
  178. // 时
  179. for (var i = 0; i < 24; i++) {
  180. hours.push(i);
  181. }
  182. // 分
  183. for (var i = 0; i < 60; i += 10) {
  184. minute.push(i);
  185. }
  186. },
  187. loadMinute: function (hours, minute) {
  188. var minuteIndex;
  189. if (currentMinute > 0 && currentMinute <= 10) {
  190. minuteIndex = 10;
  191. } else if (currentMinute > 10 && currentMinute <= 20) {
  192. minuteIndex = 20;
  193. } else if (currentMinute > 20 && currentMinute <= 30) {
  194. minuteIndex = 30;
  195. } else if (currentMinute > 30 && currentMinute <= 40) {
  196. minuteIndex = 40;
  197. } else if (currentMinute > 40 && currentMinute <= 50) {
  198. minuteIndex = 50;
  199. } else {
  200. minuteIndex = 60;
  201. }
  202. if (minuteIndex == 60) {
  203. // 时
  204. for (var i = currentHours + 1; i < 24; i++) {
  205. hours.push(i);
  206. }
  207. } else {
  208. // 时
  209. for (var i = currentHours; i < 24; i++) {
  210. hours.push(i);
  211. }
  212. }
  213. // 分
  214. for (var i = 0; i < 60; i += 10) {
  215. minute.push(i);
  216. }
  217. },
  218. bindStartMultiPickerChange: function (e) {
  219. var that = this;
  220. var monthDay = that.data.multiArray[0][e.detail.value[0]];
  221. var hours = that.data.multiArray[1][e.detail.value[1]];
  222. var minute = that.data.multiArray[2][e.detail.value[2]];
  223. if (monthDay === "今天") {
  224. var month = date.getMonth()+1;
  225. var day = date.getDate();
  226. monthDay = month + "月" + day + "日";
  227. } else if (monthDay === "明天") {
  228. var date1 = new Date(date);
  229. date1.setDate(date.getDate() + 1);
  230. monthDay = (date1.getMonth() + 1) + "月" + date1.getDate() + "日";
  231. } else {
  232. var month = monthDay.split("-")[0]; // 返回月
  233. var day = monthDay.split("-")[1]; // 返回日
  234. monthDay = month + "月" + day + "日";
  235. }
  236. var startDate = monthDay + " " + hours + ":" + minute;
  237. that.setData({
  238. startDate: startDate
  239. })
  240. },
  241. })